Skip to content

Commit d865c7c

Browse files
committed
remove tfvars secret and add branch input
- remove tfvars secret and storing in github, use the encrypted terraform.tfvars file with transcrypt. - add branch as input - change API token name and remove vars secret file - change path for dedicated runners
1 parent 2fe0c94 commit d865c7c

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

.github/workflows/ephemeral_devnet_aws_deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Main CD for Ephememeral Devnet Deployment
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
branch:
7+
required: true
8+
type: string
59
pull_request:
610
branches:
711
- main
@@ -20,6 +24,7 @@ jobs:
2024
uses: ./.github/workflows/terraform_template_ephemeral_deploy.yml
2125
with:
2226
project: testing-framework
27+
branch: ${{ github.event.inputs.branch }}
2328
instance: ec2
2429
resource: network
2530
tf_workspace_name: ephemeral-devnet

.github/workflows/ephemeral_devnet_hetzner_deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Main CD for Ephememeral Devnet Deployment
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
branch:
7+
required: true
8+
type: string
59
pull_request:
610
branches:
711
- main
@@ -20,6 +24,7 @@ jobs:
2024
uses: ./.github/workflows/terraform_template_ephemeral_deploy.yml
2125
with:
2226
project: testing-framework
27+
branch: ${{ github.event.inputs.branch }}
2328
instance: hetzner
2429
resource: network
2530
tf_workspace_name: ephemeral-devnet-hetzner

.github/workflows/terraform_gh_runner.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches:
77
- main
88
paths:
9-
- "github-runners/terraform/base/**"
9+
- "github-runners/terraform/dedicated/**"
1010

1111
jobs:
1212
terraform_gh_runner:
@@ -22,11 +22,11 @@ jobs:
2222
uses: hashicorp/setup-terraform@v1
2323
with:
2424
terraform_version: "1.5.7"
25-
cli_config_credentials_token: ${{ secrets.TF_CLOUD_TOKEN }}
25+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
2626

27-
- name: Install dependencies
27+
- name: Decrypt the secrets
2828
run: |
29-
# Install any dependencies required by your Terraform code
29+
bash scripts/transcrypt -c aes-256-cbc -p ${{ secrets.TRANSCRYPT }} -y
3030
3131
- name: Run Bash Script
3232
id: generate_runner_token
@@ -54,14 +54,9 @@ jobs:
5454
# in subsequent steps with terraform for runner registration
5555
echo "::set-output name=runner_token::$runner_token"
5656
57-
- name: Fetch and write terraform.tfvars
58-
run: |
59-
echo ${{ secrets.TF_VARS_FILE }} > /tmp/terraform.tfvars
60-
chmod 600 /tmp/terraform.tfvars
61-
6257
- name: Run Terraform
63-
working-directory: ./github-runners/terraform/base
58+
working-directory: ./github-runners/terraform/dedicated
6459
run: |
6560
terraform init
66-
terraform plan -var-file=/tmp/terraform.tfvars
67-
terraform apply -auto-approve -var "gh_token=${{ steps.generate_runner_token.outputs.runner_token }}" -var-file=/tmp/terraform.tfvars
61+
terraform plan -var-file=terraform.tfvars
62+
terraform apply -auto-approve -var "gh_token=${{ steps.generate_runner_token.outputs.runner_token }}" -var-file=terraform.tfvars

.github/workflows/terraform_template_deploy.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,21 @@ jobs:
7171
working-directory: ${{ inputs.project }}/${{ inputs.resource }}
7272
run: terraform validate
7373

74-
- name: Fetch and write terraform.tfvars
75-
run: |
76-
echo ${{ secrets.TF_VARS_FILE }} > /tmp/terraform.tfvars
77-
chmod 600 /tmp/terraform.tfvars
78-
7974
- name: Terraform Plan for ${{ inputs.project }}/${{ inputs.resource }}
8075
if: ${{ (inputs.run_destroy == 'no') }}
8176
working-directory: ${{ inputs.project }}/${{ inputs.resource }}
8277
run: |
83-
terraform plan -var-file=/tmp/terraform.tfvars
78+
terraform plan -var-file=terraform.tfvars
8479
8580
- name: Terraform Apply for ${{ inputs.project }}/${{ inputs.resource }}
8681
if: ${{ (inputs.run_apply == 'yes') && (inputs.run_destroy == 'no') }}
8782
working-directory: ${{ inputs.project }}/${{ inputs.resource }}
8883
run: |
89-
terraform apply -auto-approve -var-file=/tmp/terraform.tfvars
84+
terraform apply -auto-approve -var-file=terraform.tfvars
9085
9186
- name: Terraform Destroy for ${{ inputs.project }}/${{ inputs.resource }}
9287
if: ${{ (inputs.run_destroy == 'yes') }}
9388
working-directory: ${{ inputs.project }}/${{ inputs.resource }}
9489
run: |
95-
terraform plan -destroy -var-file=/tmp/terraform.tfvars
96-
terraform destroy -auto-approve -var-file=/tmp/terraform.tfvars
90+
terraform plan -destroy -var-file=terraform.tfvars
91+
terraform destroy -auto-approve -var-file=terraform.tfvars

.github/workflows/terraform_template_ephemeral_deploy.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
project:
77
required: true
88
type: string
9+
branch:
10+
required: true
11+
type: string
912
instance:
1013
required: true
1114
type: string
@@ -75,26 +78,21 @@ jobs:
7578
working-directory: ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
7679
run: terraform validate
7780

78-
- name: Fetch and write terraform.tfvars
79-
run: |
80-
echo ${{ secrets.TF_VARS_FILE }} > /tmp/terraform.tfvars
81-
chmod 600 /tmp/terraform.tfvars
82-
8381
- name: Terraform Plan for ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
8482
if: ${{ (inputs.run_destroy == 'no') }}
8583
working-directory: ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
8684
run: |
87-
terraform plan -var-file=/tmp/terraform.tfvars
85+
terraform plan -var-file=terraform.tfvars -var "branch_name=${{ inputs.branch }}"
8886
8987
- name: Terraform Apply for ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
9088
if: ${{ (inputs.run_apply == 'yes') && (inputs.run_destroy == 'no') }}
9189
working-directory: ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
9290
run: |
93-
terraform apply -auto-approve -var-file=/tmp/terraform.tfvars
91+
terraform apply -auto-approve -var-file=terraform.tfvars -var "branch_name=${{ inputs.branch }}"
9492
9593
- name: Terraform Destroy for ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
9694
if: ${{ (inputs.run_destroy == 'yes') }}
9795
working-directory: ${{ inputs.project }}/${{ inputs.instance }}/${{ inputs.resource }}
9896
run: |
99-
terraform plan -destroy -var-file=/tmp/terraform.tfvars
100-
terraform destroy -auto-approve -var-file=/tmp/terraform.tfvars
97+
terraform plan -destroy -var-file=terraform.tfvars -var "branch_name=${{ inputs.branch }}"
98+
terraform destroy -auto-approve -var-file=terraform.tfvars -var "branch_name=${{ inputs.branch }}"

0 commit comments

Comments
 (0)