Skip to content

Commit bf88190

Browse files
authored
Merge pull request #19 from arunlalp/master
[TEC-69] Add Variables for Tag Policy: tag-key, tag-value, enforce-for-values
2 parents 783705b + bc5d647 commit bf88190

File tree

5 files changed

+180
-83
lines changed

5 files changed

+180
-83
lines changed

environments/dev/tag-policy/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,21 @@ module "tag-policy" {
88
policy_name = var.policy_name
99
policy_type = var.policy_type
1010
target_id = var.target_id
11+
12+
name_tag_key = var.name_tag_key
13+
name_enforce_for_values = var.name_enforce_for_values
14+
15+
environment_tag_key = var.environment_tag_key
16+
environment_enforce_for_values = var.environment_enforce_for_values
17+
18+
owner_tag_key = var.owner_tag_key
19+
owner_tag_value = var.owner_tag_value
20+
owner_enforce_for_values = var.owner_enforce_for_values
21+
22+
costcenter_tag_key = var.costcenter_tag_key
23+
costcenter_tag_value = var.costcenter_tag_value
24+
costcenter_enforce_for_values = var.costcenter_enforce_for_values
25+
26+
application_tag_key = var.application_tag_key
27+
application_enforce_for_values = var.application_enforce_for_values
1128
}
Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,79 @@
11
variable "region" {
22
type = string
3-
description = "Region for the provider"
3+
description = "The AWS region for provider configuration."
44
}
55

66
variable "policy_name" {
77
type = string
8-
description = "Name for the tag policy"
8+
description = "A descriptive name for the AWS Organizations Tag Policy."
99
}
1010

1111
variable "policy_type" {
1212
type = string
13-
description = "Type of the policy"
13+
description = "The type of the AWS Organizations Tag Policy."
1414
}
1515

1616
variable "target_id" {
1717
type = number
18-
description = "ID of the target"
19-
}
18+
description = "The ID of the target organizational unit to attach the Tag Policy."
19+
}
20+
21+
variable "name_tag_key" {
22+
type = string
23+
description = "The tag key for the 'Name' tag."
24+
}
25+
26+
variable "name_enforce_for_values" {
27+
type = list(string)
28+
description = "A list of tag values to enforce for the 'Name' tag."
29+
}
30+
31+
variable "environment_tag_key" {
32+
type = string
33+
description = "The tag key for the 'Environment' tag."
34+
}
35+
36+
variable "environment_enforce_for_values" {
37+
type = list(string)
38+
description = "A list of tag values to enforce for the 'Environment' tag."
39+
}
40+
41+
variable "owner_tag_key" {
42+
type = string
43+
description = "The tag key for the 'Owner' tag."
44+
}
45+
46+
variable "owner_tag_value" {
47+
type = list(string)
48+
description = "A list of valid tag values for the 'Owner' tag."
49+
}
50+
51+
variable "owner_enforce_for_values" {
52+
type = list(string)
53+
description = "A list of tag values to enforce for the 'Owner' tag."
54+
}
55+
56+
variable "costcenter_tag_key" {
57+
type = string
58+
description = "The tag key for the 'CostCenter' tag."
59+
}
60+
61+
variable "costcenter_tag_value" {
62+
type = list(string)
63+
description = "A list of valid tag values for the 'CostCenter' tag."
64+
}
65+
66+
variable "costcenter_enforce_for_values" {
67+
type = list(string)
68+
description = "A list of tag values to enforce for the 'CostCenter' tag."
69+
}
70+
71+
variable "application_tag_key" {
72+
type = string
73+
description = "The tag key for the 'Application' tag."
74+
}
75+
76+
variable "application_enforce_for_values" {
77+
type = list(string)
78+
description = "A list of tag values to enforce for the 'Application' tag."
79+
}

