From ac5f70617862f2e2a87a90bb0c0d33419e74c628 Mon Sep 17 00:00:00 2001 From: nitrocode <7775707+nitrocode@users.noreply.github.com> Date: Mon, 4 Jul 2022 11:59:46 -0400 Subject: [PATCH] Add count logic (#7) * Add count logic * Auto Format Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com> --- .github/renovate.json | 2 +- README.md | 19 +++++++++++-------- README.yaml | 14 +++++++++----- docs/terraform.md | 1 - examples/complete/versions.tf | 8 ++------ iam.tf | 2 +- main.tf | 16 +++++++++++++--- outputs.tf | 24 ++++++++++++------------ versions.tf | 6 +----- 9 files changed, 50 insertions(+), 42 deletions(-) diff --git a/.github/renovate.json b/.github/renovate.json index ae4f0aa..a780298 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -4,9 +4,9 @@ ":preserveSemverRanges" ], "labels": ["auto-update"], + "dependencyDashboardAutoclose": true, "enabledManagers": ["terraform"], "terraform": { "ignorePaths": ["**/context.tf", "examples/**"] } } - diff --git a/README.md b/README.md index a3f30f8..bf6329a 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,8 @@ For automated tests of the complete example using [bats](https://github.com/bats ```hcl module "vpc" { source = "cloudposse/vpc/aws" - version = "0.21.1" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" cidr_block = "172.16.0.0/16" @@ -111,7 +112,8 @@ module "vpc" { module "subnets" { source = "cloudposse/dynamic-subnets/aws" - version = "0.38.0" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" availability_zones = var.availability_zones vpc_id = module.vpc.vpc_id @@ -124,7 +126,7 @@ module "subnets" { } resource "random_password" "admin_password" { -count = var.database_password == "" || var.database_password == null ? 1 : 0 + count = var.database_password == "" || var.database_password == null ? 1 : 0 length = 33 special = false override_special = "!#$%^&*()<>-_" @@ -150,7 +152,8 @@ locals { module "rds_instance" { source = "cloudposse/rds/aws" - version = "0.34.0" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" database_name = var.database_name database_user = var.database_user @@ -207,7 +210,6 @@ module "rds_proxy" { context = module.this.context } - ``` @@ -238,7 +240,6 @@ Available targets: |------|---------| | [terraform](#requirement\_terraform) | >= 0.13.0 | | [aws](#requirement\_aws) | >= 3.1.15 | -| [null](#requirement\_null) | >= 2.0 | ## Providers @@ -476,14 +477,16 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply ### Contributors -| [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]
[Andriy Knysh][aknysh_homepage] | -|---|---| +| [![Erik Osterman][osterman_avatar]][osterman_homepage]
[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]
[Andriy Knysh][aknysh_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]
[RB][nitrocode_homepage] | +|---|---|---| [osterman_homepage]: https://github.com/osterman [osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png [aknysh_homepage]: https://github.com/aknysh [aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png + [nitrocode_homepage]: https://github.com/nitrocode + [nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png [![README Footer][readme_footer_img]][readme_footer_link] [![Beacon][beacon]][website] diff --git a/README.yaml b/README.yaml index 4d5efb3..0f3916b 100644 --- a/README.yaml +++ b/README.yaml @@ -66,7 +66,8 @@ usage: |2- ```hcl module "vpc" { source = "cloudposse/vpc/aws" - version = "0.21.1" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" cidr_block = "172.16.0.0/16" @@ -75,7 +76,8 @@ usage: |2- module "subnets" { source = "cloudposse/dynamic-subnets/aws" - version = "0.38.0" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" availability_zones = var.availability_zones vpc_id = module.vpc.vpc_id @@ -88,7 +90,7 @@ usage: |2- } resource "random_password" "admin_password" { - count = var.database_password == "" || var.database_password == null ? 1 : 0 + count = var.database_password == "" || var.database_password == null ? 1 : 0 length = 33 special = false override_special = "!#$%^&*()<>-_" @@ -114,7 +116,8 @@ usage: |2- module "rds_instance" { source = "cloudposse/rds/aws" - version = "0.34.0" + # Cloud Posse recommends pinning every module to a specific version + # version = "x.x.x" database_name = var.database_name database_user = var.database_user @@ -171,7 +174,6 @@ usage: |2- context = module.this.context } - ``` examples: |- @@ -186,3 +188,5 @@ contributors: github: osterman - name: Andriy Knysh github: aknysh + - name: RB + github: nitrocode diff --git a/docs/terraform.md b/docs/terraform.md index 9b3b592..82b5c22 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -5,7 +5,6 @@ |------|---------| | [terraform](#requirement\_terraform) | >= 0.13.0 | | [aws](#requirement\_aws) | >= 3.1.15 | -| [null](#requirement\_null) | >= 2.0 | ## Providers diff --git a/examples/complete/versions.tf b/examples/complete/versions.tf index 971ae24..e7d0b45 100644 --- a/examples/complete/versions.tf +++ b/examples/complete/versions.tf @@ -4,11 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 2.0" - } - null = { - source = "hashicorp/null" - version = ">= 2.0" + version = ">= 3.1.15" } } -} +} \ No newline at end of file diff --git a/iam.tf b/iam.tf index 0aedce5..f7e4bb8 100644 --- a/iam.tf +++ b/iam.tf @@ -1,7 +1,7 @@ # https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.html locals { - iam_role_enabled = var.existing_iam_role_arn == null || var.existing_iam_role_arn == "" ? true : false + iam_role_enabled = local.enabled && (var.existing_iam_role_arn == null || var.existing_iam_role_arn == "") asm_secret_arns = compact([for auth in var.auth : lookup(auth, "secret_arn", "")]) kms_key_arn = join("", data.aws_kms_key.this.*.arn) iam_role_arn = local.iam_role_enabled ? join("", aws_iam_role.this.*.arn) : var.existing_iam_role_arn diff --git a/main.tf b/main.tf index 49d1277..2798052 100644 --- a/main.tf +++ b/main.tf @@ -1,4 +1,10 @@ +locals { + enabled = module.this.enabled +} + resource "aws_db_proxy" "this" { + count = local.enabled ? 1 : 0 + name = module.this.id debug_logging = var.debug_logging engine_family = var.engine_family @@ -23,7 +29,9 @@ resource "aws_db_proxy" "this" { } resource "aws_db_proxy_default_target_group" "this" { - db_proxy_name = aws_db_proxy.this.name + count = local.enabled ? 1 : 0 + + db_proxy_name = join("", aws_db_proxy.this[*].name) dynamic "connection_pool_config" { for_each = ( @@ -42,8 +50,10 @@ resource "aws_db_proxy_default_target_group" "this" { } resource "aws_db_proxy_target" "this" { + count = local.enabled ? 1 : 0 + db_instance_identifier = var.db_instance_identifier db_cluster_identifier = var.db_cluster_identifier - db_proxy_name = aws_db_proxy.this.name - target_group_name = aws_db_proxy_default_target_group.this.name + db_proxy_name = join("", aws_db_proxy.this[*].name) + target_group_name = join("", aws_db_proxy_default_target_group.this[*].name) } diff --git a/outputs.tf b/outputs.tf index b213da8..2922f76 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,60 +1,60 @@ output "proxy_id" { - value = aws_db_proxy.this.id + value = join("", aws_db_proxy.this[*].id) description = "Proxy ID" } output "proxy_arn" { - value = aws_db_proxy.this.arn + value = join("", aws_db_proxy.this[*].arn) description = "Proxy ARN" } output "proxy_endpoint" { - value = aws_db_proxy.this.endpoint + value = join("", aws_db_proxy.this[*].endpoint) description = "Proxy endpoint" } output "proxy_target_endpoint" { - value = aws_db_proxy_target.this.endpoint + value = join("", aws_db_proxy_target.this[*].endpoint) description = "Hostname for the target RDS DB Instance. Only returned for `RDS_INSTANCE` type" } output "proxy_target_id" { - value = aws_db_proxy_target.this.id + value = join("", aws_db_proxy_target.this[*].id) description = "Identifier of `db_proxy_name`, `target_group_name`, `target type` (e.g. `RDS_INSTANCE` or `TRACKED_CLUSTER`), and resource identifier separated by forward slashes (`/`)" } output "proxy_target_port" { - value = aws_db_proxy_target.this.port + value = join("", aws_db_proxy_target.this[*].port) description = "Port for the target RDS DB instance or Aurora DB cluster" } output "proxy_target_rds_resource_id" { - value = aws_db_proxy_target.this.rds_resource_id + value = join("", aws_db_proxy_target.this[*].rds_resource_id) description = "Identifier representing the DB instance or DB cluster target" } output "proxy_target_target_arn" { - value = aws_db_proxy_target.this.target_arn + value = join("", aws_db_proxy_target.this[*].target_arn) description = "Amazon Resource Name (ARN) for the DB instance or DB cluster" } output "proxy_target_tracked_cluster_id" { - value = aws_db_proxy_target.this.tracked_cluster_id + value = join("", aws_db_proxy_target.this[*].tracked_cluster_id) description = "DB Cluster identifier for the DB instance target. Not returned unless manually importing an `RDS_INSTANCE` target that is part of a DB cluster" } output "proxy_target_type" { - value = aws_db_proxy_target.this.type + value = join("", aws_db_proxy_target.this[*].type) description = "Type of target. e.g. `RDS_INSTANCE` or `TRACKED_CLUSTER`" } output "proxy_default_target_group_arn" { - value = aws_db_proxy_default_target_group.this.arn + value = join("", aws_db_proxy_default_target_group.this[*].arn) description = "The Amazon Resource Name (ARN) representing the default target group" } output "proxy_default_target_group_name" { - value = aws_db_proxy_default_target_group.this.name + value = join("", aws_db_proxy_default_target_group.this[*].name) description = "The name of the default target group" } diff --git a/versions.tf b/versions.tf index 7fe4e99..e7d0b45 100644 --- a/versions.tf +++ b/versions.tf @@ -6,9 +6,5 @@ terraform { source = "hashicorp/aws" version = ">= 3.1.15" } - null = { - source = "hashicorp/null" - version = ">= 2.0" - } } -} +} \ No newline at end of file