Skip to content

Commit b8ab16e

Browse files
mishraompCopilot
andauthored
feat: modular terraform aligning to best practices (#148)
* feat: modular terraform aligning to best practices * fix: module versions * fix: deployer * fix * fix * fix: vars * more fixes * fix: vars * some more fixes * fix db cluster name var * hanlde plan failure when cluster is blank * trying to see if the fix branch works * upgrade common modules * fix: api cpu * comment until fixed * fix: tags * fix provider for waf * fix: provider * adding provider to tg * fix: provider * Update infra/variables.tf Co-authored-by: Copilot <[email protected]> * Update infra/variables.tf Co-authored-by: Copilot <[email protected]> * Update .github/workflows/.deployer.yml Co-authored-by: Copilot <[email protected]> * Update infra/modules/api/main.tf Co-authored-by: Copilot <[email protected]> * Update terragrunt/terragrunt.hcl Co-authored-by: Copilot <[email protected]> * fix: env var * fix: the outputs * fix: output in root module --------- Co-authored-by: Copilot <[email protected]>
1 parent c85949a commit b8ab16e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1292
-1299
lines changed

.github/workflows/.deploy_stack.yml

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,46 +90,23 @@ jobs:
9090
name: Stack Prefix
9191
needs: ecr
9292
uses: ./.github/workflows/.stack-prefix.yml
93-
deploy-db:
94-
name: Deploys Database
93+
deploy:
94+
name: Deploys
9595
needs: [stack-prefix]
9696
uses: ./.github/workflows/.deployer.yml
9797
with:
9898
environment_name: ${{ inputs.environment_name }}
9999
command: ${{ inputs.command }}
100-
working_directory: database
101100
app_env: ${{ inputs.app_env }}
102101
stack_prefix: ${{ needs.stack-prefix.outputs.stack_prefix }}
103-
secrets: inherit
104-
deploy-api:
105-
name: Deploys API
106-
needs: [deploy-db, stack-prefix]
107-
uses: ./.github/workflows/.deployer.yml
108-
with:
109-
environment_name: ${{ inputs.environment_name }}
110-
command: ${{ inputs.command }}
111102
tag: ${{ inputs.tag }}
112-
app_env: ${{ inputs.app_env }}
113-
working_directory: api
114-
stack_prefix: ${{ needs.stack-prefix.outputs.stack_prefix }}
115-
secrets: inherit
116-
deploy-cloudfront:
117-
name: Deploys Cloudfront
118-
needs: [stack-prefix]
119-
uses: ./.github/workflows/.deployer.yml
120-
with:
121-
environment_name: ${{ inputs.environment_name }}
122-
command: ${{ inputs.command }}
123-
tag: ${{ inputs.tag }}
124-
app_env: ${{ inputs.app_env }}
125-
working_directory: frontend
126-
stack_prefix: ${{ needs.stack-prefix.outputs.stack_prefix }}
127103
secrets: inherit
104+
128105
build-ui:
129106
name: Build And upload UI to s3 ${{ inputs.environment_name }}
130107
environment: ${{ inputs.environment_name }}
131108
if: (inputs.command == 'apply')
132-
needs: [deploy-api, deploy-cloudfront]
109+
needs: [deploy]
133110
runs-on: ubuntu-24.04
134111
steps:
135112
- name: Checkout
@@ -149,9 +126,9 @@ jobs:
149126
- name: Build And Update UI (CF)
150127
working-directory: frontend
151128
env:
152-
VITE_API_BASE_URL: ${{ needs.deploy-api.outputs.API_GW_URL }}/api
153-
S3_BUCKET_ARN: ${{ needs.deploy-cloudfront.outputs.S3_BUCKET_ARN }}
154-
CF_DISTRIBUTION_ID: ${{ needs.deploy-cloudfront.outputs.CF_DISTRIBUTION_ID }}
129+
VITE_API_BASE_URL: ${{ needs.deploy.outputs.API_GW_URL }}/api
130+
S3_BUCKET_ARN: ${{ needs.deploy.outputs.S3_BUCKET_ARN }}
131+
CF_DISTRIBUTION_ID: ${{ needs.deploy.outputs.CF_DISTRIBUTION_ID }}
155132
run: |
156133
npm run deploy
157134
aws s3 sync --delete ./dist s3://$(echo "$S3_BUCKET_ARN" | cut -d: -f6)

.github/workflows/.deployer.yml

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ on:
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
17+
2218
tag:
2319
description: 'The tag of the containers to deploy'
2420
default: 'latest'
@@ -37,6 +33,8 @@ on:
3733
value: ${{ jobs.infra.outputs.API_GW_URL }}
3834
S3_BUCKET_ARN:
3935
value: ${{ jobs.infra.outputs.S3_BUCKET_ARN }}
36+
S3_BUCKET_NAME:
37+
value: ${{ jobs.infra.outputs.S3_BUCKET_NAME }}
4038
CF_DOMAIN:
4139
value: ${{ jobs.infra.outputs.CF_DOMAIN }}
4240
CF_DISTRIBUTION_ID:
@@ -45,21 +43,22 @@ on:
4543
env:
4644
TG_VERSION: 0.63.6
4745
TF_VERSION: 1.12.2
48-
TG_SRC_PATH: terraform/${{ inputs.working_directory }}
46+
TG_SRC_PATH: terragrunt
4947
AWS_REGION: ca-central-1
5048
permissions:
5149
id-token: write # This is required for requesting the JWT
5250
contents: write # This is required for actions/checkout
5351
jobs:
5452
infra:
5553
environment: ${{ inputs.environment_name }}
56-
name: Terraform ${{inputs.command}} ${{inputs.working_directory}} ${{inputs.app_env}}
54+
name: Terragrunt ${{inputs.command}} ${{inputs.app_env}}
5755
runs-on: ubuntu-24.04
5856
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 }}
57+
API_GW_URL: ${{ steps.tg.outputs.API_GW_URL }}
58+
S3_BUCKET_ARN: ${{ steps.tg.outputs.S3_BUCKET_ARN }}
59+
S3_BUCKET_NAME: ${{ steps.tg.outputs.S3_BUCKET_NAME }}
60+
CF_DOMAIN: ${{ steps.tg.outputs.CF_DOMAIN }}
61+
CF_DISTRIBUTION_ID: ${{ steps.tg.outputs.CF_DISTRIBUTION_ID }}
6362
steps:
6463
- name: Checkout
6564
uses: actions/checkout@v4
@@ -91,7 +90,8 @@ jobs:
9190
with:
9291
terragrunt-version: ${{ env.TG_VERSION }}
9392
- name: Terragrunt ${{inputs.command}}
94-
working-directory: terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
93+
id: tg
94+
working-directory: terragrunt/${{ inputs.environment_name }}
9595
env:
9696
target_env: ${{ inputs.environment_name }}
9797
aws_license_plate: ${{ secrets.AWS_LICENSE_PLATE }}
@@ -100,46 +100,17 @@ jobs:
100100
app_env: ${{inputs.app_env}}
101101
stack_prefix: ${{ inputs.stack_prefix }}
102102
repo_name: ${{ github.event.repository.name }}
103-
terrgrunt_command: ${{ inputs.command }}
103+
terragrunt_command: ${{ inputs.command }}
104104
run: |
105105
# Run terraform
106106
terragrunt run-all ${{inputs.command}} --terragrunt-non-interactive
107-
- name: Terragrunt API Outputs
108-
if: (inputs.working_directory == 'api' && inputs.command == 'apply')
109-
working-directory: terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
110-
id: tg-outputs
111-
env:
112-
target_env: ${{ inputs.environment_name }}
113-
aws_license_plate: ${{ secrets.AWS_LICENSE_PLATE }}
114-
api_image: ${{ steps.image-tags.outputs.api-image }}
115-
flyway_image: ${{ steps.image-tags.outputs.flyway-image }}
116-
app_env: ${{inputs.app_env}}
117-
stack_prefix: ${{ inputs.stack_prefix }}
118-
repo_name: ${{ github.event.repository.name }}
119-
terrgrunt_command: ${{ inputs.command }}
120-
run: |
121107
terragrunt output -json > outputs.json
122108
#print the output
123109
cat outputs.json
124-
echo "API_GW_URL=$(jq -r .apigw_url.value outputs.json)" >> $GITHUB_OUTPUT
125-
- name: Terragrunt Frontend Outputs
126-
if: (inputs.working_directory == 'frontend' && inputs.command == 'apply')
127-
working-directory: terraform/${{ inputs.working_directory }}/${{ inputs.environment_name }}
128-
id: tg-outputs-frontend
129-
env:
130-
target_env: ${{ inputs.environment_name }}
131-
aws_license_plate: ${{ secrets.AWS_LICENSE_PLATE }}
132-
api_image: ${{ steps.image-tags.outputs.api-image }}
133-
flyway_image: ${{ steps.image-tags.outputs.flyway-image }}
134-
app_env: ${{inputs.app_env}}
135-
stack_prefix: ${{ inputs.stack_prefix }}
136-
repo_name: ${{ github.event.repository.name }}
137-
terrgrunt_command: ${{ inputs.command }}
138-
run: |
139-
terragrunt output -json > outputs.json
140-
#print the output
141-
cat outputs.json
142-
143-
echo "S3_BUCKET_ARN=$(jq -r .s3_bucket_arn.value outputs.json)" >> $GITHUB_OUTPUT
110+
111+
echo "S3_BUCKET_ARN=$(jq -r .frontend_bucket.value.arn outputs.json)" >> $GITHUB_OUTPUT
112+
echo "S3_BUCKET_NAME=$(jq -r .frontend_bucket.value.name outputs.json)" >> $GITHUB_OUTPUT
144113
echo "CF_DOMAIN=$(jq -r .cloudfront.value.domain_name outputs.json)" >> $GITHUB_OUTPUT
145-
echo "CF_DISTRIBUTION_ID=$(jq -r .cloudfront.value.distribution_id outputs.json)" >> $GITHUB_OUTPUT
114+
echo "CF_DISTRIBUTION_ID=$(jq -r .cloudfront.value.distribution_id outputs.json)" >> $GITHUB_OUTPUT
115+
echo "API_GW_URL=$(jq -r .apigw_url.value outputs.json)" >> $GITHUB_OUTPUT
116+

