Skip to content

Commit 173b493

Browse files
authored
add managed secrets option (#87)
1 parent aba9422 commit 173b493

File tree

9 files changed

+62
-23
lines changed

9 files changed

+62
-23
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ module "redshift" {
179179
| Name | Version |
180180
|------|---------|
181181
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
182-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
182+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24 |
183183
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
184184

185185
## Providers
186186

187187
| Name | Version |
188188
|------|---------|
189-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
189+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24 |
190190
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
191191

192192
## Modules
@@ -255,8 +255,10 @@ No modules.
255255
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | The ARN for the KMS encryption key. When specifying `kms_key_arn`, `encrypted` needs to be set to `true` | `string` | `null` | no |
256256
| <a name="input_logging"></a> [logging](#input\_logging) | Logging configuration for the cluster | `any` | `{}` | no |
257257
| <a name="input_maintenance_track_name"></a> [maintenance\_track\_name](#input\_maintenance\_track\_name) | The name of the maintenance track for the restored cluster. When you take a snapshot, the snapshot inherits the MaintenanceTrack value from the cluster. The snapshot might be on a different track than the cluster that was the source for the snapshot. Default value is `current` | `string` | `null` | no |
258+
| <a name="input_manage_master_password"></a> [manage\_master\_password](#input\_manage\_master\_password) | (Optional) Whether to use AWS SecretsManager to manage the cluster admin credentials. Conflicts with master\_password. One of master\_password or manage\_master\_password is required unless snapshot\_identifier is provided. | `bool` | `null` | no |
258259
| <a name="input_manual_snapshot_retention_period"></a> [manual\_snapshot\_retention\_period](#input\_manual\_snapshot\_retention\_period) | The default number of days to retain a manual snapshot. If the value is -1, the snapshot is retained indefinitely. This setting doesn't change the retention period of existing snapshots. Valid values are between `-1` and `3653`. Default value is `-1` | `number` | `null` | no |
259260
| <a name="input_master_password"></a> [master\_password](#input\_master\_password) | Password for the master DB user. (Required unless a `snapshot_identifier` is provided). Must contain at least 8 chars, one uppercase letter, one lowercase letter, and one number | `string` | `null` | no |
261+
| <a name="input_master_password_secret_kms_key_id"></a> [master\_password\_secret\_kms\_key\_id](#input\_master\_password\_secret\_kms\_key\_id) | (Optional) ID of the KMS key used to encrypt the cluster admin credentials secret. | `string` | `null` | no |
260262
| <a name="input_master_username"></a> [master\_username](#input\_master\_username) | Username for the master DB user (Required unless a `snapshot_identifier` is provided). Defaults to `awsuser` | `string` | `"awsuser"` | no |
261263
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The node type to be provisioned for the cluster | `string` | `""` | no |
262264
| <a name="input_number_of_nodes"></a> [number\_of\_nodes](#input\_number\_of\_nodes) | Number of nodes in the cluster. Defaults to 1. Note: values greater than 1 will trigger `cluster_type` to switch to `multi-node` | `number` | `1` | no |
@@ -318,6 +320,7 @@ No modules.
318320
| <a name="output_endpoint_access_id"></a> [endpoint\_access\_id](#output\_endpoint\_access\_id) | The Redshift-managed VPC endpoint name |
319321
| <a name="output_endpoint_access_port"></a> [endpoint\_access\_port](#output\_endpoint\_access\_port) | The port number on which the cluster accepts incoming connections |
320322
| <a name="output_endpoint_access_vpc_endpoint"></a> [endpoint\_access\_vpc\_endpoint](#output\_endpoint\_access\_vpc\_endpoint) | The connection endpoint for connecting to an Amazon Redshift cluster through the proxy. See details below |
323+
| <a name="output_master_password_secret_arn"></a> [master\_password\_secret\_arn](#output\_master\_password\_secret\_arn) | ARN of managed master password secret |
321324
| <a name="output_parameter_group_arn"></a> [parameter\_group\_arn](#output\_parameter\_group\_arn) | Amazon Resource Name (ARN) of the parameter group created |
322325
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | The name of the Redshift parameter group created |
323326
| <a name="output_scheduled_action_iam_role_arn"></a> [scheduled\_action\_iam\_role\_arn](#output\_scheduled\_action\_iam\_role\_arn) | Scheduled actions IAM role ARN |

examples/complete/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ Note that this example may create resources which cost money. Run `terraform des
2424
| Name | Version |
2525
|------|---------|
2626
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
27-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24 |
2828

2929
## Providers
3030

3131
| Name | Version |
3232
|------|---------|
33-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
34-
| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 5.0 |
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24 |
34+
| <a name="provider_aws.us_east_1"></a> [aws.us\_east\_1](#provider\_aws.us\_east\_1) | >= 5.24 |
3535

3636
## Modules
3737

@@ -89,6 +89,7 @@ No inputs.
8989
| <a name="output_endpoint_access_id"></a> [endpoint\_access\_id](#output\_endpoint\_access\_id) | The Redshift-managed VPC endpoint name |
9090
| <a name="output_endpoint_access_port"></a> [endpoint\_access\_port](#output\_endpoint\_access\_port) | The port number on which the cluster accepts incoming connections |
9191
| <a name="output_endpoint_access_vpc_endpoint"></a> [endpoint\_access\_vpc\_endpoint](#output\_endpoint\_access\_vpc\_endpoint) | The connection endpoint for connecting to an Amazon Redshift cluster through the proxy. See details below |
92+
| <a name="output_master_password_secret_arn"></a> [master\_password\_secret\_arn](#output\_master\_password\_secret\_arn) | ARN of managed master password secret |
9293
| <a name="output_parameter_group_arn"></a> [parameter\_group\_arn](#output\_parameter\_group\_arn) | Amazon Resource Name (ARN) of the parameter group created |
9394
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | The name of the Redshift parameter group created |
9495
| <a name="output_scheduled_action_iam_role_arn"></a> [scheduled\_action\_iam\_role\_arn](#output\_scheduled\_action\_iam\_role\_arn) | Scheduled actions IAM role ARN |

examples/complete/main.tf

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ module "redshift" {
3737
node_type = "ra3.xlplus"
3838
number_of_nodes = 3
3939

40-
database_name = "mydb"
41-
master_username = "mydbuser"
42-
create_random_password = false
43-
master_password = "MySecretPassw0rd1!" # Do better!
40+
database_name = "mydb"
41+
master_username = "mydbuser"
42+
# Either provide a good master password
43+
# create_random_password = false
44+
# master_password = "MySecretPassw0rd1!" # Do better!
45+
# Or make Redshift manage it in secrets manager
46+
manage_master_password = true
4447

4548
encrypted = true
4649
kms_key_arn = aws_kms_key.redshift.arn

examples/complete/outputs.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,11 @@ output "authentication_profiles" {
209209
description = "Map of authentication profiles created and their associated attributes"
210210
value = module.redshift.authentication_profiles
211211
}
212+
213+
################################################################################
214+
# Managed Master Password Secret
215+
################################################################################
216+
output "master_password_secret_arn" {
217+
description = "ARN of managed master password secret"
218+
value = module.redshift.master_password_secret_arn
219+
}

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.24"
88
}
99
}
1010
}

main.tf

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,20 @@ resource "aws_redshift_cluster" "this" {
5858
}
5959
}
6060

61-
maintenance_track_name = var.maintenance_track_name
62-
manual_snapshot_retention_period = var.manual_snapshot_retention_period
63-
master_password = var.snapshot_identifier != null ? null : local.master_password
64-
master_username = var.master_username
65-
node_type = var.node_type
66-
number_of_nodes = var.number_of_nodes
67-
owner_account = var.owner_account
68-
port = var.port
69-
preferred_maintenance_window = var.preferred_maintenance_window
70-
publicly_accessible = var.publicly_accessible
71-
skip_final_snapshot = var.skip_final_snapshot
72-
snapshot_cluster_identifier = var.snapshot_cluster_identifier
61+
maintenance_track_name = var.maintenance_track_name
62+
manual_snapshot_retention_period = var.manual_snapshot_retention_period
63+
manage_master_password = try(var.manage_master_password, false) ? var.manage_master_password : null
64+
master_password = var.snapshot_identifier == null && !try(var.manage_master_password, false) ? local.master_password : null
65+
master_password_secret_kms_key_id = try(var.master_password_secret_kms_key_id, null)
66+
master_username = var.master_username
67+
node_type = var.node_type
68+
number_of_nodes = var.number_of_nodes
69+
owner_account = var.owner_account
70+
port = var.port
71+
preferred_maintenance_window = var.preferred_maintenance_window
72+
publicly_accessible = var.publicly_accessible
73+
skip_final_snapshot = var.skip_final_snapshot
74+
snapshot_cluster_identifier = var.snapshot_cluster_identifier
7375

7476
dynamic "snapshot_copy" {
7577
for_each = length(var.snapshot_copy) > 0 ? [var.snapshot_copy] : []

outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,12 @@ output "authentication_profiles" {
213213
description = "Map of authentication profiles created and their associated attributes"
214214
value = aws_redshift_authentication_profile.this
215215
}
216+
217+
################################################################################
218+
# Managed Master Password Secret
219+
################################################################################
220+
221+
output "master_password_secret_arn" {
222+
description = "ARN of managed master password secret"
223+
value = try(aws_redshift_cluster.this[0].master_password_secret_arn, null)
224+
}

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ variable "manual_snapshot_retention_period" {
123123
default = null
124124
}
125125

126+
127+
variable "manage_master_password" {
128+
description = "(Optional) Whether to use AWS SecretsManager to manage the cluster admin credentials. Conflicts with master_password. One of master_password or manage_master_password is required unless snapshot_identifier is provided."
129+
type = bool
130+
default = null
131+
}
132+
133+
variable "master_password_secret_kms_key_id" {
134+
description = "(Optional) ID of the KMS key used to encrypt the cluster admin credentials secret."
135+
type = string
136+
default = null
137+
}
138+
126139
variable "master_password" {
127140
description = "Password for the master DB user. (Required unless a `snapshot_identifier` is provided). Must contain at least 8 chars, one uppercase letter, one lowercase letter, and one number"
128141
type = string

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.24"
88
}
99
random = {
1010
source = "hashicorp/random"

0 commit comments

Comments
 (0)