DrInTech22 triggered the pipeline #28
This file contains 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: Terraform Plan and Cost Estimation | |
run-name: ${{ github.actor }} triggered the pipeline | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
branches: | |
- 'infra_main' | |
# paths: | |
# - './terraform/**' | |
permissions: | |
pull-requests: write | |
env: | |
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
TF_VAR_aws_region: ${{ vars.TF_AWS_REGION }} | |
TF_VAR_ami_id: ${{ vars.TF_AMI_ID }} | |
TF_VAR_instance_type: ${{ vars.TF_INSTANCE_TYPE }} | |
TF_VAR_key_pair_name: ${{ vars.TF_KEY_PAIR_NAME }} | |
TF_VAR_private_key: ${{ secrets.PRIVATE_KEY }} | |
TF_VAR_domain_name: ${{ vars.TF_DOMAIN_NAME }} | |
TF_VAR_frontend_domain: ${{ vars.TF_FRONTEND_DOMAIN }} | |
TF_VAR_db_domain: ${{ vars.TF_DB_DOMAIN }} | |
TF_VAR_traefik_domain: ${{ vars.TF_TRAEFIK_DOMAIN }} | |
TF_VAR_cert_email: ${{ secrets.TF_CERT_EMAIL }} | |
TF_VAR_private_key_path: ./${{ vars.TF_KEY_PAIR_NAME }}.pem | |
jobs: | |
terraform-plan: | |
name: Terraform Plan | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout PR Branch | |
uses: actions/checkout@v2 | |
- name: Write Private Key to File | |
run: | | |
echo "${{ secrets.PRIVATE_KEY }}" > ${{ vars.TF_KEY_PAIR_NAME }}.pem | |
chmod 600 ${{ vars.TF_KEY_PAIR_NAME }}.pem | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Terraform Init | |
id: init | |
run: terraform init | |
working-directory: ./terraform | |
- name: Terraform Plan | |
id: plan | |
run: terraform plan -out=tfplan.out | |
working-directory: ./terraform | |
- name: Save Plan JSON | |
id: save-plan | |
run: terraform show -json tfplan.out > ../../tfplan.json && pwd | |
working-directory: ./terraform | |
- name: Setup Infracost | |
uses: infracost/actions/setup@v3 | |
with: | |
api-key: ${{ secrets.INFRACOST_API_KEY }} | |
- name: Run Infracost | |
run: | | |
infracost breakdown --path=./terraform --format=json --out-file=/tmp/infracost-new.json && pwd && cat /tmp/infracost-new.json | |
# Checkout the branch you want Infracost to compare costs against, most commonly the target branch. | |
- name: Checkout base branch | |
uses: actions/checkout@v4 | |
with: | |
ref: '${{ github.event.pull_request.base.ref }}' | |
- name: Run Infracost | |
shell: bash | |
run: | | |
infracost breakdown --path=./terraform --format=json --out-file=/tmp/infracost-base.json && pwd | |
infracost diff --path=../tfplan.json \ | |
--format=json \ | |
--compare-to=/tmp/infracost-base.json \ | |
--out-file=/tmp/infracost.json | |
- name: Post Infracost Comment | |
run: | | |
infracost comment github --path=/tmp/infracost.json \ | |
--repo=$GITHUB_REPOSITORY \ | |
--github-token=${{ github.token }} \ | |
--pull-request=${{ github.event.pull_request.number }} \ | |
--behavior=update |