name: Terraform Apply on: push: branches: - main jobs: validate: name: Validate runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v3 - name: Setup Terraform uses: hashicorp/setup-terraform@v2 - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v2 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ vars.AWS_REGION }} - name: Terraform Init working-directory: infra run: | terraform init \ --backend-config="bucket=${{ vars.TERRAFORM_STATE_BUCKET_NAME }}" \ --backend-config="key={{ vars.TERRAFORM_STATE_KEY }}" \ --backend-config="region=${{ vars.TERRAFORM_STATE_REGION }}" \ --backend-config="encrypt=true" \ --backend-config="dynamodb_table=${{ vars.TERRAFORM_STATE_DYNAMODB_TABLE }}" - name: Terraform Apply working-directory: infra run: terraform apply --auto-approve - name: Terraform Apply (second time to output correct values from CloudFormation Stacks) working-directory: infra run: terraform apply --auto-approve