.github/workflows/.destroy_stack.yml

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,15 @@ jobs:
3232
stack-prefix:
3333
name: Stack Prefix
3434
uses: ./.github/workflows/.stack-prefix.yml
35-
api:
36-
name: Destroy API
35+
destroy:
36+
name: Destroy
3737
needs: [stack-prefix]
3838
uses: ./.github/workflows/.deployer.yml
3939
with:
4040
environment_name: ${{ inputs.environment_name }}
4141
command: ${{ inputs.command }}
42-
tag: ${{ inputs.tag }}
4342
app_env: ${{ inputs.app_env }}
44-
working_directory: api
45-
stack_prefix: ${{ needs.stack-prefix.outputs.stack_prefix }}
46-
secrets: inherit
47-
db:
48-
name: Destroy Database
49-
needs: [stack-prefix, api]
50-
uses: ./.github/workflows/.deployer.yml
51-
with:
52-
environment_name: ${{ inputs.environment_name }}
53-
command: ${{ inputs.command }}
54-
working_directory: database
55-
app_env: ${{ inputs.app_env }}
56-
stack_prefix: ${{ needs.stack-prefix.outputs.stack_prefix }}
57-
secrets: inherit
58-
59-
cloudfront:
60-
name: Destroy Cloudfront
61-
needs: [stack-prefix]
62-
uses: ./.github/workflows/.deployer.yml
63-
with:
64-
environment_name: ${{ inputs.environment_name }}
65-
command: ${{ inputs.command }}
66-
tag: ${{ inputs.tag }}
67-
app_env: ${{ inputs.app_env }}
68-
working_directory: frontend
6943
stack_prefix: ${{ needs.stack-prefix.outputs.stack_prefix }}
7044
secrets: inherit
7145

