From d12270a4647944412c1ee27f22e2279afc5ac16a Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Wed, 27 Mar 2024 13:16:06 -0700 Subject: [PATCH 1/9] creates special character db pwds --- modules/database/main.tf | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/database/main.tf b/modules/database/main.tf index d7b632b7..8062932e 100644 --- a/modules/database/main.tf +++ b/modules/database/main.tf @@ -2,8 +2,10 @@ # SPDX-License-Identifier: MPL-2.0 resource "random_string" "postgresql_password" { - length = 128 - special = false + length = 128 + special = true + min_special = 4 + override_special = "+(!]&;$)" } resource "aws_security_group" "postgresql" { @@ -59,7 +61,7 @@ resource "aws_db_instance" "postgresql" { instance_class = var.db_size password = random_string.postgresql_password.result # no special characters allowed - username = var.db_username + username = var.db_username allow_major_version_upgrade = false apply_immediately = true @@ -74,12 +76,12 @@ resource "aws_db_instance" "postgresql" { max_allocated_storage = 0 multi_az = true # no special characters allowed - db_name = var.db_name - port = 5432 - publicly_accessible = false - skip_final_snapshot = true - storage_encrypted = true - kms_key_id = var.kms_key_arn - storage_type = "gp2" - vpc_security_group_ids = [aws_security_group.postgresql.id] + db_name = var.db_name + port = 5432 + publicly_accessible = false + skip_final_snapshot = true + storage_encrypted = true + kms_key_id = var.kms_key_arn + storage_type = "gp2" + vpc_security_group_ids = [aws_security_group.postgresql.id] } From 71eee6496085f6a72d83b1e65f25f74c7677e036 Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 10:36:30 -0700 Subject: [PATCH 2/9] adds escapes for heredoc to compose --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 4ba7ef1c..69c86ee9 100644 --- a/main.tf +++ b/main.tf @@ -151,7 +151,7 @@ module "runtime_container_engine_config" { database_name = local.database.name database_user = local.database.username - database_password = local.database.password + database_password = replace(local.database.password, "$", "\\$\\$") database_host = local.database.endpoint database_parameters = local.database.parameters From d859734f2fae9c06a000bb58b1be19cf2fd135a8 Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 10:50:44 -0700 Subject: [PATCH 3/9] moves replace to config --- locals.tf | 8 +++++++- main.tf | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/locals.tf b/locals.tf index 44a163e8..9059de4d 100644 --- a/locals.tf +++ b/locals.tf @@ -21,7 +21,13 @@ locals { network_private_subnet_cidrs = var.deploy_vpc ? module.networking[0].network_private_subnet_cidrs : var.network_private_subnet_cidrs database = try( - module.database[0], + { + name = module.database.name + password = replace(module.database.password, "$", "\\$\\$") + endpoint = module.database.endpoint + username = module.database.username + parameters = module.database.parameters + }, { name = null password = null diff --git a/main.tf b/main.tf index 69c86ee9..4ba7ef1c 100644 --- a/main.tf +++ b/main.tf @@ -151,7 +151,7 @@ module "runtime_container_engine_config" { database_name = local.database.name database_user = local.database.username - database_password = replace(local.database.password, "$", "\\$\\$") + database_password = local.database.password database_host = local.database.endpoint database_parameters = local.database.parameters From 8c9970cd6c787136a8d539e2c3a71c661b30ce9a Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 10:55:25 -0700 Subject: [PATCH 4/9] removes try and adds index --- locals.tf | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/locals.tf b/locals.tf index 9059de4d..b5cbd139 100644 --- a/locals.tf +++ b/locals.tf @@ -20,22 +20,14 @@ locals { network_public_subnets = var.deploy_vpc ? module.networking[0].network_public_subnets : var.network_public_subnets network_private_subnet_cidrs = var.deploy_vpc ? module.networking[0].network_private_subnet_cidrs : var.network_private_subnet_cidrs - database = try( + database = { - name = module.database.name - password = replace(module.database.password, "$", "\\$\\$") - endpoint = module.database.endpoint - username = module.database.username - parameters = module.database.parameters - }, - { - name = null - password = null - endpoint = null - username = null - parameters = null + name = module.database[0].name + password = replace(module.database[0].password, "$", "\\$\\$") + endpoint = module.database[0].endpoint + username = module.database[0].username + parameters = module.database[0].parameters } - ) object_storage = try( module.object_storage[0], From a5765c417d21c462e93b86c555b2d4ecb5582597 Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 10:57:38 -0700 Subject: [PATCH 5/9] try with index --- locals.tf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/locals.tf b/locals.tf index b5cbd139..6d688c9e 100644 --- a/locals.tf +++ b/locals.tf @@ -20,14 +20,22 @@ locals { network_public_subnets = var.deploy_vpc ? module.networking[0].network_public_subnets : var.network_public_subnets network_private_subnet_cidrs = var.deploy_vpc ? module.networking[0].network_private_subnet_cidrs : var.network_private_subnet_cidrs - database = + database = try( { name = module.database[0].name password = replace(module.database[0].password, "$", "\\$\\$") endpoint = module.database[0].endpoint username = module.database[0].username parameters = module.database[0].parameters + }, + { + name = null + password = null + endpoint = null + username = null + parameters = null } + ) object_storage = try( module.object_storage[0], From d020c18f2e3f97562779ef7b642dcb6f0371f438 Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 11:04:53 -0700 Subject: [PATCH 6/9] makes special chars change further down --- locals.tf | 8 +------- main.tf | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/locals.tf b/locals.tf index 6d688c9e..44a163e8 100644 --- a/locals.tf +++ b/locals.tf @@ -21,13 +21,7 @@ locals { network_private_subnet_cidrs = var.deploy_vpc ? module.networking[0].network_private_subnet_cidrs : var.network_private_subnet_cidrs database = try( - { - name = module.database[0].name - password = replace(module.database[0].password, "$", "\\$\\$") - endpoint = module.database[0].endpoint - username = module.database[0].username - parameters = module.database[0].parameters - }, + module.database[0], { name = null password = null diff --git a/main.tf b/main.tf index 4ba7ef1c..5f6fb10c 100644 --- a/main.tf +++ b/main.tf @@ -117,7 +117,7 @@ module "database" { # Docker Compose File Config for TFE on instance(s) using Flexible Deployment Options # ------------------------------------------------------------------------------------ module "runtime_container_engine_config" { - source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=main" + source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=special-db" count = var.is_replicated_deployment ? 0 : 1 tfe_license = var.hc_license From f2608ec1c7c8610094a0f82551c2acc6543d84e0 Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 11:28:43 -0700 Subject: [PATCH 7/9] sanity check --- .idea/.gitignore | 8 ++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/terraform-aws-terraform-enterprise.iml | 16 ++++++++++++++++ .idea/vcs.xml | 6 ++++++ main.tf | 2 +- 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/terraform-aws-terraform-enterprise.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..639900d1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..4401a25c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/terraform-aws-terraform-enterprise.iml b/.idea/terraform-aws-terraform-enterprise.iml new file mode 100644 index 00000000..94316b46 --- /dev/null +++ b/.idea/terraform-aws-terraform-enterprise.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.tf b/main.tf index 5f6fb10c..4ba7ef1c 100644 --- a/main.tf +++ b/main.tf @@ -117,7 +117,7 @@ module "database" { # Docker Compose File Config for TFE on instance(s) using Flexible Deployment Options # ------------------------------------------------------------------------------------ module "runtime_container_engine_config" { - source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=special-db" + source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=main" count = var.is_replicated_deployment ? 0 : 1 tfe_license = var.hc_license From 46aca2857f9a7e05e5e5b24342f1590646cc005a Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 12:21:26 -0700 Subject: [PATCH 8/9] adds back special chars --- .idea/.gitignore | 8 -------- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/terraform-aws-terraform-enterprise.iml | 16 ---------------- .idea/vcs.xml | 6 ------ main.tf | 2 +- 6 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/terraform-aws-terraform-enterprise.iml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b81..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 639900d1..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 4401a25c..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/terraform-aws-terraform-enterprise.iml b/.idea/terraform-aws-terraform-enterprise.iml deleted file mode 100644 index 94316b46..00000000 --- a/.idea/terraform-aws-terraform-enterprise.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddf..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/main.tf b/main.tf index 4ba7ef1c..5f6fb10c 100644 --- a/main.tf +++ b/main.tf @@ -117,7 +117,7 @@ module "database" { # Docker Compose File Config for TFE on instance(s) using Flexible Deployment Options # ------------------------------------------------------------------------------------ module "runtime_container_engine_config" { - source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=main" + source = "git::https://github.com/hashicorp/terraform-random-tfe-utility//modules/runtime_container_engine_config?ref=special-db" count = var.is_replicated_deployment ? 0 : 1 tfe_license = var.hc_license From acb25571326f66ad5b6fd2650256f226d8aaecc1 Mon Sep 17 00:00:00 2001 From: Theo Skolnik Date: Thu, 28 Mar 2024 13:36:05 -0700 Subject: [PATCH 9/9] forces dollar sign --- modules/database/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/database/main.tf b/modules/database/main.tf index 8062932e..53d49a68 100644 --- a/modules/database/main.tf +++ b/modules/database/main.tf @@ -5,7 +5,7 @@ resource "random_string" "postgresql_password" { length = 128 special = true min_special = 4 - override_special = "+(!]&;$)" + override_special = "$" } resource "aws_security_group" "postgresql" {