Skip to content

DT-436 adding tags to aws resources #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 102 additions & 82 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 19 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
data "aws_eks_cluster_auth" "this" {
count = var.enable_eks ? 1 : 0
name = module.comet_eks[0].cluster_name
}

locals {
resource_name = "comet-${var.environment}"
tags = {
Terraform = "true"
Environment = var.environment
}
all_tags = merge(
{
Terraform = "true"
Environment = var.environment_tag
},
var.common_tags
)
}

module "comet_vpc" {
source = "./modules/comet_vpc"
count = var.enable_vpc ? 1 : 0
environment = var.environment
common_tags = local.all_tags

eks_enabled = var.enable_eks
single_nat_gateway = var.single_nat_gateway
Expand All @@ -24,6 +23,7 @@ module "comet_ec2" {
source = "./modules/comet_ec2"
count = var.enable_ec2 ? 1 : 0
environment = var.environment
common_tags = local.all_tags

vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
comet_ec2_subnet = var.enable_vpc ? module.comet_vpc[0].public_subnets[0] : var.comet_public_subnets[0]
Expand All @@ -46,6 +46,7 @@ module "comet_ec2_alb" {
source = "./modules/comet_ec2_alb"
count = var.enable_ec2_alb ? 1 : 0
environment = var.environment
common_tags = local.all_tags

vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
public_subnets = var.enable_vpc ? module.comet_vpc[0].public_subnets : var.comet_public_subnets
Expand All @@ -56,6 +57,12 @@ module "comet_eks" {
source = "./modules/comet_eks"
count = var.enable_eks ? 1 : 0
environment = var.environment
common_tags = local.all_tags

providers = {
kubernetes = kubernetes.eks
helm = helm.eks
}

vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
eks_private_subnets = var.enable_vpc ? module.comet_vpc[0].private_subnets : var.comet_private_subnets
Expand Down Expand Up @@ -88,6 +95,7 @@ module "comet_elasticache" {
source = "./modules/comet_elasticache"
count = var.enable_elasticache ? 1 : 0
environment = var.environment
common_tags = local.all_tags

vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
elasticache_private_subnets = var.enable_vpc ? module.comet_vpc[0].private_subnets : var.comet_private_subnets
Expand All @@ -107,6 +115,7 @@ module "comet_rds" {
source = "./modules/comet_rds"
count = var.enable_rds ? 1 : 0
environment = var.environment
common_tags = local.all_tags

availability_zones = var.enable_vpc ? module.comet_vpc[0].azs : var.availability_zones
vpc_id = var.enable_vpc ? module.comet_vpc[0].vpc_id : var.comet_vpc_id
Expand All @@ -130,6 +139,7 @@ module "comet_s3" {
source = "./modules/comet_s3"
count = var.enable_s3 ? 1 : 0
environment = var.environment
common_tags = local.all_tags

comet_s3_bucket = var.s3_bucket_name
s3_force_destroy = var.s3_force_destroy
Expand Down
18 changes: 8 additions & 10 deletions modules/comet_ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ locals {
https_port = 443
any_port = 0
cidr_anywhere = "0.0.0.0/0"

tags = {
Terraform = "true"
Environment = var.environment
}
}

data "aws_ami" "al2" {
Expand Down Expand Up @@ -145,12 +140,16 @@ resource "aws_instance" "comet_ec2" {
root_block_device {
volume_type = var.comet_ec2_volume_type
volume_size = var.comet_ec2_volume_size
tags = var.common_tags
}

tags = merge(local.tags, {
Name = "${var.environment}-comet-ml-${count.index}"
})

tags = merge(
var.common_tags,
{
Name = "${var.environment}-comet-ml-${count.index}"
}
)

lifecycle {
create_before_destroy = true
}
Expand All @@ -161,7 +160,6 @@ resource "aws_eip" "comet_ec2_eip" {
instance = aws_instance.comet_ec2[0].id
domain = "vpc"
}

resource "aws_security_group" "comet_ec2_sg" {
name = "comet_${var.environment}_ec2_sg"
description = "Comet EC2 instance security group"
Expand Down
8 changes: 7 additions & 1 deletion modules/comet_ec2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ variable "comet_ec2_s3_iam_policy" {
variable "comet_ec2_alb_sg" {
description = "ID of the security group attached to an associated application load balancer, for creating ingress EC2 SG rule"
type = string
}
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
8 changes: 1 addition & 7 deletions modules/comet_ec2_alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ locals {
https_port = 443
any_port = 0
cidr_anywhere = "0.0.0.0/0"

tags = {
Terraform = "true"
Environment = var.environment
}
}

resource "aws_security_group" "comet_alb_sg" {
Expand Down Expand Up @@ -43,6 +38,7 @@ resource "aws_vpc_security_group_egress_rule" "comet_ec2_alb_egress" {
module "alb" {
source = "terraform-aws-modules/alb/aws"
version = "~> 8.0"
tags = var.common_tags

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

Expand Down Expand Up @@ -82,6 +78,4 @@ module "alb" {
}
}
]

tags = local.tags
}
Loading