46+

.github/workflows/pr-open.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ jobs:
5151
with:
5252
tag: ${{ github.event.number || 'latest' }}
5353

54-
resume-resources-dev:
55-
name: Resume Resources Dev
56-
if: (github.event_name == 'workflow_dispatch')
57-
concurrency:
58-
group: rrd-${{ github.event.number || 'latest' }}
59-
cancel-in-progress: false
60-
needs: [builds]
61-
uses: ./.github/workflows/resume-resources.yml
62-
with:
63-
app_env: dev
64-
secrets: inherit
54+
# resume-resources-dev:
55+
# name: Resume Resources Dev
56+
# if: (github.event_name == 'workflow_dispatch')
57+
# concurrency:
58+
# group: rrd-${{ github.event.number || 'latest' }}
59+
# cancel-in-progress: false
60+
# needs: [builds]
61+
# uses: ./.github/workflows/resume-resources.yml
62+
# with:
63+
# app_env: dev
64+
# secrets: inherit
6565

6666
deploy-to-dev:
6767
name: Deploy to Dev
6868
if: (github.event_name == 'workflow_dispatch')
6969
concurrency:
7070
group: deploy-dev-${{ github.event.number || 'latest' }}
7171
cancel-in-progress: false
72-
needs: [resume-resources-dev, plan-stack]
72+
#needs: [resume-resources-dev, plan-stack]
7373
uses: ./.github/workflows/.deploy_stack.yml
7474
with:
7575
environment_name: prod # ::change it to:: dev , template repo only has PROD

0 commit comments

Comments
 (0)