modules/tag-policy/main.tf

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Provider Configuration
1+
# Provider Configuration
22
provider "aws" {
33
region = var.region
44
}
@@ -11,81 +11,26 @@ resource "aws_organizations_policy" "tag_policy" {
1111
content = jsonencode({
1212
"tags" = {
1313
"Name" = {
14-
"tag_key" = {
15-
"@@assign" = "Name"
16-
},
17-
"enforced_for" = {
18-
"@@assign" = [
19-
"ec2:instance",
20-
"ec2:security-group"
21-
]
22-
}
14+
"tag_key" = { "@@assign" = var.name_tag_key },
15+
"enforced_for" = { "@@assign" = var.name_enforce_for_values }
2316
},
2417
"Environment" = {
25-
"tag_key" = {
26-
"@@assign" = "Environment"
27-
},
28-
"tag_value" = {
29-
"@@assign" = [
30-
"dev",
31-
"stage",
32-
"prod"
33-
]
34-
},
35-
"enforced_for" = {
36-
"@@assign" = [
37-
"ec2:instance",
38-
"ec2:security-group"
39-
]
40-
}
18+
"tag_key" = { "@@assign" = var.environment_tag_key },
19+
"enforced_for" = { "@@assign" = var.environment_enforce_for_values }
4120
},
4221
"Owner" = {
43-
"tag_key" = {
44-
"@@assign" = "Owner"
45-
},
46-
"tag_value" = {
47-
"@@assign" = [
48-
"Techiescamp"
49-
]
50-
},
51-
"enforced_for" = {
52-
"@@assign" = [
53-
"ec2:instance",
54-
"ec2:security-group"
55-
]
56-
}
22+
"tag_key" = { "@@assign" = var.owner_tag_key },
23+
"tag_value" = { "@@assign" = var.owner_tag_value },
24+
"enforced_for" = { "@@assign" = var.owner_enforce_for_values }
5725
},
5826
"CostCenter" = {
59-
"tag_key" = {
60-
"@@assign" = "CostCenter"
61-
},
62-
"tag_value" = {
63-
"@@assign" = [
64-
"project-pet-clinic"
65-
]
66-
},
67-
"enforced_for" = {
68-
"@@assign" = [
69-
"ec2:instance",
70-
"ec2:security-group"
71-
]
72-
}
27+
"tag_key" = { "@@assign" = var.costcenter_tag_key },
28+
"tag_value" = { "@@assign" = var.costcenter_tag_value },
29+
"enforced_for" = { "@@assign" = var.costcenter_enforce_for_values }
7330
},
7431
"Application" = {
75-
"tag_key" = {
76-
"@@assign" = "Application"
77-
},
78-
"tag_value" = {
79-
"@@assign" = [
80-
"web-app"
81-
]
82-
},
83-
"enforced_for" = {
84-
"@@assign" = [
85-
"ec2:instance",
86-
"ec2:security-group"
87-
]
88-
}
32+
"tag_key" = { "@@assign" = var.application_tag_key },
33+
"enforced_for" = { "@@assign" = var.application_enforce_for_values }
8934
}
9035
}
9136
})
@@ -97,7 +42,3 @@ resource "aws_organizations_policy_attachment" "account_attachment" {
9742
policy_id = aws_organizations_policy.tag_policy.id
9843
target_id = var.target_id
9944
}
100-
101-
102-
103-

modules/tag-policy/variables.tf

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,79 @@
11
variable "region" {
22
type = string
3-
description = "Region for the provider."
3+
description = "The AWS region for provider configuration."
44
}
55

66
variable "policy_name" {
77
type = string
8-
description = "Name for the tag policy."
8+
description = "A descriptive name for the AWS Organizations Tag Policy."
99
}
1010

1111
variable "policy_type" {
1212
type = string
13-
description = "Type of the policy."
13+
description = "The type of the AWS Organizations Tag Policy."
1414
}
1515

1616
variable "target_id" {
1717
type = number
18-
description = "ID of the target."
19-
}
18+
description = "The ID of the target organizational unit to attach the Tag Policy."
19+
}
20+
21+
variable "name_tag_key" {
22+
type = string
23+
description = "The tag key for the 'Name' tag."
24+
}
25+
26+
variable "name_enforce_for_values" {
27+
type = list(string)
28+
description = "A list of tag values to enforce for the 'Name' tag."
29+
}
30+
31+
variable "environment_tag_key" {
32+
type = string
33+
description = "The tag key for the 'Environment' tag."
34+
}
35+
36+
variable "environment_enforce_for_values" {
37+
type = list(string)
38+
description = "A list of tag values to enforce for the 'Environment' tag."
39+
}
40+
41+
variable "owner_tag_key" {
42+
type = string
43+
description = "The tag key for the 'Owner' tag."
44+
}
45+
46+
variable "owner_tag_value" {
47+
type = list(string)
48+
description = "A list of valid tag values for the 'Owner' tag."
49+
}
50+
51+
variable "owner_enforce_for_values" {
52+
type = list(string)
53+
description = "A list of tag values to enforce for the 'Owner' tag."
54+
}
55+
56+
variable "costcenter_tag_key" {
57+
type = string
58+
description = "The tag key for the 'CostCenter' tag."
59+
}
60+
61+
variable "costcenter_tag_value" {
62+
type = list(string)
63+
description = "A list of valid tag values for the 'CostCenter' tag."
64+
}
65+
66+
variable "costcenter_enforce_for_values" {
67+
type = list(string)
68+
description = "A list of tag values to enforce for the 'CostCenter' tag."
69+
}
70+
71+
variable "application_tag_key" {
72+
type = string
73+
description = "The tag key for the 'Application' tag."
74+
}
75+
76+
variable "application_enforce_for_values" {
77+
type = list(string)
78+
description = "A list of tag values to enforce for the 'Application' tag."
79+
}

vars/dev/tag-policy.tfvars

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@
22
region = "eu-north-1"
33
policy_name = "Techiescamp"
44
policy_type = "TAG_POLICY"
5-
target_id = "814200988517"
5+
target_id = "814200988517"
6+
7+
name_tag_key = "Name"
8+
name_enforce_for_values = ["ec2:instance", "ec2:security-group"]
9+
10+
environment_tag_key = "Environment"
11+
environment_enforce_for_values = ["ec2:instance", "ec2:security-group"]
12+
13+
owner_tag_key = "Owner"
14+
owner_tag_value = ["techiescamp"]
15+
owner_enforce_for_values = ["ec2:instance", "ec2:security-group"]
16+
17+
costcenter_tag_key = "CostCenter"
18+
costcenter_tag_value = ["techiescamp-commerce"]
19+
costcenter_enforce_for_values = ["ec2:instance", "ec2:security-group"]
20+
21+
application_tag_key = "Application"
22+
application_enforce_for_values = ["ec2:instance", "ec2:security-group"]
23+
24+

0 commit comments

Comments
 (0)