Skip to content

Commit baf09dc

Browse files
authored
feat: add Terragrunt pipeline for landing page deployment via GitHub Actions (#317)
* feat: add Terragrunt pipeline for landing page deployment * fix: add setup-terraform step so Terragrunt can find terraform binary * chore: add environment: landing-page-prod to validate and apply jobs
1 parent d212e09 commit baf09dc

4 files changed

Lines changed: 125 additions & 3 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Deploy Landing Page
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "landing-page/**"
9+
- "terraform/landing-page/**"
10+
- ".github/workflows/deploy-landing-page.yaml"
11+
- "assets/**"
12+
pull_request:
13+
branches:
14+
- main
15+
paths:
16+
- "landing-page/**"
17+
- "terraform/landing-page/**"
18+
- ".github/workflows/deploy-landing-page.yaml"
19+
- "assets/**"
20+
workflow_dispatch:
21+
22+
permissions:
23+
contents: read
24+
id-token: write
25+
26+
jobs:
27+
validate:
28+
runs-on: ubuntu-latest
29+
environment: landing-page-prod
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- name: Configure AWS credentials
34+
uses: aws-actions/configure-aws-credentials@v5
35+
with:
36+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
37+
aws-region: us-east-1
38+
39+
- name: Setup Terraform
40+
uses: hashicorp/setup-terraform@v3
41+
with:
42+
terraform_version: "1.9.8"
43+
44+
- name: Setup Terragrunt
45+
run: |
46+
TG_VERSION="0.72.6"
47+
curl -sL "https://github.com/gruntwork-io/terragrunt/releases/download/v${TG_VERSION}/terragrunt_linux_amd64" -o /usr/local/bin/terragrunt
48+
chmod +x /usr/local/bin/terragrunt
49+
50+
- name: Terragrunt Init
51+
working-directory: terraform/landing-page
52+
run: terragrunt init
53+
env:
54+
TF_VAR_hosted_zone_id: ${{ secrets.HOSTED_ZONE_ID }}
55+
56+
- name: Terragrunt Validate
57+
working-directory: terraform/landing-page
58+
run: terragrunt validate
59+
env:
60+
TF_VAR_hosted_zone_id: ${{ secrets.HOSTED_ZONE_ID }}
61+
62+
apply:
63+
needs: validate
64+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
65+
runs-on: ubuntu-latest
66+
environment: landing-page-prod
67+
steps:
68+
- uses: actions/checkout@v4
69+
70+
- name: Configure AWS credentials
71+
uses: aws-actions/configure-aws-credentials@v5
72+
with:
73+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
74+
aws-region: us-east-1
75+
76+
- name: Setup Terraform
77+
uses: hashicorp/setup-terraform@v3
78+
with:
79+
terraform_version: "1.9.8"
80+
81+
- name: Setup Terragrunt
82+
run: |
83+
TG_VERSION="0.72.6"
84+
curl -sL "https://github.com/gruntwork-io/terragrunt/releases/download/v${TG_VERSION}/terragrunt_linux_amd64" -o /usr/local/bin/terragrunt
85+
chmod +x /usr/local/bin/terragrunt
86+
87+
- name: Terragrunt Init
88+
working-directory: terraform/landing-page
89+
run: terragrunt init
90+
env:
91+
TF_VAR_hosted_zone_id: ${{ secrets.HOSTED_ZONE_ID }}
92+
93+
- name: Terragrunt Apply
94+
working-directory: terraform/landing-page
95+
run: terragrunt apply -auto-approve
96+
env:
97+
TF_VAR_hosted_zone_id: ${{ secrets.HOSTED_ZONE_ID }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ override.tf.json
217217
.terraformrc
218218
terraform.rc
219219

220+
# Terragrunt generated provider files
221+
provider-generated.tf
222+
220223
# End of https://www.toptal.com/developers/gitignore/api/terraform
221224

222225
# Created by https://www.toptal.com/developers/gitignore/api/go

terraform/landing-page/terraform.tf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ terraform {
99
version = "~> 3.0"
1010
}
1111
}
12-
}
1312

14-
provider "aws" {
15-
region = "us-east-1"
13+
backend "s3" {}
1614
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
locals {
2+
aws_region = "us-east-1"
3+
}
4+
5+
remote_state {
6+
backend = "s3"
7+
config = {
8+
bucket = "tf2-quickserver-terraform-state"
9+
key = "landing-page/terraform.tfstate"
10+
region = local.aws_region
11+
encrypt = true
12+
dynamodb_table = "tf2-quickserver-terraform-locks"
13+
}
14+
}
15+
16+
generate "provider" {
17+
path = "provider-generated.tf"
18+
if_exists = "overwrite_terragrunt"
19+
contents = <<EOF
20+
provider "aws" {
21+
region = "${local.aws_region}"
22+
}
23+
EOF
24+
}

0 commit comments

Comments
 (0)