Skip to content

Commit c2df563

Browse files
Add default tagging
1 parent 2b5954e commit c2df563

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

.github/workflows/terragrunt-deploy.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ 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+
run: |
50+
echo "${{ github.repository }}" | cut -d "/" -f 2 > repo.txt
51+
echo "TF_VAR_organization_tag=${{ github.repository_owner }}" >> "$GITHUB_OUTPUT"
52+
echo "TF_VAR_repository_tag=$(cat repo.txt)" >> "$GITHUB_OUTPUT"
53+
echo "TF_VAR_commit_hash_tag=${{ github.sha }}" >> "$GITHUB_OUTPUT"
54+
4855
- name: Configure AWS credentials
4956
uses: aws-actions/configure-aws-credentials@a95656fcd9ec16a226c7099657b9fc91cc777601
5057
with:
@@ -59,6 +66,9 @@ jobs:
5966
AWS_REGION: ${{ inputs.region }}
6067
INPUT_PRE_EXEC_0: |
6168
sudo apt update -yqq && sudo apt install python3 -yqq
69+
TF_VAR_organization_tag: ${{ vars.TF_VAR_organization_tag }}
70+
TF_VAR_repository_tag: ${{ vars.TF_VAR_repository_tag }}
71+
TF_VAR_organizaTF_VAR_commit_hash_tagtion_tag: ${{ vars.TF_VAR_commit_hash_tag }}
6272
with:
6373
tf_version: ${{ inputs.tf_version }}
6474
tg_version: ${{ inputs.tg_version }}
@@ -68,10 +78,13 @@ jobs:
6878
- name: Deploy
6979
uses: gruntwork-io/terragrunt-action@aee21a7df999be8b471c2a8564c6cd853cb674e1
7080
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
81+
AWS_REGION: ${{ inputs.region }}
82+
TERRAFORM_PLAN: ${{ steps.plan.outputs.TERRAFORM_PLAN }}
83+
INPUT_PRE_EXEC_0: |
84+
sudo apt update -yqq && sudo apt install python3 -yqq
85+
TF_VAR_organization_tag: ${{ vars.TF_VAR_organization_tag }}
86+
TF_VAR_repository_tag: ${{ vars.TF_VAR_repository_tag }}
87+
TF_VAR_organizaTF_VAR_commit_hash_tagtion_tag: ${{ vars.TF_VAR_commit_hash_tag }}z
7588
with:
7689
tf_version: ${{ inputs.tf_version }}
7790
tg_version: ${{ inputs.tg_version }}

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)