Skip to content

Commit 929695d

Browse files
committed
Add runtime auto tfvars support. Use better naming
1 parent 5168fe3 commit 929695d

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

.github/workflows/terraform-deploy.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ on:
1010
type: string
1111
required: true
1212

13-
tf_var_file:
13+
tfvars_file:
1414
type: string
1515
required: true
1616

17+
auto_tfvars_artifact:
18+
type: string
19+
required: false
20+
1721
tf_backend_resource_group_name:
1822
type: string
1923
required: true
@@ -52,7 +56,8 @@ env:
5256
TF_BACKEND_STORAGE_ACCOUNT_NAME: ${{ inputs.tf_backend_storage_account_name }}
5357
TF_BACKEND_STORAGE_CONTAINER_NAME: ${{ inputs.tf_backend_storage_container_name }}
5458
TF_BACKEND_STATE_KEY: ${{ inputs.tf_backend_state_key }}
55-
TF_VAR_FILE: ${{ inputs.tf_var_file }}
59+
TFVARS_FILE: ${{ inputs.tfvars_file }}
60+
AUTO_TFVARS_ARTIFACT: ${{ inputs.auto_tfvars_artifact }}
5661
WORKING_DIR: ${{ inputs.working_dir }}
5762

5863
permissions:
@@ -75,9 +80,18 @@ jobs:
7580
- name: Checkout
7681
uses: actions/checkout@v3
7782

78-
- name: TF values
83+
- name: Download auto tfvars
84+
if: ${{ env.AUTO_TFVARS_ARTIFACT }}
85+
uses: actions/download-artifact@v3
86+
with:
87+
name: ${{ env.AUTO_TFVARS_ARTIFACT }}
88+
path: ${{ env.WORKING_DIR }}
89+
90+
- name: Show tfvars artifact
91+
if: ${{ inputs.auto_tf_var_files_artifact }}
7992
run: |
80-
cat "./$TF_VAR_FILE"
93+
echo "tfvars artifact contents:"
94+
cat "./values.auto.tfvars"
8195
8296
- name: Setup Terraform
8397
uses: hashicorp/setup-terraform@v2
@@ -94,7 +108,7 @@ jobs:
94108
run: terraform validate
95109

96110
- name: Terraform Plan
97-
run: terraform plan -var-file=$TF_VAR_FILE
111+
run: terraform plan -var-file=$TFVARS_FILE
98112

99113
terraform-apply:
100114
name: 'Terraform Apply'
@@ -111,6 +125,13 @@ jobs:
111125
- name: Checkout
112126
uses: actions/checkout@v3
113127

128+
- name: Download auto tfvars
129+
if: ${{ env.AUTO_TFVARS_ARTIFACT }}
130+
uses: actions/download-artifact@v3
131+
with:
132+
name: ${{ env.AUTO_TFVARS_ARTIFACT }}
133+
path: ${{ env.WORKING_DIR }}
134+
114135
- name: Setup Terraform
115136
uses: hashicorp/setup-terraform@v2
116137

@@ -123,4 +144,4 @@ jobs:
123144
-backend-config="key=$TF_BACKEND_STATE_KEY"
124145
125146
- name: Terraform Apply
126-
run: terraform apply -auto-approve -var-file=$TF_VAR_FILE
147+
run: terraform apply -auto-approve -var-file=$TFVARS_FILE

0 commit comments

Comments
 (0)