Skip to content

Commit ac5f706

Browse files
Add count logic (#7)
* Add count logic * Auto Format Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>
1 parent 1c56cf6 commit ac5f706

File tree

9 files changed

+50
-42
lines changed

9 files changed

+50
-42
lines changed

.github/renovate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
":preserveSemverRanges"
55
],
66
"labels": ["auto-update"],
7+
"dependencyDashboardAutoclose": true,
78
"enabledManagers": ["terraform"],
89
"terraform": {
910
"ignorePaths": ["**/context.tf", "examples/**"]
1011
}
1112
}
12-

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ For automated tests of the complete example using [bats](https://github.com/bats
102102
```hcl
103103
module "vpc" {
104104
source = "cloudposse/vpc/aws"
105-
version = "0.21.1"
105+
# Cloud Posse recommends pinning every module to a specific version
106+
# version = "x.x.x"
106107
107108
cidr_block = "172.16.0.0/16"
108109
@@ -111,7 +112,8 @@ module "vpc" {
111112
112113
module "subnets" {
113114
source = "cloudposse/dynamic-subnets/aws"
114-
version = "0.38.0"
115+
# Cloud Posse recommends pinning every module to a specific version
116+
# version = "x.x.x"
115117
116118
availability_zones = var.availability_zones
117119
vpc_id = module.vpc.vpc_id
@@ -124,7 +126,7 @@ module "subnets" {
124126
}
125127
126128
resource "random_password" "admin_password" {
127-
count = var.database_password == "" || var.database_password == null ? 1 : 0
129+
count = var.database_password == "" || var.database_password == null ? 1 : 0
128130
length = 33
129131
special = false
130132
override_special = "!#$%^&*()<>-_"
@@ -150,7 +152,8 @@ locals {
150152
151153
module "rds_instance" {
152154
source = "cloudposse/rds/aws"
153-
version = "0.34.0"
155+
# Cloud Posse recommends pinning every module to a specific version
156+
# version = "x.x.x"
154157
155158
database_name = var.database_name
156159
database_user = var.database_user
@@ -207,7 +210,6 @@ module "rds_proxy" {
207210
208211
context = module.this.context
209212
}
210-
211213
```
212214

213215

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

243244
## Providers
244245

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

478479
<!-- markdownlint-disable -->
479-
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] |
480-
|---|---|
480+
| [![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] |
481+
|---|---|---|
481482
<!-- markdownlint-restore -->
482483

483484
[osterman_homepage]: https://github.com/osterman
484485
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
485486
[aknysh_homepage]: https://github.com/aknysh
486487
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
488+
[nitrocode_homepage]: https://github.com/nitrocode
489+
[nitrocode_avatar]: https://img.cloudposse.com/150x150/https://github.com/nitrocode.png
487490

488491
[![README Footer][readme_footer_img]][readme_footer_link]
489492
[![Beacon][beacon]][website]

README.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ usage: |2-
6666
```hcl
6767
module "vpc" {
6868
source = "cloudposse/vpc/aws"
69-
version = "0.21.1"
69+
# Cloud Posse recommends pinning every module to a specific version
70+
# version = "x.x.x"
7071
7172
cidr_block = "172.16.0.0/16"
7273
@@ -75,7 +76,8 @@ usage: |2-
7576
7677
module "subnets" {
7778
source = "cloudposse/dynamic-subnets/aws"
78-
version = "0.38.0"
79+
# Cloud Posse recommends pinning every module to a specific version
80+
# version = "x.x.x"
7981
8082
availability_zones = var.availability_zones
8183
vpc_id = module.vpc.vpc_id
@@ -88,7 +90,7 @@ usage: |2-
8890
}
8991
9092
resource "random_password" "admin_password" {
91-
count = var.database_password == "" || var.database_password == null ? 1 : 0
93+
count = var.database_password == "" || var.database_password == null ? 1 : 0
9294
length = 33
9395
special = false
9496
override_special = "!#$%^&*()<>-_"
@@ -114,7 +116,8 @@ usage: |2-
114116
115117
module "rds_instance" {
116118
source = "cloudposse/rds/aws"
117-
version = "0.34.0"
119+
# Cloud Posse recommends pinning every module to a specific version
120+
# version = "x.x.x"
118121
119122
database_name = var.database_name
120123
database_user = var.database_user
@@ -171,7 +174,6 @@ usage: |2-
171174
172175
context = module.this.context
173176
}
174-
175177
```
176178
177179
examples: |-
@@ -186,3 +188,5 @@ contributors:
186188
github: osterman
187189
- name: Andriy Knysh
188190
github: aknysh
191+
- name: RB
192+
github: nitrocode

docs/terraform.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
77
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.1.15 |
8-
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
98

109
## Providers
1110

examples/complete/versions.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 2.0"
8-
}
9-
null = {
10-
source = "hashicorp/null"
11-
version = ">= 2.0"
7+
version = ">= 3.1.15"
128
}
139
}
14-
}
10+
}

iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy.html
22

