Skip to content

Commit e03a273

Browse files
authored
Merge pull request #5 from arunlalp/gitlab
Gitlab
2 parents ea15764 + 2188190 commit e03a273

File tree

7 files changed

+165
-0
lines changed

7 files changed

+165
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
module "tag-policy" {
6+
source = "../../../modules/tag-policy"
7+
region = var.region
8+
policy_name = var.policy_name
9+
policy_type = var.policy_type
10+
target_id = var.target_id
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "policy_id" {
2+
value = module.tag-policy.policy_id
3+
description = "ID of the tag policy"
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "region" {
2+
type = string
3+
description = "Region for the provider"
4+
}
5+
6+
variable "policy_name" {
7+
type = string
8+
description = "Name for the tag policy"
9+
}
10+
11+
variable "policy_type" {
12+
type = string
13+
description = "Type of the policy"
14+
}
15+
16+
variable "target_id" {
17+
type = number
18+
description = "ID of the target"
19+
}

modules/tag-policy/main.tf

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Provider Configuration
2+
provider "aws" {
3+
region = var.region
4+
}
5+
6+
# Create Tag Policy
7+
resource "aws_organizations_policy" "tag_policy" {
8+
name = var.policy_name
9+
description = "Resource Provision"
10+
11+
content = jsonencode({
12+
"tags" = {
13+
"Name" = {
14+
"tag_key" = {
15+
"@@assign" = "Name"
16+
},
17+
"enforced_for" = {
18+
"@@assign" = [
19+
"ec2:instance",
20+
"ec2:security-group"
21+
]
22+
}
23+
},
24+
"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+
}
41+
},
42+
"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+
}
57+
},
58+
"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+
}
73+
},
74+
"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+
}
89+
}
90+
}
91+
})
92+
93+
type = var.policy_type
94+
}
95+
96+
resource "aws_organizations_policy_attachment" "account_attachment" {
97+
policy_id = aws_organizations_policy.tag_policy.id
98+
target_id = var.target_id
99+
}
100+
101+
102+
103+

modules/tag-policy/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "policy_id" {
2+
value = aws_organizations_policy.tag_policy.id
3+
description = "ID of the tag policy."
4+
}

modules/tag-policy/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "region" {
2+
type = string
3+
description = "Region for the provider."
4+
}
5+
6+
variable "policy_name" {
7+
type = string
8+
description = "Name for the tag policy."
9+
}
10+
11+
variable "policy_type" {
12+
type = string
13+
description = "Type of the policy."
14+
}
15+
16+
variable "target_id" {
17+
type = number
18+
description = "ID of the target."
19+
}

vars/dev/tag-policy.tfvars

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Tag Policy Vars
2+
region = "eu-north-1"
3+
policy_name = "Techiescamp"
4+
policy_type = "TAG_POLICY"
5+
target_id = "814200988517"

0 commit comments

Comments
 (0)