From aa22d3f08b5eae6c81a730a94825eea4ad1a191a Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Wed, 10 May 2023 16:29:10 -0300 Subject: [PATCH] 20482: Allows the site admin to customize tags applied to every resource. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- tools/salt-install/terraform/aws/data-storage/locals.tf | 1 + tools/salt-install/terraform/aws/data-storage/main.tf | 5 +++-- tools/salt-install/terraform/aws/services/locals.tf | 1 + tools/salt-install/terraform/aws/services/main.tf | 5 +++-- tools/salt-install/terraform/aws/vpc/main.tf | 5 +++-- tools/salt-install/terraform/aws/vpc/outputs.tf | 4 ++++ tools/salt-install/terraform/aws/vpc/terraform.tfvars | 9 ++++++++- tools/salt-install/terraform/aws/vpc/variables.tf | 6 ++++++ 8 files changed, 29 insertions(+), 7 deletions(-) diff --git a/tools/salt-install/terraform/aws/data-storage/locals.tf b/tools/salt-install/terraform/aws/data-storage/locals.tf index 5b9f68969e..f8d611400f 100644 --- a/tools/salt-install/terraform/aws/data-storage/locals.tf +++ b/tools/salt-install/terraform/aws/data-storage/locals.tf @@ -5,4 +5,5 @@ locals { region_name = data.terraform_remote_state.vpc.outputs.region_name cluster_name = data.terraform_remote_state.vpc.outputs.cluster_name + custom_tags = data.terraform_remote_state.vpc.outputs.custom_tags } diff --git a/tools/salt-install/terraform/aws/data-storage/main.tf b/tools/salt-install/terraform/aws/data-storage/main.tf index 6f7e233fd8..a3ef8f010f 100644 --- a/tools/salt-install/terraform/aws/data-storage/main.tf +++ b/tools/salt-install/terraform/aws/data-storage/main.tf @@ -13,9 +13,10 @@ terraform { provider "aws" { region = local.region_name default_tags { - tags = { + tags = merge(local.custom_tags, { Arvados = local.cluster_name - } + Terraform = true + }) } } diff --git a/tools/salt-install/terraform/aws/services/locals.tf b/tools/salt-install/terraform/aws/services/locals.tf index 73de27780a..abba4aab73 100644 --- a/tools/salt-install/terraform/aws/services/locals.tf +++ b/tools/salt-install/terraform/aws/services/locals.tf @@ -16,4 +16,5 @@ locals { internal_service_hosts = data.terraform_remote_state.vpc.outputs.internal_service_hosts ssl_password_secret_name = "${local.cluster_name}-${var.ssl_password_secret_name_suffix}" instance_ami_id = var.instance_ami != "" ? var.instance_ami : data.aws_ami.debian-11.image_id + custom_tags = data.terraform_remote_state.vpc.outputs.custom_tags } diff --git a/tools/salt-install/terraform/aws/services/main.tf b/tools/salt-install/terraform/aws/services/main.tf index c528a12399..f7a2527c2c 100644 --- a/tools/salt-install/terraform/aws/services/main.tf +++ b/tools/salt-install/terraform/aws/services/main.tf @@ -13,9 +13,10 @@ terraform { provider "aws" { region = local.region_name default_tags { - tags = { + tags = merge(local.custom_tags, { Arvados = local.cluster_name - } + Terraform = true + }) } } diff --git a/tools/salt-install/terraform/aws/vpc/main.tf b/tools/salt-install/terraform/aws/vpc/main.tf index be5e57490d..5ac836b687 100644 --- a/tools/salt-install/terraform/aws/vpc/main.tf +++ b/tools/salt-install/terraform/aws/vpc/main.tf @@ -13,9 +13,10 @@ terraform { provider "aws" { region = var.region_name default_tags { - tags = { + tags = merge(var.custom_tags, { Arvados = var.cluster_name - } + Terraform = true + }) } } diff --git a/tools/salt-install/terraform/aws/vpc/outputs.tf b/tools/salt-install/terraform/aws/vpc/outputs.tf index ca11f5d0d8..b7974bd159 100644 --- a/tools/salt-install/terraform/aws/vpc/outputs.tf +++ b/tools/salt-install/terraform/aws/vpc/outputs.tf @@ -77,3 +77,7 @@ output "cluster_name" { output "domain_name" { value = var.domain_name } + +output "custom_tags" { + value = var.custom_tags +} diff --git a/tools/salt-install/terraform/aws/vpc/terraform.tfvars b/tools/salt-install/terraform/aws/vpc/terraform.tfvars index 32480f879a..573825696a 100644 --- a/tools/salt-install/terraform/aws/vpc/terraform.tfvars +++ b/tools/salt-install/terraform/aws/vpc/terraform.tfvars @@ -15,4 +15,11 @@ region_name = "us-east-1" # vpc_id = "vpc-" # sg_id = "sg-" # public_subnet_id = "subnet-" -# private_subnet_id = "subnet-" \ No newline at end of file +# private_subnet_id = "subnet-" + +# Optional custom tags to add to every resource. Default: {} +# custom_tags = { +# environment = "production" +# project = "Phoenix" +# owner = "jdoe" +# } \ No newline at end of file diff --git a/tools/salt-install/terraform/aws/vpc/variables.tf b/tools/salt-install/terraform/aws/vpc/variables.tf index e14c598085..ec6f5711b7 100644 --- a/tools/salt-install/terraform/aws/vpc/variables.tf +++ b/tools/salt-install/terraform/aws/vpc/variables.tf @@ -61,4 +61,10 @@ variable "public_subnet_id" { description = "Use existing public subnet instead of creating one for the cluster" type = string default = "" +} + +variable "custom_tags" { + description = "Apply customized tags to every resource on the cluster" + type = map(string) + default = {} } \ No newline at end of file -- 2.30.2