Skip to content

Commit bffa8cc

Browse files
authored
Merge pull request #29 from comet-ml/DT-436_tagging_terraform_resources
DT-436 clean implementation
2 parents 2eb52d8 + 3693db5 commit bffa8cc

File tree

19 files changed

+236
-164
lines changed

19 files changed

+236
-164
lines changed

.terraform.lock.hcl

Lines changed: 81 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.tf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ data "aws_eks_cluster_auth" "this" {
55

66
locals {
77
resource_name = "comet-${var.environment}"
8-
tags = {
9-
Terraform = "true"
10-
Environment = var.environment
11-
}
8+
all_tags = merge(
9+
{
10+
Terraform = "true"
11+
},
12+
var.environment_tag != "" ? { Environment = var.environment_tag } : {},
13+
var.common_tags
14+
)
1215
}
1316

1417
module "comet_vpc" {
1518
source = "./modules/comet_vpc"
1619
count = var.enable_vpc ? 1 : 0
1720
environment = var.environment
21+
common_tags = local.all_tags
1822
region = var.region
1923

2024
eks_enabled = var.enable_eks
@@ -25,6 +29,7 @@ module "comet_ec2" {
2529
source = "./modules/comet_ec2"
2630
count = var.enable_ec2 ? 1 : 0
2731
environment = var.environment
32+
common_tags = local.all_tags
2833

2934
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
3035
comet_ec2_subnet = var.enable_vpc ? module.comet_vpc[0].public_subnets[0] : var.comet_public_subnets[0]
@@ -47,6 +52,7 @@ module "comet_ec2_alb" {
4752
source = "./modules/comet_ec2_alb"
4853
count = var.enable_ec2_alb ? 1 : 0
4954
environment = var.environment
55+
common_tags = local.all_tags
5056

5157
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
5258
public_subnets = var.enable_vpc ? module.comet_vpc[0].public_subnets : var.comet_public_subnets
@@ -57,6 +63,7 @@ module "comet_eks" {
5763
source = "./modules/comet_eks"
5864
count = var.enable_eks ? 1 : 0
5965
environment = var.environment
66+
common_tags = local.all_tags
6067

6168
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
6269
eks_private_subnets = var.enable_vpc ? module.comet_vpc[0].private_subnets : var.comet_private_subnets
@@ -89,6 +96,7 @@ module "comet_elasticache" {
8996
source = "./modules/comet_elasticache"
9097
count = var.enable_elasticache ? 1 : 0
9198
environment = var.environment
99+
common_tags = local.all_tags
92100

93101
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
94102
elasticache_private_subnets = var.enable_vpc ? module.comet_vpc[0].private_subnets : var.comet_private_subnets
@@ -108,6 +116,7 @@ module "comet_rds" {
108116
source = "./modules/comet_rds"
109117
count = var.enable_rds ? 1 : 0
110118
environment = var.environment
119+
common_tags = local.all_tags
111120

112121
availability_zones = var.enable_vpc ? module.comet_vpc[0].azs : var.availability_zones
113122
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
@@ -131,6 +140,7 @@ module "comet_s3" {
131140
source = "./modules/comet_s3"
132141
count = var.enable_s3 ? 1 : 0
133142
environment = var.environment
143+
common_tags = local.all_tags
134144

135145
comet_s3_bucket = var.s3_bucket_name
136146
s3_force_destroy = var.s3_force_destroy

modules/comet_ec2/main.tf

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ locals {
44
https_port = 443
55
any_port = 0
66
cidr_anywhere = "0.0.0.0/0"
7-
8-
tags = {
9-
Terraform = "true"
10-
Environment = var.environment
11-
}
127
}
138

149
data "aws_ami" "al2" {
@@ -145,12 +140,16 @@ resource "aws_instance" "comet_ec2" {
145140
root_block_device {
146141
volume_type = var.comet_ec2_volume_type
147142
volume_size = var.comet_ec2_volume_size
143+
tags = var.common_tags
148144
}
149145

150-
tags = merge(local.tags, {
151-
Name = "${var.environment}-comet-ml-${count.index}"
152-
})
153-
146+
tags = merge(
147+
var.common_tags,
148+
{
149+
Name = "${var.environment}-comet-ml-${count.index}"
150+
}
151+
)
152+
154153
lifecycle {
155154
create_before_destroy = true
156155
}
@@ -161,7 +160,6 @@ resource "aws_eip" "comet_ec2_eip" {
161160
instance = aws_instance.comet_ec2[0].id
162161
domain = "vpc"
163162
}
164-
165163
resource "aws_security_group" "comet_ec2_sg" {
166164
name = "comet_${var.environment}_ec2_sg"
167165
description = "Comet EC2 instance security group"

modules/comet_ec2/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ variable "comet_ec2_s3_iam_policy" {
6868
variable "comet_ec2_alb_sg" {
6969
description = "ID of the security group attached to an associated application load balancer, for creating ingress EC2 SG rule"
7070
type = string
71-
}
71+
}
72+
73+
variable "common_tags" {
74+
type = map(string)
75+
description = "A map of common tags"
76+
default = {}
77+
}

modules/comet_ec2_alb/main.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ locals {
33
https_port = 443
44
any_port = 0
55
cidr_anywhere = "0.0.0.0/0"
6-
7-
tags = {
8-
Terraform = "true"
9-
Environment = var.environment
10-
}
116
}
127

138
resource "aws_security_group" "comet_alb_sg" {
@@ -43,6 +38,7 @@ resource "aws_vpc_security_group_egress_rule" "comet_ec2_alb_egress" {
4338
module "alb" {
4439
source = "terraform-aws-modules/alb/aws"
4540
version = "~> 8.0"
41+
tags = var.common_tags
4642

4743
name = "comet-${var.environment}-alb"
4844

@@ -82,6 +78,4 @@ module "alb" {
8278
}
8379
}
8480
]
85-
86-
tags = local.tags
8781
}

modules/comet_ec2_alb/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ variable "public_subnets" {
1616
variable "ssl_certificate_arn" {
1717
description = "ARN of the ACM certificate to use for the ALB"
1818
type = string
19-
}
19+
}
20+
21+
variable "common_tags" {
22+
type = map(string)
23+
description = "A map of common tags"
24+
default = {}
25+
}

0 commit comments

Comments
 (0)