Skip to content
This repository was archived by the owner on Jan 31, 2021. It is now read-only.

Commit 3de1a7e

Browse files
authored
Added chamber parameters mapping (#7)
1 parent ed391b1 commit 3de1a7e

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Available targets:
101101
| chamber_service | `chamber` service name. See [chamber usage](https://github.com/segmentio/chamber#usage) for more details | string | `` | no |
102102
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
103103
| documentdb_apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | string | `true` | no |
104+
| documentdb_chamber_parameters_mapping | Allow to specify keys names for chamber to store values | map | `<map>` | no |
104105
| documentdb_cluster_enabled | Set to false to prevent the module from creating DocumentDB cluster | string | `true` | no |
105106
| documentdb_cluster_family | The family of the DocumentDB cluster parameter group. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-parameter-group-create.html | string | `docdb3.6` | no |
106107
| documentdb_cluster_parameters | List of DB parameters to apply | list | `<list>` | no |

docs/terraform.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| chamber_service | `chamber` service name. See [chamber usage](https://github.com/segmentio/chamber#usage) for more details | string | `` | no |
1111
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
1212
| documentdb_apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | string | `true` | no |
13+
| documentdb_chamber_parameters_mapping | Allow to specify keys names for chamber to store values | map | `<map>` | no |
1314
| documentdb_cluster_enabled | Set to false to prevent the module from creating DocumentDB cluster | string | `true` | no |
1415
| documentdb_cluster_family | The family of the DocumentDB cluster parameter group. For more details, see https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-parameter-group-create.html | string | `docdb3.6` | no |
1516
| documentdb_cluster_parameters | List of DB parameters to apply | list | `<list>` | no |

documentdb.tf

+21-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ variable "documentdb_port" {
2121
description = "DocumentDB port"
2222
}
2323

24+
variable "documentdb_chamber_parameters_mapping" {
25+
type = "map"
26+
default = {}
27+
description = "Allow to specify keys names for chamber to store values"
28+
}
29+
2430
variable "documentdb_master_username" {
2531
type = "string"
2632
default = ""
@@ -101,6 +107,7 @@ locals {
101107
documentdb_cluster_enabled = "${var.enabled == "true" && var.documentdb_cluster_enabled == "true" ? "true" : "false"}"
102108
documentdb_master_username = "${length(var.documentdb_master_username) > 0 ? var.documentdb_master_username : join("", random_string.documentdb_master_username.*.result)}"
103109
documentdb_master_password = "${length(var.documentdb_master_password) > 0 ? var.documentdb_master_password : join("", random_string.documentdb_master_password.*.result)}"
110+
documentdb_connection_uri = "${format("mongodb://%s:%s@%s:%s", local.documentdb_master_username, local.documentdb_master_password, module.documentdb_cluster.endpoint, var.documentdb_port)}"
104111
}
105112

106113
module "documentdb_cluster" {
@@ -150,7 +157,7 @@ resource "random_string" "documentdb_master_password" {
150157

151158
resource "aws_ssm_parameter" "documentdb_master_username" {
152159
count = "${local.documentdb_cluster_enabled == "true" ? 1 : 0}"
153-
name = "${format(var.chamber_format, local.chamber_service, "documentdb_master_username")}"
160+
name = "${format(var.chamber_format, local.chamber_service, lookup(var.documentdb_chamber_parameters_mapping, "documentdb_master_username", "documentdb_master_username"))}"
154161
value = "${local.documentdb_master_username}"
155162
description = "DocumentDB Username for the master DB user"
156163
type = "String"
@@ -159,7 +166,7 @@ resource "aws_ssm_parameter" "documentdb_master_username" {
159166

160167
resource "aws_ssm_parameter" "documentdb_master_password" {
161168
count = "${local.documentdb_cluster_enabled == "true" ? 1 : 0}"
162-
name = "${format(var.chamber_format, local.chamber_service, "documentdb_master_password")}"
169+
name = "${format(var.chamber_format, local.chamber_service, lookup(var.documentdb_chamber_parameters_mapping, "documentdb_master_password", "documentdb_master_password"))}"
163170
value = "${local.documentdb_master_password}"
164171
description = "DocumentDB Password for the master DB user"
165172
type = "SecureString"
@@ -169,7 +176,7 @@ resource "aws_ssm_parameter" "documentdb_master_password" {
169176

170177
resource "aws_ssm_parameter" "documentdb_master_hostname" {
171178
count = "${local.documentdb_cluster_enabled == "true" ? 1 : 0}"
172-
name = "${format(var.chamber_format, local.chamber_service, "documentdb_master_hostname")}"
179+
name = "${format(var.chamber_format, local.chamber_service, lookup(var.documentdb_chamber_parameters_mapping, "documentdb_master_hostname", "documentdb_master_hostname"))}"
173180
value = "${module.documentdb_cluster.master_host}"
174181
description = "DocumentDB DB master hostname"
175182
type = "String"
@@ -178,7 +185,7 @@ resource "aws_ssm_parameter" "documentdb_master_hostname" {
178185

179186
resource "aws_ssm_parameter" "documentdb_replicas_hostname" {
180187
count = "${local.documentdb_cluster_enabled == "true" ? 1 : 0}"
181-
name = "${format(var.chamber_format, local.chamber_service, "documentdb_replicas_hostname")}"
188+
name = "${format(var.chamber_format, local.chamber_service, lookup(var.documentdb_chamber_parameters_mapping, "documentdb_replicas_hostname", "documentdb_replicas_hostname"))}"
182189
value = "${module.documentdb_cluster.replicas_host}"
183190
description = "DocumentDB DB replicas hostname"
184191
type = "String"
@@ -187,13 +194,22 @@ resource "aws_ssm_parameter" "documentdb_replicas_hostname" {
187194

188195
resource "aws_ssm_parameter" "documentdb_cluster_name" {
189196
count = "${local.documentdb_cluster_enabled == "true" ? 1 : 0}"
190-
name = "${format(var.chamber_format, local.chamber_service, "documentdb_cluster_name")}"
197+
name = "${format(var.chamber_format, local.chamber_service, lookup(var.documentdb_chamber_parameters_mapping, "documentdb_cluster_name", "documentdb_cluster_name"))}"
191198
value = "${module.documentdb_cluster.cluster_name}"
192199
description = "DocumentDB Cluster Identifier"
193200
type = "String"
194201
overwrite = "${var.overwrite_ssm_parameter}"
195202
}
196203

204+
resource "aws_ssm_parameter" "documentdb_connection_uri" {
205+
count = "${local.documentdb_cluster_enabled == "true" ? 1 : 0}"
206+
name = "${format(var.chamber_format, local.chamber_service, lookup(var.documentdb_chamber_parameters_mapping, "documentdb_connection_uri", "documentdb_connection_uri"))}"
207+
value = "${local.documentdb_connection_uri}"
208+
description = "DocumentDB connection URI"
209+
type = "String"
210+
overwrite = "${var.overwrite_ssm_parameter}"
211+
}
212+
197213
output "documentdb_master_username" {
198214
value = "${module.documentdb_cluster.master_username}"
199215
description = "DocumentDB Username for the master DB user"

0 commit comments

Comments
 (0)