Skip to content

Commit 231450e

Browse files
committed
fix: dynamically generate a tfvars file from github secrets
1 parent a754292 commit 231450e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

.github/workflows/terraform.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,28 @@ jobs:
3030
with:
3131
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
3232

33+
# Create tfvars file
34+
- name: Create Terraform variables file
35+
run: |
36+
cat > ./terraform/terraform.tfvars << EOF
37+
admin_ssh_key = "${{ secrets.SSH_ADMIN_PUBKEY }}"
38+
vultr_api_key = "${{ secrets.VULTR_API_KEY }}"
39+
EOF
40+
3341
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
3442
- name: Terraform Init
35-
run: |
36-
terraform -chdir=./terraform init \
37-
-var='admin_ssh_key=${{ secrets.SSH_ADMIN_PUBKEY }}' \
38-
-var='vultr_api_key=${{ secrets.VULTR_API_KEY }}'
43+
run: terraform -chdir=./terraform init
3944

4045
# Checks that all Terraform configuration files adhere to a canonical format
4146
- name: Terraform Format
4247
run: terraform -chdir=./terraform fmt -check
4348

4449
# Generates an execution plan for Terraform
4550
- name: Terraform Plan
46-
run: |
47-
terraform -chdir=./terraform plan -input=false \
48-
-var='admin_ssh_key=${{ secrets.SSH_ADMIN_PUBKEY }}' \
49-
-var='vultr_api_key=${{ secrets.VULTR_API_KEY }}'
51+
run: terraform -chdir=./terraform plan -input=false
5052

5153
# On push to "main", build or change infrastructure according to Terraform configuration files
5254
# Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
5355
- name: Terraform Apply
5456
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
55-
run: |
56-
terraform -chdir=./terraform apply -auto-approve -input=false \
57-
-var='admin_ssh_key=${{ secrets.SSH_ADMIN_PUBKEY }}' \
58-
-var='vultr_api_key=${{ secrets.VULTR_API_KEY }}'
57+
run: terraform -chdir=./terraform apply -auto-approve -input=false

0 commit comments

Comments
 (0)