Skip to content
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

DT-436 adding tags to aws resources #25

Draft
wants to merge 9 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
8 changes: 7 additions & 1 deletion .terraform.lock.hcl

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

4 changes: 0 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ data "aws_eks_cluster_auth" "this" {

locals {
resource_name = "comet-${var.environment}"
tags = {
Terraform = "true"
Environment = var.environment
}
}

module "comet_vpc" {
Expand Down
16 changes: 7 additions & 9 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 @@ -147,10 +142,13 @@ resource "aws_instance" "comet_ec2" {
volume_size = var.comet_ec2_volume_size
}

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 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 = {}
}
7 changes: 0 additions & 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 @@ -82,6 +77,4 @@ module "alb" {
}
}
]

tags = local.tags
}
3 changes: 2 additions & 1 deletion modules/comet_ec2_alb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ variable "public_subnets" {
variable "ssl_certificate_arn" {
description = "ARN of the ACM certificate to use for the ALB"
type = string
}
}

7 changes: 0 additions & 7 deletions modules/comet_eks/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
locals {
tags = {
Terraform = "true"
Environment = var.environment
}
volume_type = "gp3"
volume_encrypted = false
volume_delete_on_termination = true
Expand Down Expand Up @@ -97,7 +93,6 @@ module "eks" {
}
} : {}
)
tags = local.tags
}


Expand Down Expand Up @@ -133,6 +128,4 @@ module "eks_blueprints_addons" {
enable_aws_cloudwatch_metrics = var.eks_aws_cloudwatch_metrics
enable_external_dns = var.eks_external_dns
external_dns_route53_zone_arns = var.eks_external_dns_r53_zones

tags = local.tags
}
2 changes: 1 addition & 1 deletion modules/comet_eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ variable "eks_airflow_instance_type" {
variable "eks_airflow_node_count" {
description = "Instance count for EKS Airflow nodes"
type = number
}
}
5 changes: 0 additions & 5 deletions modules/comet_elasticache/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
locals {
redis_port = 6379

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

resource "aws_elasticache_replication_group" "comet-ml-ec-redis" {
Expand Down
2 changes: 1 addition & 1 deletion modules/comet_elasticache/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ variable "elasticache_auth_token" {
description = "Auth token for ElastiCache"
type = string
default = null
}
}
14 changes: 6 additions & 8 deletions modules/comet_rds/main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
locals {
mysql_port = 3306

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

resource "aws_db_subnet_group" "comet-ml-rds-subnet" {
name = "cometml-rds-sgn-${var.environment}"
subnet_ids = var.rds_private_subnets
tags = merge(local.tags, {
Name = "cometml-rds-sng-${var.environment}"
})
tags = merge(
var.common_tags,
{
Name = "cometml-rds-sng-${var.environment}"
}
)
}

resource "aws_rds_cluster_instance" "comet-ml-rds-mysql" {
Expand Down
6 changes: 6 additions & 0 deletions modules/comet_rds/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ variable "rds_root_password" {
description = "Root password for RDS database"
type = string
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
31 changes: 18 additions & 13 deletions modules/comet_s3/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
locals {
tags = {
Terraform = "true"
Environment = var.environment
}
suffix = substr(sha1("${var.environment}"), 0, 8)
}

Expand All @@ -11,9 +7,12 @@ resource "aws_s3_bucket" "comet_s3_bucket" {

force_destroy = var.s3_force_destroy

tags = merge(local.tags, {
Name = var.comet_s3_bucket
})
tags = merge(
var.common_tags,
{
Name = var.comet_s3_bucket
}
)
}

resource "aws_s3_bucket" "comet_druid_bucket" {
Expand All @@ -23,9 +22,12 @@ resource "aws_s3_bucket" "comet_druid_bucket" {

force_destroy = var.s3_force_destroy

tags = merge(local.tags, {
Name = "comet-druid-${local.suffix}"
})
tags = merge(
var.common_tags,
{
Name = "comet-druid-${local.suffix}"
}
)
}

resource "aws_s3_bucket" "comet_airflow_bucket" {
Expand All @@ -35,9 +37,12 @@ resource "aws_s3_bucket" "comet_airflow_bucket" {

force_destroy = var.s3_force_destroy

tags = merge(local.tags, {
Name = "comet-airflow-${local.suffix}"
})
tags = merge(
var.common_tags,
{
Name = "comet-airflow-${local.suffix}"
}
)
}

resource "aws_iam_policy" "comet_s3_iam_policy" {
Expand Down
8 changes: 7 additions & 1 deletion modules/comet_s3/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ variable "s3_force_destroy" {
variable "enable_mpm_infra" {
description = "Sets buckets to be created for MPM Druid/Airflow"
type = bool
}
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
7 changes: 0 additions & 7 deletions modules/comet_vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ locals {
resource_name = "comet-${var.environment}"
vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

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

module "vpc" {
Expand Down Expand Up @@ -37,6 +32,4 @@ module "vpc" {
# if EKS deployment, set subnet tags for AWS Load Balancer Controller auto-discovery
public_subnet_tags = var.eks_enabled ? { "kubernetes.io/role/elb" = 1 } : null
private_subnet_tags = var.eks_enabled ? { "kubernetes.io/role/internal-elb" = 1 } : null

tags = local.tags
}
2 changes: 1 addition & 1 deletion modules/comet_vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ variable "eks_enabled" {
variable "single_nat_gateway" {
description = "Controls whether single NAT gateway used for all public subnets"
type = bool
}
}
10 changes: 10 additions & 0 deletions providers.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
provider "aws" {
region = var.region

default_tags {
tags = merge(
{
Terraform = "true"
Environment = var.environment_tag
},
var.common_tags
)
}
}

provider "kubernetes" {
Expand Down
Loading