Skip to content

Commit

Permalink
ci: added terraform version and aws credentials dynamically (#84)
Browse files Browse the repository at this point in the history
Co-authored-by: Anmol Nagpal <anmol@clouddrove.com>
  • Loading branch information
vaibhav7797 and anmolnagpal authored Sep 27, 2023
1 parent bb25820 commit 011b5ce
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/terraform_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ jobs:
SPACES_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }}
SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }}
TF_VAR_access_token: ${{ secrets.TF_VAR_access_token }}

outputs:
tfplanExitCode: ${{ steps.tf-plan.outputs.exitcode }}

Expand Down
32 changes: 28 additions & 4 deletions .github/workflows/tf-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ on:
required: false
type: string
default: './_example/complete/'
terraform_version:
description: 'Terraform version to use. Leave empty for the latest version.'
required: false
type: string
aws_credentials:
description: 'AWS credentials to use.'
required: false
default: false
type: string
secrets:
AWS_ACCESS_KEY_ID:
description: 'aws access keys'
required: false
AWS_SECRET_ACCESS_KEY:
description: 'aws secret access keys'
required: false

jobs:
# - Terraform version extract as output.
Expand Down Expand Up @@ -50,11 +66,19 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
if: ${{ inputs.aws_credentials == 'true' }}
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

# - Installing terraform version based on version extract.
- name: Install Terraform v${{ matrix.version }}
- name: Install Terraform v${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ matrix.version }}
terraform_version: ${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}

# - Terraform checks to Init and Validate terraform code.
- name: Init & validate v${{ matrix.version }}
Expand All @@ -75,10 +99,10 @@ jobs:
uses: actions/checkout@v4

# - Action added to install terraform
- name: Install Terraform v${{ needs.versionExtract.outputs.maxVersion }}
- name: Install Terraform v${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ needs.versionExtract.outputs.maxVersion }}
terraform_version: ${{ inputs.terraform_version || needs.versionExtract.outputs.maxVersion }}

# - Running command to check terraform formatting changes.
- name: Check Terraform format changes
Expand Down
5 changes: 5 additions & 0 deletions docs/terraform-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ jobs:
uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master
with:
working_directory: './_example/complete/'
# terraform_version: 0.12.31 // Specify the Terraform version to use. Uncomment and provide your desired version, or leave it as is to use the latest version.
aws_credentials: false // Provide your AWS Credentails ID here if 'aws_credentials' is set to 'true'.
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
```

0 comments on commit 011b5ce

Please sign in to comment.