33
locals {
4-
iam_role_enabled = var.existing_iam_role_arn == null || var.existing_iam_role_arn == "" ? true : false
4+
iam_role_enabled = local.enabled && (var.existing_iam_role_arn == null || var.existing_iam_role_arn == "")
55
asm_secret_arns = compact([for auth in var.auth : lookup(auth, "secret_arn", "")])
66
kms_key_arn = join("", data.aws_kms_key.this.*.arn)
77
iam_role_arn = local.iam_role_enabled ? join("", aws_iam_role.this.*.arn) : var.existing_iam_role_arn

main.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
locals {
2+
enabled = module.this.enabled
3+
}
4+
15
resource "aws_db_proxy" "this" {
6+
count = local.enabled ? 1 : 0
7+
28
name = module.this.id
39
debug_logging = var.debug_logging
410
engine_family = var.engine_family
@@ -23,7 +29,9 @@ resource "aws_db_proxy" "this" {
2329
}
2430

2531
resource "aws_db_proxy_default_target_group" "this" {
26-
db_proxy_name = aws_db_proxy.this.name
32+
count = local.enabled ? 1 : 0
33+
34+
db_proxy_name = join("", aws_db_proxy.this[*].name)
2735

2836
dynamic "connection_pool_config" {
2937
for_each = (
@@ -42,8 +50,10 @@ resource "aws_db_proxy_default_target_group" "this" {
4250
}
4351

4452
resource "aws_db_proxy_target" "this" {
53+
count = local.enabled ? 1 : 0
54+
4555
db_instance_identifier = var.db_instance_identifier
4656
db_cluster_identifier = var.db_cluster_identifier
47-
db_proxy_name = aws_db_proxy.this.name
48-
target_group_name = aws_db_proxy_default_target_group.this.name
57+
db_proxy_name = join("", aws_db_proxy.this[*].name)
58+
target_group_name = join("", aws_db_proxy_default_target_group.this[*].name)
4959
}

outputs.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
output "proxy_id" {
2-
value = aws_db_proxy.this.id
2+
value = join("", aws_db_proxy.this[*].id)
33
description = "Proxy ID"
44
}
55

66
output "proxy_arn" {
7-
value = aws_db_proxy.this.arn
7+
value = join("", aws_db_proxy.this[*].arn)
88
description = "Proxy ARN"
99
}
1010

1111
output "proxy_endpoint" {
12-
value = aws_db_proxy.this.endpoint
12+
value = join("", aws_db_proxy.this[*].endpoint)
1313
description = "Proxy endpoint"
1414
}
1515

1616
output "proxy_target_endpoint" {
17-
value = aws_db_proxy_target.this.endpoint
17+
value = join("", aws_db_proxy_target.this[*].endpoint)
1818
description = "Hostname for the target RDS DB Instance. Only returned for `RDS_INSTANCE` type"
1919
}
2020

2121
output "proxy_target_id" {
22-
value = aws_db_proxy_target.this.id
22+
value = join("", aws_db_proxy_target.this[*].id)
2323
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 (`/`)"
2424
}
2525

2626
output "proxy_target_port" {
27-
value = aws_db_proxy_target.this.port
27+
value = join("", aws_db_proxy_target.this[*].port)
2828
description = "Port for the target RDS DB instance or Aurora DB cluster"
2929
}
3030

3131
output "proxy_target_rds_resource_id" {
32-
value = aws_db_proxy_target.this.rds_resource_id
32+
value = join("", aws_db_proxy_target.this[*].rds_resource_id)
3333
description = "Identifier representing the DB instance or DB cluster target"
3434
}
3535

3636
output "proxy_target_target_arn" {
37-
value = aws_db_proxy_target.this.target_arn
37+
value = join("", aws_db_proxy_target.this[*].target_arn)
3838
description = "Amazon Resource Name (ARN) for the DB instance or DB cluster"
3939
}
4040

4141
output "proxy_target_tracked_cluster_id" {
42-
value = aws_db_proxy_target.this.tracked_cluster_id
42+
value = join("", aws_db_proxy_target.this[*].tracked_cluster_id)
4343
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"
4444
}
4545

4646
output "proxy_target_type" {
47-
value = aws_db_proxy_target.this.type
47+
value = join("", aws_db_proxy_target.this[*].type)
4848
description = "Type of target. e.g. `RDS_INSTANCE` or `TRACKED_CLUSTER`"
4949
}
5050

5151
output "proxy_default_target_group_arn" {
52-
value = aws_db_proxy_default_target_group.this.arn
52+
value = join("", aws_db_proxy_default_target_group.this[*].arn)
5353
description = "The Amazon Resource Name (ARN) representing the default target group"
5454
}
5555

5656
output "proxy_default_target_group_name" {
57-
value = aws_db_proxy_default_target_group.this.name
57+
value = join("", aws_db_proxy_default_target_group.this[*].name)
5858
description = "The name of the default target group"
5959
}
6060

versions.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ terraform {
66
source = "hashicorp/aws"
77
version = ">= 3.1.15"
88
}
9-
null = {
10-
source = "hashicorp/null"
11-
version = ">= 2.0"
12-
}
139
}
14-
}
10+
}

0 commit comments

Comments
 (0)