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 7 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.

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

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

module "comet_vpc" {
Expand All @@ -18,6 +21,8 @@ module "comet_vpc" {

eks_enabled = var.enable_eks
single_nat_gateway = var.single_nat_gateway

common_tags = local.merged_tags
}

module "comet_ec2" {
Expand All @@ -40,6 +45,8 @@ module "comet_ec2" {

s3_enabled = var.enable_s3
comet_ec2_s3_iam_policy = var.enable_s3 ? module.comet_s3[0].comet_s3_iam_policy_arn : null

common_tags = local.merged_tags
}

module "comet_ec2_alb" {
Expand All @@ -50,6 +57,8 @@ module "comet_ec2_alb" {
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
ssl_certificate_arn = var.enable_ec2_alb ? var.ssl_certificate_arn : null

common_tags = local.merged_tags
}

module "comet_eks" {
Expand Down Expand Up @@ -82,6 +91,8 @@ module "comet_eks" {
eks_druid_node_count = var.eks_druid_node_count
eks_airflow_instance_type = var.eks_airflow_instance_type
eks_airflow_node_count = var.eks_airflow_node_count

common_tags = local.merged_tags
}

module "comet_elasticache" {
Expand All @@ -101,6 +112,8 @@ module "comet_elasticache" {
elasticache_num_cache_nodes = var.elasticache_num_cache_nodes
elasticache_transit_encryption = var.elasticache_transit_encryption
elasticache_auth_token = var.elasticache_auth_token

common_tags = local.merged_tags
}

module "comet_rds" {
Expand All @@ -124,6 +137,8 @@ module "comet_rds" {
rds_preferred_backup_window = var.rds_preferred_backup_window
rds_database_name = var.rds_database_name
rds_root_password = var.rds_root_password

common_tags = local.merged_tags
}

module "comet_s3" {
Expand All @@ -135,4 +150,6 @@ module "comet_s3" {
s3_force_destroy = var.s3_force_destroy

enable_mpm_infra = var.enable_mpm_infra

common_tags = local.merged_tags
}
5 changes: 1 addition & 4 deletions modules/comet_ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ locals {
any_port = 0
cidr_anywhere = "0.0.0.0/0"

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

data "aws_ami" "al2" {
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 = {}
}
5 changes: 1 addition & 4 deletions modules/comet_ec2_alb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ locals {
any_port = 0
cidr_anywhere = "0.0.0.0/0"

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

resource "aws_security_group" "comet_alb_sg" {
Expand Down
8 changes: 7 additions & 1 deletion modules/comet_ec2_alb/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ variable "public_subnets" {
variable "ssl_certificate_arn" {
description = "ARN of the ACM certificate to use for the ALB"
type = string
}
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
8 changes: 3 additions & 5 deletions modules/comet_eks/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
locals {
tags = {
Terraform = "true"
Environment = var.environment
}
tags = var.common_tags

volume_type = "gp3"
volume_encrypted = false
volume_delete_on_termination = true
}
}

data "aws_iam_policy" "ebs_csi_policy" {
arn = "arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy"
Expand Down
8 changes: 7 additions & 1 deletion modules/comet_eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ variable "eks_airflow_instance_type" {
variable "eks_airflow_node_count" {
description = "Instance count for EKS Airflow nodes"
type = number
}
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
5 changes: 1 addition & 4 deletions modules/comet_elasticache/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
locals {
redis_port = 6379

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

resource "aws_elasticache_replication_group" "comet-ml-ec-redis" {
Expand Down
8 changes: 7 additions & 1 deletion modules/comet_elasticache/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ variable "elasticache_auth_token" {
description = "Auth token for ElastiCache"
type = string
default = null
}
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
5 changes: 1 addition & 4 deletions modules/comet_rds/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
locals {
mysql_port = 3306

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

resource "aws_db_subnet_group" "comet-ml-rds-subnet" {
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 = {}
}
6 changes: 2 additions & 4 deletions modules/comet_s3/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
locals {
tags = {
Terraform = "true"
Environment = var.environment
}
tags = var.common_tags

suffix = substr(sha1("${var.environment}"), 0, 8)
}

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 = {}
}
5 changes: 1 addition & 4 deletions modules/comet_vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ locals {
vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

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

module "vpc" {
Expand Down
8 changes: 7 additions & 1 deletion modules/comet_vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ variable "eks_enabled" {
variable "single_nat_gateway" {
description = "Controls whether single NAT gateway used for all public subnets"
type = bool
}
}

variable "common_tags" {
type = map(string)
description = "A map of common tags"
default = {}
}
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
},
var.common_tags
)
}
}

provider "kubernetes" {
Expand Down
Loading