Skip to content

Commit

Permalink
Merge pull request #57 from appvia/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
richcto authored Jan 22, 2025
2 parents d85d7a1 + 7602e5b commit fe65b1f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tags": {
"mandatory": ["CostCenter", "BillingCode"],
"allowed": {
"CostCenter": "^CC-[0-9]{4}$",
"BillingCode": "^BC-[0-9]{3}$"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tags": {
"mandatory": ["Environment", "Owner", "Project"],
"allowed": {
"Environment": ["dev", "test", "prod"],
"Owner": "^[a-zA-Z]+$",
"Project": "^[a-zA-Z0-9-_]+$"
}
}
}
14 changes: 14 additions & 0 deletions examples/basic/values/production.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ organization = {
}
]
}

tagging_policies = {
"MandatoryTaggingPolicy" = {
description = "Enforces mandatory tags like Environment, Owner, and Project."
filename = "assets/tagging-policies/mandatory-tagging-policy.json"
key = "infrastructure"
}

"CostTaggingPolicy" = {
description = "Ensures resources are tagged with cost-related metadata."
filename = "assets/tagging-policies/cost-tagging-policy.json"
key = "workloads"
}
}
6 changes: 3 additions & 3 deletions policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ resource "aws_organizations_policy_attachment" "service_control_policy_attachmen
## Provision any tagging policies
#
resource "aws_organizations_policy" "tagging_policy" {
for_each = { for x in var.tagging_policies : x.name => x }
for_each = var.tagging_policies

name = each.key
content = each.value.content
Expand All @@ -44,14 +44,14 @@ resource "aws_organizations_policy" "tagging_policy" {

## Attach any tagging policies to the organizational units
resource "aws_organizations_policy_attachment" "tagging_policy_attachment_root" {
for_each = { for x in var.tagging_policies : x.name => x if x.key == "root" }
for_each = { for k, v in var.tagging_policies : k => v if v.key == "root" }

policy_id = aws_organizations_policy.tagging_policy[each.key].id
target_id = local.root_ou
}

resource "aws_organizations_policy_attachment" "tagging_policy_attachment" {
for_each = { for x in var.tagging_policies : x.name => x if x.key != "root" }
for_each = { for k, v in var.tagging_policies : k => v if v.key != "root" }

policy_id = aws_organizations_policy.tagging_policy[each.key].id
target_id = coalesce(each.value.target_id, try(local.all_ou_attributes[each.value.key].id, null))
Expand Down

0 comments on commit fe65b1f

Please sign in to comment.