From 6aa7521e953bd8bb947bedd2c2a67f21e6532b6e Mon Sep 17 00:00:00 2001 From: roiklorin Date: Wed, 28 Aug 2024 13:46:19 +0300 Subject: [PATCH] Populating additional tags (#437) * adding additional tags for poc deployments other than dfs_deployment and changing additional tags var in the intallation deployment directory to match that of dfs_deployment (changed type to map). * changed [] to {} as additional tags' default value in installation directory * deleted local.additional_tags in sonar multi account * fixed typos --- .../dsf_single_account_deployment/main.tf | 3 +-- .../dsf_single_account_deployment/variables.tf | 18 ++++++------------ .../sonar_multi_account_deployment/main.tf | 3 +-- .../variables.tf | 18 ++++++------------ .../sonar_single_account_deployment/main.tf | 3 +-- .../variables.tf | 18 ++++++------------ examples/aws/poc/dsf_deployment/main.tf | 2 +- examples/aws/poc/dsf_deployment/variables.tf | 2 +- .../aws/poc/sonar_basic_deployment/main.tf | 2 +- .../poc/sonar_basic_deployment/variables.tf | 6 ++++++ examples/aws/poc/sonar_hadr_deployment/main.tf | 2 +- .../aws/poc/sonar_hadr_deployment/variables.tf | 6 ++++++ 12 files changed, 37 insertions(+), 46 deletions(-) diff --git a/examples/aws/installation/dsf_single_account_deployment/main.tf b/examples/aws/installation/dsf_single_account_deployment/main.tf index 010f5293b..e6457801c 100644 --- a/examples/aws/installation/dsf_single_account_deployment/main.tf +++ b/examples/aws/installation/dsf_single_account_deployment/main.tf @@ -11,8 +11,7 @@ locals { deployment_name_salted = join("-", [var.deployment_name, module.globals.salt]) password = var.password != null ? var.password : module.globals.random_password workstation_cidr = var.workstation_cidr != null ? var.workstation_cidr : local.workstation_cidr_24 - additional_tags = var.additional_tags != null ? { for item in var.additional_tags : split("=", item)[0] => split("=", item)[1] } : {} - tags = merge(module.globals.tags, { "deployment_name" = local.deployment_name_salted }, local.additional_tags) + tags = merge(module.globals.tags, var.additional_tags, { "deployment_name" = local.deployment_name_salted }) hub_main_private_key_file_path = var.hub_main_key_pair != null ? var.hub_main_key_pair.private_key_file_path : module.key_pair_hub_main[0].private_key_file_path hub_main_public_key_name = var.hub_main_key_pair != null ? var.hub_main_key_pair.public_key_name : module.key_pair_hub_main[0].key_pair.key_pair_name diff --git a/examples/aws/installation/dsf_single_account_deployment/variables.tf b/examples/aws/installation/dsf_single_account_deployment/variables.tf index 032c245f3..9da9da082 100644 --- a/examples/aws/installation/dsf_single_account_deployment/variables.tf +++ b/examples/aws/installation/dsf_single_account_deployment/variables.tf @@ -1,3 +1,9 @@ +variable "additional_tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} + variable "deployment_name" { type = string default = "imperva-dsf" @@ -19,18 +25,6 @@ variable "aws_region_2" { description = "The second AWS region for the deployed resources (e.g us-east-2)" } -variable "additional_tags" { - type = list(string) - default = [] - description = "Additional tags to add to the DSFKit resources. Put tags in the following format - Key: Name. For example - [\"Key1=Name1\", \"Key2=Name2\"]" - validation { - condition = alltrue([ - for tag_pair in var.additional_tags : can(regex("^([a-zA-Z0-9+\\-_.:/@]+)=([a-zA-Z0-9+\\-_.:/]+)$", tag_pair)) - ]) - error_message = "Invalid tag format. All values must be in the format of 'key=value', where 'key' is a valid AWS tag name and 'value' is a valid AWS tag value. Note that the '=' character is not allowed in either the key or the value." - } -} - variable "enable_sonar" { type = bool default = true diff --git a/examples/aws/installation/sonar_multi_account_deployment/main.tf b/examples/aws/installation/sonar_multi_account_deployment/main.tf index f4c26cba3..7913de5a3 100644 --- a/examples/aws/installation/sonar_multi_account_deployment/main.tf +++ b/examples/aws/installation/sonar_multi_account_deployment/main.tf @@ -10,8 +10,7 @@ locals { password = var.password != null ? var.password : module.globals.random_password workstation_cidr = var.workstation_cidr != null ? var.workstation_cidr : local.workstation_cidr_24 tarball_location = var.tarball_location != null ? var.tarball_location : module.globals.tarball_location - additional_tags = var.additional_tags != null ? { for item in var.additional_tags : split("=", item)[0] => split("=", item)[1] } : {} - tags = merge(module.globals.tags, { "deployment_name" = local.deployment_name_salted }, local.additional_tags) + tags = merge(module.globals.tags, var.additional_tags, { "deployment_name" = local.deployment_name_salted }) should_create_hub_main_key_pair = var.hub_main_key_pair == null ? true : false should_create_hub_dr_key_pair = var.hub_dr_key_pair == null ? true : false should_create_gw_main_key_pair = var.gw_main_key_pair == null ? true : false diff --git a/examples/aws/installation/sonar_multi_account_deployment/variables.tf b/examples/aws/installation/sonar_multi_account_deployment/variables.tf index b7525464a..c8ba2255a 100644 --- a/examples/aws/installation/sonar_multi_account_deployment/variables.tf +++ b/examples/aws/installation/sonar_multi_account_deployment/variables.tf @@ -1,3 +1,9 @@ +variable "additional_tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} + variable "deployment_name" { type = string default = "imperva-dsf" @@ -44,18 +50,6 @@ variable "aws_region_gw_dr" { description = "AWS region for the DR Agentless gateway (e.g us-east-1)" } -variable "additional_tags" { - type = list(string) - default = [] - description = "Additional tags to add to the DSFKit resources. Put tags in the following format - Key: Name. For example - [\"Key1=Name1\", \"Key2=Name2\"]" - validation { - condition = alltrue([ - for tag_pair in var.additional_tags : can(regex("^([a-zA-Z0-9+\\-_.:/@]+)=([a-zA-Z0-9+\\-_.:/]+)$", tag_pair)) - ]) - error_message = "Invalid tag format. All values must be in the format of 'key=value', where 'key' is a valid AWS tag name and 'value' is a valid AWS tag value. Note that the '=' character is not allowed in either the key or the value." - } -} - variable "subnet_hub_main" { type = string description = "AWS subnet id for the main DSF Hub (e.g subnet-xxxxxxxxxxxxxxxxx)" diff --git a/examples/aws/installation/sonar_single_account_deployment/main.tf b/examples/aws/installation/sonar_single_account_deployment/main.tf index 86701e48c..1f0d7d505 100644 --- a/examples/aws/installation/sonar_single_account_deployment/main.tf +++ b/examples/aws/installation/sonar_single_account_deployment/main.tf @@ -21,8 +21,7 @@ locals { password = var.password != null ? var.password : module.globals.random_password workstation_cidr = var.workstation_cidr != null ? var.workstation_cidr : local.workstation_cidr_24 tarball_location = var.tarball_location != null ? var.tarball_location : module.globals.tarball_location - additional_tags = var.additional_tags != null ? { for item in var.additional_tags : split("=", item)[0] => split("=", item)[1] } : {} - tags = merge(module.globals.tags, { "deployment_name" = local.deployment_name_salted }, local.additional_tags) + tags = merge(module.globals.tags, var.additional_tags, { "deployment_name" = local.deployment_name_salted }) should_create_hub_key_pair = var.hub_key_pair == null ? true : false should_create_gw_key_pair = var.gw_key_pair == null ? true : false } diff --git a/examples/aws/installation/sonar_single_account_deployment/variables.tf b/examples/aws/installation/sonar_single_account_deployment/variables.tf index 2c55cda66..df86781bb 100644 --- a/examples/aws/installation/sonar_single_account_deployment/variables.tf +++ b/examples/aws/installation/sonar_single_account_deployment/variables.tf @@ -1,3 +1,9 @@ +variable "additional_tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} + variable "deployment_name" { type = string default = "imperva-dsf" @@ -24,18 +30,6 @@ variable "sonar_version" { } } -variable "additional_tags" { - type = list(string) - default = [] - description = "Additional tags to add to the DSFKit resources. Put tags in the following format - Key: Name. For example - [\"Key1=Name1\", \"Key2=Name2\"]" - validation { - condition = alltrue([ - for tag_pair in var.additional_tags : can(regex("^([a-zA-Z0-9+\\-_.:/@]+)=([a-zA-Z0-9+\\-_.:/]+)$", tag_pair)) - ]) - error_message = "Invalid tag format. All values must be in the format of 'key=value', where 'key' is a valid AWS tag name and 'value' is a valid AWS tag value. Note that the '=' character is not allowed in either the key or the value." - } -} - variable "tarball_location" { type = object({ s3_bucket = string diff --git a/examples/aws/poc/dsf_deployment/main.tf b/examples/aws/poc/dsf_deployment/main.tf index 49de03716..67c620428 100644 --- a/examples/aws/poc/dsf_deployment/main.tf +++ b/examples/aws/poc/dsf_deployment/main.tf @@ -31,6 +31,6 @@ locals { deployment_name_salted = join("-", [var.deployment_name, module.globals.salt]) password = var.password != null ? var.password : module.globals.random_password workstation_cidr = var.workstation_cidr != null ? var.workstation_cidr : local.workstation_cidr_24 - tags = merge(module.globals.tags, var.tags, { "deployment_name" = local.deployment_name_salted }) + tags = merge(module.globals.tags, var.additional_tags, { "deployment_name" = local.deployment_name_salted }) private_key_file_path = module.key_pair.private_key_file_path } diff --git a/examples/aws/poc/dsf_deployment/variables.tf b/examples/aws/poc/dsf_deployment/variables.tf index 8e755ae50..93a56fb08 100644 --- a/examples/aws/poc/dsf_deployment/variables.tf +++ b/examples/aws/poc/dsf_deployment/variables.tf @@ -1,4 +1,4 @@ -variable "tags" { +variable "additional_tags" { description = "A map of tags to add to all resources" type = map(string) default = {} diff --git a/examples/aws/poc/sonar_basic_deployment/main.tf b/examples/aws/poc/sonar_basic_deployment/main.tf index e78591241..ad334d089 100644 --- a/examples/aws/poc/sonar_basic_deployment/main.tf +++ b/examples/aws/poc/sonar_basic_deployment/main.tf @@ -37,7 +37,7 @@ locals { password = var.password != null ? var.password : module.globals.random_password workstation_cidr = var.workstation_cidr != null ? var.workstation_cidr : local.workstation_cidr_24 tarball_location = module.globals.tarball_location - tags = merge(module.globals.tags, { "deployment_name" = local.deployment_name_salted }) + tags = merge(module.globals.tags, var.additional_tags,{ "deployment_name" = local.deployment_name_salted }) hub_subnet_id = var.subnet_ids != null ? var.subnet_ids.hub_subnet_id : module.vpc[0].public_subnets[0] gw_subnet_id = var.subnet_ids != null ? var.subnet_ids.gw_subnet_id : module.vpc[0].private_subnets[0] db_subnet_ids = var.subnet_ids != null ? var.subnet_ids.db_subnet_ids : module.vpc[0].public_subnets diff --git a/examples/aws/poc/sonar_basic_deployment/variables.tf b/examples/aws/poc/sonar_basic_deployment/variables.tf index 2451fdaba..91c732c3e 100644 --- a/examples/aws/poc/sonar_basic_deployment/variables.tf +++ b/examples/aws/poc/sonar_basic_deployment/variables.tf @@ -1,3 +1,9 @@ +variable "additional_tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} + variable "deployment_name" { type = string default = "imperva-dsf" diff --git a/examples/aws/poc/sonar_hadr_deployment/main.tf b/examples/aws/poc/sonar_hadr_deployment/main.tf index 90c300e99..ce5aac818 100644 --- a/examples/aws/poc/sonar_hadr_deployment/main.tf +++ b/examples/aws/poc/sonar_hadr_deployment/main.tf @@ -35,7 +35,7 @@ locals { password = var.password != null ? var.password : module.globals.random_password workstation_cidr = var.workstation_cidr != null ? var.workstation_cidr : local.workstation_cidr_24 tarball_location = var.tarball_location != null ? var.tarball_location : module.globals.tarball_location - tags = merge(module.globals.tags, { "deployment_name" = local.deployment_name_salted }) + tags = merge(module.globals.tags, var.additional_tags, { "deployment_name" = local.deployment_name_salted }) main_hub_subnet_id = var.subnet_ids != null ? var.subnet_ids.main_hub_subnet_id : module.vpc[0].public_subnets[0] dr_hub_subnet_id = var.subnet_ids != null ? var.subnet_ids.dr_hub_subnet_id : module.vpc[0].public_subnets[1] main_gws_subnet_id = var.subnet_ids != null ? var.subnet_ids.main_gws_subnet_id : module.vpc[0].private_subnets[0] diff --git a/examples/aws/poc/sonar_hadr_deployment/variables.tf b/examples/aws/poc/sonar_hadr_deployment/variables.tf index 00f96419c..7ac8bd376 100644 --- a/examples/aws/poc/sonar_hadr_deployment/variables.tf +++ b/examples/aws/poc/sonar_hadr_deployment/variables.tf @@ -1,3 +1,9 @@ +variable "additional_tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} + variable "deployment_name" { type = string default = "imperva-dsf"