fix: update Terraform workflow to download and upload state files
Some checks failed
Terraform CI/CD / terraform (push) Has been cancelled
Some checks failed
Terraform CI/CD / terraform (push) Has been cancelled
This commit is contained in:
17
.github/workflows/terraform.yaml
vendored
17
.github/workflows/terraform.yaml
vendored
@@ -6,7 +6,7 @@ on:
|
||||
|
||||
jobs:
|
||||
terraform:
|
||||
runs-on: ssot
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
container:
|
||||
image: hashicorp/terraform:1.6.6
|
||||
@@ -23,6 +23,14 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Download previous Terraform state if it exists
|
||||
- name: Download previous Terraform state
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: terraform-state
|
||||
path: terraform/
|
||||
continue-on-error: true # skip if no previous state exists
|
||||
|
||||
- name: Terraform Init
|
||||
run: terraform -chdir=terraform init -input=false
|
||||
|
||||
@@ -46,3 +54,10 @@ jobs:
|
||||
- name: Terraform Apply
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: terraform -chdir=terraform apply -input=false -auto-approve tfplan
|
||||
|
||||
# Upload updated Terraform state
|
||||
- name: Upload Terraform state
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: terraform-state
|
||||
path: terraform/terraform.tfstate
|
||||
|
||||
Reference in New Issue
Block a user