Skip to content

Commit

Permalink
Add count logic (#7)
Browse files Browse the repository at this point in the history
* Add count logic

* Auto Format

Co-authored-by: cloudpossebot <[email protected]>
  • Loading branch information
nitrocode and cloudpossebot committed Jul 4, 2022
1 parent 1c56cf6 commit ac5f706
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
":preserveSemverRanges"
],
"labels": ["auto-update"],
"dependencyDashboardAutoclose": true,
"enabledManagers": ["terraform"],
"terraform": {
"ignorePaths": ["**/context.tf", "examples/**"]
}
}

19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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 = "!#$%^&*()<>-_"
Expand All @@ -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
Expand Down Expand Up @@ -207,7 +210,6 @@ module "rds_proxy" {
context = module.this.context
}
```


Expand Down Expand Up @@ -238,7 +240,6 @@ Available targets:
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.1.15 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |

## Providers

Expand Down Expand Up @@ -476,14 +477,16 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
### Contributors

<!-- markdownlint-disable -->
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] |
|---|---|
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![RB][nitrocode_avatar]][nitrocode_homepage]<br/>[RB][nitrocode_homepage] |
|---|---|---|
<!-- markdownlint-restore -->

[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]
Expand Down
14 changes: 9 additions & 5 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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 = "!#$%^&*()<>-_"
Expand All @@ -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
Expand Down Expand Up @@ -171,7 +174,6 @@ usage: |2-
context = module.this.context
}
```
examples: |-
Expand All @@ -186,3 +188,5 @@ contributors:
github: osterman
- name: Andriy Knysh
github: aknysh
- name: RB
github: nitrocode
1 change: 0 additions & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.1.15 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |

## Providers

Expand Down
8 changes: 2 additions & 6 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
2 changes: 1 addition & 1 deletion iam.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 13 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = (
Expand All @@ -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)
}
24 changes: 12 additions & 12 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down
6 changes: 1 addition & 5 deletions versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@ terraform {
source = "hashicorp/aws"
version = ">= 3.1.15"
}
null = {
source = "hashicorp/null"
version = ">= 2.0"
}
}
}
}

0 comments on commit ac5f706

Please sign in to comment.