Skip to content

Commit cc450d0

Browse files
Add default tagging (#3)
* Add default tagging * Fix workflows * Fix workflows * Fix outputs * Fix outputs
1 parent 2b5954e commit cc450d0

File tree

7 files changed

+72
-64
lines changed

7 files changed

+72
-64
lines changed

.github/workflows/deploy-sandbox.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deploy Sandbox Environment
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
permissions:
9+
id-token: write
10+
contents: read
11+
12+
jobs:
13+
call-terragrunt-deploy:
14+
permissions:
15+
contents: read
16+
id-token: write
17+
uses: ./.github/workflows/terragrunt-deploy.yml
18+
with:
19+
tf_version: '1.5.5'
20+
tg_version: '0.54.11'
21+
environment: sandbox
22+
region: us-east-2
23+
env_id: '000'
24+
secrets: inherit

.github/workflows/terragrunt-deploy.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ jobs:
4545
test -z "${{ vars.DEPLOY_ROLE_ARN }}" && (echo "::error title=Repository Configuration Incomplete::This repository is missing an environment variable for DEPLOY_ROLE_ARN in the ${{ inputs.environment }} environment!"; raised=1)
4646
exit $raised
4747
48+
- name: "Set default Terraform Tags"
49+
id: set-tags
50+
run: |
51+
set -x
52+
echo "${{ github.repository }}" | cut -d "/" -f 2 > repo.txt
53+
echo "TF_VAR_organization_tag=${{ github.repository_owner }}" >> "$GITHUB_OUTPUT"
54+
echo "TF_VAR_repository_tag=$(cat repo.txt)" >> "$GITHUB_OUTPUT"
55+
echo "TF_VAR_commit_hash_tag=${{ github.sha }}" >> "$GITHUB_OUTPUT"
56+
4857
- name: Configure AWS credentials
4958
uses: aws-actions/configure-aws-credentials@a95656fcd9ec16a226c7099657b9fc91cc777601
5059
with:
@@ -59,6 +68,9 @@ jobs:
5968
AWS_REGION: ${{ inputs.region }}
6069
INPUT_PRE_EXEC_0: |
6170
sudo apt update -yqq && sudo apt install python3 -yqq
71+
TF_VAR_organization_tag: ${{ steps.set-tags.outputs.TF_VAR_organization_tag }}
72+
TF_VAR_repository_tag: ${{ steps.set-tags.outputs.TF_VAR_repository_tag }}
73+
TF_VAR_commit_hash_tag: ${{ steps.set-tags.outputs.TF_VAR_commit_hash_tag }}
6274
with:
6375
tf_version: ${{ inputs.tf_version }}
6476
tg_version: ${{ inputs.tg_version }}
@@ -68,10 +80,13 @@ jobs:
6880
- name: Deploy
6981
uses: gruntwork-io/terragrunt-action@aee21a7df999be8b471c2a8564c6cd853cb674e1
7082
env:
71-
AWS_REGION: ${{ inputs.region }}
72-
TERRAFORM_PLAN: ${{ steps.plan.outputs.TERRAFORM_PLAN }}
73-
INPUT_PRE_EXEC_0: |
74-
sudo apt update -yqq && sudo apt install python3 -yqq
83+
AWS_REGION: ${{ inputs.region }}
84+
TERRAFORM_PLAN: ${{ steps.plan.outputs.TERRAFORM_PLAN }}
85+
INPUT_PRE_EXEC_0: |
86+
sudo apt update -yqq && sudo apt install python3 -yqq
87+
TF_VAR_organization_tag: ${{ steps.set-tags.outputs.TF_VAR_organization_tag }}
88+
TF_VAR_repository_tag: ${{ steps.set-tags.outputs.TF_VAR_repository_tag }}
89+
TF_VAR_commit_hash_tag: ${{ steps.set-tags.outputs.TF_VAR_commit_hash_tag }}
7590
with:
7691
tf_version: ${{ inputs.tf_version }}
7792
tg_version: ${{ inputs.tg_version }}

.github/workflows/test.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

terragrunt.hcl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,41 @@ generate "provider" {
2424
contents = <<EOF
2525
provider "aws" {
2626
region = "${local.region}"
27+
28+
default_tags {
29+
tags = {
30+
Organization = var.organization_tag
31+
Repository = var.repository_tag
32+
CommitHash = var.commit_hash_tag
33+
}
34+
}
2735
}
2836
2937
provider "aws" {
3038
alias = "global"
3139
region = "us-east-1"
40+
41+
default_tags {
42+
tags = {
43+
Organization = var.organization_tag
44+
Repository = var.repository_tag
45+
CommitHash = var.commit_hash_tag
46+
}
47+
}
48+
}
49+
50+
variable "organization_tag" {
51+
type = string
3252
}
53+
54+
variable "repository_tag" {
55+
type = string
56+
}
57+
58+
variable "commit_hash_tag" {
59+
type = string
60+
}
61+
3362
EOF
3463
}
3564

0 commit comments

Comments
 (0)