Provision AWS with Terraform #35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Provision AWS with Terraform | |
| on: | |
| workflow_dispatch: # Enables manual triggering | |
| push: | |
| paths: | |
| - 'terraform/**' | |
| jobs: | |
| terraform_deploy: | |
| runs-on: ubuntu-latest | |
| environment: development | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Configure AWS Credentials | |
| 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: eu-central-1 | |
| role-to-assume: arn:aws:iam::149532386180:role/TerraformExecutionRole | |
| role-session-name: GitHubActionsTerraform | |
| - name: Restore Terraform Cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: terraform/.terraform | |
| key: terraform-${{ runner.os }}-${{ hashFiles('**/*.tf') }} | |
| restore-keys: | | |
| terraform-${{ runner.os }}- | |
| - name: Set up Terraform | |
| uses: hashicorp/setup-terraform@v2 | |
| with: | |
| terraform_version: 1.5.5 # Specify the Terraform version you want to use | |
| - name: Terraform Init (if cache is missing) | |
| working-directory: terraform | |
| run: terraform init | |
| - name: Terraform Plan | |
| working-directory: terraform | |
| run: terraform plan -out=tfplan | |
| - name: Terraform Apply | |
| if: ${{ success() }} | |
| working-directory: terraform | |
| run: terraform apply -auto-approve tfplan |