1414 required : true
1515 default : ' apply'
1616 type : string
17- working_directory :
18- description : ' The working directory to run the command in'
19- required : true
20- default : ' database'
21- type : string
2217 tag :
2318 description : ' The tag of the containers to deploy'
2419 default : ' latest'
3732 value : ${{ jobs.infra.outputs.API_GW_URL }}
3833 S3_BUCKET_ARN :
3934 value : ${{ jobs.infra.outputs.S3_BUCKET_ARN }}
35+ S3_BUCKET_NAME :
36+ value : ${{ jobs.infra.outputs.S3_BUCKET_NAME }}
4037 CF_DOMAIN :
4138 value : ${{ jobs.infra.outputs.CF_DOMAIN }}
4239 CF_DISTRIBUTION_ID :
4340 value : ${{ jobs.infra.outputs.CF_DISTRIBUTION_ID }}
4441
4542env :
46- TG_VERSION : 0.63.6
47- TF_VERSION : 1.12.2
48- TG_SRC_PATH : terraform/${{ inputs.working_directory }}
49- AWS_REGION : ca-central-1
43+ TG_VERSION : 0.63.6
44+ TF_VERSION : 1.12.2
45+ TG_SRC_PATH : terragrunt
46+ AWS_REGION : ca-central-1
5047permissions :
5148 id-token : write # This is required for requesting the JWT
5249 contents : write # This is required for actions/checkout
5350jobs :
5451 infra :
5552 environment : ${{ inputs.environment_name }}
56- name : Terraform ${{inputs.command}} ${{inputs.working_directory }} ${{inputs.app_env}}
53+ name : Terragrunt ${{inputs.command}} ${{inputs.app_env}}
5754 runs-on : ubuntu-24.04
5855 outputs :
59- API_GW_URL : ${{ steps.tg-outputs.outputs.API_GW_URL }}
60- S3_BUCKET_ARN : ${{ steps.tg-outputs-frontend.outputs.S3_BUCKET_ARN }}
61- CF_DOMAIN : ${{ steps.tg-outputs-frontend.outputs.CF_DOMAIN }}
62- CF_DISTRIBUTION_ID : ${{ steps.tg-outputs-frontend.outputs.CF_DISTRIBUTION_ID }}
56+ API_GW_URL : ${{ steps.tg.outputs.API_GW_URL }}
57+ S3_BUCKET_ARN : ${{ steps.tg.outputs.S3_BUCKET_ARN }}
58+ S3_BUCKET_NAME : ${{ steps.tg.outputs.S3_BUCKET_NAME }}
59+ CF_DOMAIN : ${{ steps.tg.outputs.CF_DOMAIN }}
60+ CF_DISTRIBUTION_ID : ${{ steps.tg.outputs.CF_DISTRIBUTION_ID }}
6361 steps :
6462 - name : Checkout
6563 uses : actions/checkout@v4
6664 - name : Configure AWS Credentials
6765 uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
6866 with :
69- role-to-assume : ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
70- role-session-name : ${{ inputs.environment_name }}-deployment
71- aws-region : ${{ env.AWS_REGION }}
67+ role-to-assume : ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
68+ role-session-name : ${{ inputs.environment_name }}-deployment
69+ aws-region : ${{ env.AWS_REGION }}
7270 - uses : hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
7371 with :
7472 terraform_version : ${{ env.TF_VERSION }}
@@ -82,57 +80,35 @@ jobs:
8280 shell : bash
8381 run : |
8482 API_IMAGE="${{ steps.ecr-check.outputs.ecr-registry }}/${{ github.repository }}:backend-${{ inputs.tag }}"
83+ FLYWAY_IMAGE="${{ steps.ecr-check.outputs.ecr-registry }}/${{ github.repository }}:migrations-${{ inputs.tag }}"
8584 echo "api-image=$API_IMAGE" >> $GITHUB_OUTPUT
85+ echo "flyway-image=$FLYWAY_IMAGE" >> $GITHUB_OUTPUT
8686
8787 - name : Setup Terragrunt
8888 uses : autero1/action-terragrunt@aefb0a43c4f5503a91fefb307745c4d51c26ed0e # v3
8989 with :
90- terragrunt-version : ${{ env.TG_VERSION }}
90+ terragrunt-version : ${{ env.TG_VERSION }}
9191 - name : Terragrunt ${{inputs.command}}
92- working-directory : terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
93- env :
94- target_env : ${{ inputs.environment_name }}
95- aws_license_plate : ${{ secrets.AWS_LICENSE_PLATE }}
96- api_image : ${{ steps.image-tags.outputs.api-image }}
97- app_env : ${{inputs.app_env}}
98- stack_prefix : ${{ inputs.stack_prefix }}
99- repo_name : ${{ github.event.repository.name }}
100- run : |
101- # Run terraform
102- terragrunt run-all ${{inputs.command}} --terragrunt-non-interactive
103- - name : Terragrunt API Outputs
104- if : (inputs.working_directory == 'api' && inputs.command == 'apply')
105- working-directory : terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
106- id : tg-outputs
92+ id : tg
93+ working-directory : terragrunt/${{ inputs.environment_name }}
10794 env :
108- target_env : ${{ inputs.environment_name }}
109- aws_license_plate : ${{ secrets.AWS_LICENSE_PLATE }}
110- api_image : ${{ steps.image-tags.outputs.api-image }}
111- app_env : ${{inputs.app_env}}
112- stack_prefix : ${{ inputs.stack_prefix }}
113- repo_name : ${{ github.event.repository.name }}
95+ target_env : ${{ inputs.environment_name }}
96+ aws_license_plate : ${{ secrets.AWS_LICENSE_PLATE }}
97+ api_image : ${{ steps.image-tags.outputs.api-image }}
98+ app_env : ${{inputs.app_env}}
99+ stack_prefix : ${{ inputs.stack_prefix }}
100+ repo_name : ${{ github.event.repository.name }}
101+ terragrunt_command : ${{ inputs.command }}
114102 run : |
115- terragrunt output -json > outputs.json
116- #print the output
117- cat outputs.json
118-
119- echo "API_GW_URL=$(jq -r .apigw_url.value outputs.json)" >> $GITHUB_OUTPUT
120- - name : Terragrunt Frontend Outputs
121- if : (inputs.working_directory == 'frontend' && inputs.command == 'apply')
122- working-directory : terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
123- id : tg-outputs-frontend
124- env :
125- target_env : ${{ inputs.environment_name }}
126- aws_license_plate : ${{ secrets.AWS_LICENSE_PLATE }}
127- api_image : ${{ steps.image-tags.outputs.api-image }}
128- app_env : ${{inputs.app_env}}
129- stack_prefix : ${{ inputs.stack_prefix }}
130- repo_name : ${{ github.event.repository.name }}
131- run : |
132- terragrunt output -json > outputs.json
133- #print the output
134- cat outputs.json
135-
136- echo "S3_BUCKET_ARN=$(jq -r .s3_bucket_arn.value outputs.json)" >> $GITHUB_OUTPUT
137- echo "CF_DOMAIN=$(jq -r .cloudfront.value.domain_name outputs.json)" >> $GITHUB_OUTPUT
138- echo "CF_DISTRIBUTION_ID=$(jq -r .cloudfront.value.distribution_id outputs.json)" >> $GITHUB_OUTPUT
103+ # Run terraform
104+ terragrunt run-all ${{inputs.command}} --terragrunt-non-interactive
105+ terragrunt output -json > outputs.json
106+ #print the output
107+ cat outputs.json
108+
109+ echo "S3_BUCKET_ARN=$(jq -r .frontend_bucket.value.arn outputs.json)" >> $GITHUB_OUTPUT
110+ echo "S3_BUCKET_NAME=$(jq -r .frontend_bucket.value.name outputs.json)" >> $GITHUB_OUTPUT
111+ echo "CF_DOMAIN=$(jq -r .cloudfront.value.domain_name outputs.json)" >> $GITHUB_OUTPUT
112+ echo "CF_DISTRIBUTION_ID=$(jq -r .cloudfront.value.distribution_id outputs.json)" >> $GITHUB_OUTPUT
113+ echo "API_GW_URL=$(jq -r .apigw_url.value outputs.json)" >> $GITHUB_OUTPUT
114+
0 commit comments