Skip to content

Commit cc39e9d

Browse files
ElementTechOrest Kapkoamitai-devopsAlKapkonebryantbiggs
authored
feat!: Increase Terraform and AWS provider minimum supported versions; update auth configuration schema (#17)
Co-authored-by: Orest Kapko <orest.kapko@welltech.com> Co-authored-by: Amitai Getzler <amitai.getzler@explorium.ai> Co-authored-by: Orest Kapko <kapko2311@gmail.com> Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com> Co-authored-by: Anton Babenko <anton@antonbabenko.com>
1 parent 5d1c5e6 commit cc39e9d

File tree

31 files changed

+626
-750
lines changed

31 files changed

+626
-750
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.76.0
3+
rev: v1.80.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -23,7 +23,7 @@ repos:
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.3.0
26+
rev: v4.4.0
2727
hooks:
2828
- id: check-merge-conflict
2929
- id: end-of-file-fixer

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module "rds_proxy" {
1515
vpc_subnet_ids = ["subnet-30ef7b3c", "subnet-1ecda77b", "subnet-ca09ddbc"]
1616
vpc_security_group_ids = ["sg-f1d03a88"]
1717
18-
db_proxy_endpoints = {
18+
endpoints = {
1919
read_write = {
2020
name = "read-write-endpoint"
2121
vpc_subnet_ids = ["subnet-30ef7b3c", "subnet-1ecda77b", "subnet-ca09ddbc"]
@@ -29,18 +29,17 @@ module "rds_proxy" {
2929
}
3030
}
3131
32-
secrets = {
32+
auth = {
3333
"superuser" = {
34-
description = "Aurora PostgreSQL superuser password"
35-
arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:superuser-6gsjLD"
36-
kms_key_id = "6ca29066-552a-46c5-a7d7-7bf9a15fc255"
34+
description = "Aurora PostgreSQL superuser password"
35+
secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:superuser-6gsjLD"
3736
}
3837
}
3938
4039
# Target Aurora cluster
4140
engine_family = "POSTGRESQL"
4241
target_db_cluster = true
43-
db_cluster_identifier = "myendpoint"
42+
db_cluster_identifier = "my-endpoint"
4443
4544
tags = {
4645
Terraform = "true"
@@ -63,14 +62,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
6362

6463
| Name | Version |
6564
|------|---------|
66-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
67-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.38 |
65+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
66+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
6867

6968
## Providers
7069

7170
| Name | Version |
7271
|------|---------|
73-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.38 |
72+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
7473

7574
## Modules
7675

@@ -90,23 +89,23 @@ No modules.
9089
| [aws_iam_role_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource |
9190
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
9291
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
92+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
9393
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
9494

9595
## Inputs
9696

9797
| Name | Description | Type | Default | Required |
9898
|------|-------------|------|---------|:--------:|
99-
| <a name="input_auth_scheme"></a> [auth\_scheme](#input\_auth\_scheme) | The type of authentication that the proxy uses for connections from the proxy to the underlying database. One of `SECRETS` | `string` | `"SECRETS"` | no |
99+
| <a name="input_auth"></a> [auth](#input\_auth) | Configuration block(s) with authorization mechanisms to connect to the associated instances or clusters | `any` | `{}` | no |
100100
| <a name="input_connection_borrow_timeout"></a> [connection\_borrow\_timeout](#input\_connection\_borrow\_timeout) | The number of seconds for a proxy to wait for a connection to become available in the connection pool | `number` | `null` | no |
101+
| <a name="input_create"></a> [create](#input\_create) | Whether cluster should be created (affects nearly all resources) | `bool` | `true` | no |
101102
| <a name="input_create_iam_policy"></a> [create\_iam\_policy](#input\_create\_iam\_policy) | Determines whether an IAM policy is created | `bool` | `true` | no |
102103
| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Determines whether an IAM role is created | `bool` | `true` | no |
103-
| <a name="input_create_proxy"></a> [create\_proxy](#input\_create\_proxy) | Determines whether a proxy and its resources will be created | `bool` | `true` | no |
104104
| <a name="input_db_cluster_identifier"></a> [db\_cluster\_identifier](#input\_db\_cluster\_identifier) | DB cluster identifier | `string` | `""` | no |
105105
| <a name="input_db_instance_identifier"></a> [db\_instance\_identifier](#input\_db\_instance\_identifier) | DB instance identifier | `string` | `""` | no |
106-
| <a name="input_db_proxy_endpoints"></a> [db\_proxy\_endpoints](#input\_db\_proxy\_endpoints) | Map of DB proxy endpoints to create and their attributes (see `aws_db_proxy_endpoint`) | `any` | `{}` | no |
107106
| <a name="input_debug_logging"></a> [debug\_logging](#input\_debug\_logging) | Whether the proxy includes detailed information about SQL statements in its logs | `bool` | `false` | no |
107+
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | Map of DB proxy endpoints to create and their attributes (see `aws_db_proxy_endpoint`) | `any` | `{}` | no |
108108
| <a name="input_engine_family"></a> [engine\_family](#input\_engine\_family) | The kind of database engine that the proxy will connect to. Valid values are `MYSQL` or `POSTGRESQL` | `string` | `""` | no |
109-
| <a name="input_iam_auth"></a> [iam\_auth](#input\_iam\_auth) | Whether to require or disallow AWS Identity and Access Management (IAM) authentication for connections to the proxy. One of `DISABLED`, `REQUIRED` | `string` | `"REQUIRED"` | no |
110109
| <a name="input_iam_policy_name"></a> [iam\_policy\_name](#input\_iam\_policy\_name) | The name of the role policy. If omitted, Terraform will assign a random, unique name | `string` | `""` | no |
111110
| <a name="input_iam_role_description"></a> [iam\_role\_description](#input\_iam\_role\_description) | The description of the role | `string` | `""` | no |
112111
| <a name="input_iam_role_force_detach_policies"></a> [iam\_role\_force\_detach\_policies](#input\_iam\_role\_force\_detach\_policies) | Specifies to force detaching any policies the role has before destroying it | `bool` | `true` | no |
@@ -117,6 +116,7 @@ No modules.
117116
| <a name="input_iam_role_tags"></a> [iam\_role\_tags](#input\_iam\_role\_tags) | A map of tags to apply to the IAM role | `map(string)` | `{}` | no |
118117
| <a name="input_idle_client_timeout"></a> [idle\_client\_timeout](#input\_idle\_client\_timeout) | The number of seconds that a connection to the proxy can be inactive before the proxy disconnects it | `number` | `1800` | no |
119118
| <a name="input_init_query"></a> [init\_query](#input\_init\_query) | One or more SQL statements for the proxy to run when opening each new database connection | `string` | `""` | no |
119+
| <a name="input_kms_key_arns"></a> [kms\_key\_arns](#input\_kms\_key\_arns) | List of KMS Key ARNs to allow access to decrypt SecretsManager secrets | `list(string)` | `[]` | no |
120120
| <a name="input_log_group_kms_key_id"></a> [log\_group\_kms\_key\_id](#input\_log\_group\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data | `string` | `null` | no |
121121
| <a name="input_log_group_retention_in_days"></a> [log\_group\_retention\_in\_days](#input\_log\_group\_retention\_in\_days) | Specifies the number of days you want to retain log events in the log group | `number` | `30` | no |
122122
| <a name="input_log_group_tags"></a> [log\_group\_tags](#input\_log\_group\_tags) | A map of tags to apply to the CloudWatch log group | `map(string)` | `{}` | no |
@@ -127,11 +127,10 @@ No modules.
127127
| <a name="input_proxy_tags"></a> [proxy\_tags](#input\_proxy\_tags) | A map of tags to apply to the RDS Proxy | `map(string)` | `{}` | no |
128128
| <a name="input_require_tls"></a> [require\_tls](#input\_require\_tls) | A Boolean parameter that specifies whether Transport Layer Security (TLS) encryption is required for connections to the proxy | `bool` | `true` | no |
129129
| <a name="input_role_arn"></a> [role\_arn](#input\_role\_arn) | The Amazon Resource Name (ARN) of the IAM role that the proxy uses to access secrets in AWS Secrets Manager | `string` | `""` | no |
130-
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Map of secerets to be used by RDS Proxy for authentication to the database | `map(object({ arn = string, description = string, kms_key_id = string }))` | `{}` | no |
131130
| <a name="input_session_pinning_filters"></a> [session\_pinning\_filters](#input\_session\_pinning\_filters) | Each item in the list represents a class of SQL operations that normally cause all later statements in a session using a proxy to be pinned to the same underlying database connection | `list(string)` | `[]` | no |
132-
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to use on all resources | `map(string)` | `{}` | no |
133-
| <a name="input_target_db_cluster"></a> [target\_db\_cluster](#input\_target\_db\_cluster) | Determines whether DB cluster is targetted by proxy | `bool` | `false` | no |
134-
| <a name="input_target_db_instance"></a> [target\_db\_instance](#input\_target\_db\_instance) | Determines whether DB instance is targetted by proxy | `bool` | `false` | no |
131+
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
132+
| <a name="input_target_db_cluster"></a> [target\_db\_cluster](#input\_target\_db\_cluster) | Determines whether DB cluster is targeted by proxy | `bool` | `false` | no |
133+
| <a name="input_target_db_instance"></a> [target\_db\_instance](#input\_target\_db\_instance) | Determines whether DB instance is targeted by proxy | `bool` | `false` | no |
135134
| <a name="input_use_policy_name_prefix"></a> [use\_policy\_name\_prefix](#input\_use\_policy\_name\_prefix) | Whether to use unique name beginning with the specified `iam_policy_name` | `bool` | `false` | no |
136135
| <a name="input_use_role_name_prefix"></a> [use\_role\_name\_prefix](#input\_use\_role\_name\_prefix) | Whether to use unique name beginning with the specified `iam_role_name` | `bool` | `false` | no |
137136
| <a name="input_vpc_security_group_ids"></a> [vpc\_security\_group\_ids](#input\_vpc\_security\_group\_ids) | One or more VPC security group IDs to associate with the new proxy | `list(string)` | `[]` | no |

UPGRADE-3.0.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Upgrade from v2.x to v3.x
2+
3+
If you have any questions regarding this upgrade process, please consult the `examples` directory.
4+
If you find a bug, please open an issue with supporting configuration to reproduce.
5+
6+
## List of backwards incompatible changes
7+
8+
- Minimum supported Terraform version is now 1.0
9+
- Minimum supported AWS provider version is now 5.0
10+
- The manner in which authentication is configured has changed - previously auth settings were provided under `secrets` in conjunction with `auth_scheme` and `iam_auth` variables. Now, auth settings are provided under the `auth` variable for multiple auth entries.
11+
12+
### Variable and output changes
13+
14+
1. Removed variables:
15+
16+
- `auth_scheme` is now set under the `auth` variable for a given auth entry
17+
- `iam_auth` is now set under the `auth` variable for a given auth entry
18+
19+
2. Renamed variables:
20+
21+
- `create_proxy` -> `create`
22+
- `secrets` -> `auth`
23+
- `db_proxy_endpoints` -> `endpoints`
24+
25+
3. Added variables:
26+
27+
- `kms_key_arns` - list of KMS key ARNs to use allowing permission to decrypt SecretsManager secrets
28+
29+
4. Removed outputs:
30+
31+
- None
32+
33+
5. Renamed outputs:
34+
35+
- None
36+
37+
6. Added outputs:
38+
39+
- None
40+
41+
## Diff of Before (v2.x) vs After (v3.x)
42+
43+
```diff
44+
module "rds_proxy" {
45+
source = "terraform-aws-modules/rds-proxy/aws"
46+
- version = "~> 2.0"
47+
+ version = "~> 3.0"
48+
49+
# Only the affected attributes are shown
50+
- create_proxy = true
51+
+ create = true
52+
53+
- db_proxy_endpoints = {
54+
- ...
55+
- }
56+
+ endpoints = {
57+
+ ...
58+
+ }
59+
60+
- secrets = {
61+
- "superuser" = {
62+
- description = "Aurora PostgreSQL superuser password"
63+
- arn = "arn:aws:secretsmanager:eu-west-1:123456789012:secret:superuser-6gsjLD"
64+
- kms_key_id = "6ca29066-552a-46c5-a7d7-7bf9a15fc255"
65+
- }
66+
- }
67+
+ auth = {
68+
+ "superuser" = {
69+
+ description = "Aurora PostgreSQL superuser password"
70+
+ secret_arn = "arn:aws:secretsmanager:us-east-1:123456789012:secret:superuser-6gsjLD"
71+
+ }
72+
+ }
73+
+ kms_key_arns = ["arn:aws:kms:eu-west-1:123456789012:key/6ca29066-552a-46c5-a7d7-7bf9a15fc255"]
74+
}
75+
```
76+
77+
### State Changes
78+
79+
- None

examples/mysql_iam_cluster/README.md renamed to examples/mysql-iam-cluster/README.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,29 @@ An EC2 instance configuration has been provided for use in validating the exampl
3030

3131
| Name | Version |
3232
|------|---------|
33-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
34-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.38 |
35-
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
33+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
34+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
3635

3736
## Providers
3837

3938
| Name | Version |
4039
|------|---------|
41-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.38 |
42-
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
40+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
4341

4442
## Modules
4543

4644
| Name | Source | Version |
4745
|------|--------|---------|
48-
| <a name="module_rds"></a> [rds](#module\_rds) | terraform-aws-modules/rds-aurora/aws | ~> 6.0 |
46+
| <a name="module_rds"></a> [rds](#module\_rds) | terraform-aws-modules/rds-aurora/aws | ~> 8.0 |
4947
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | n/a |
50-
| <a name="module_rds_proxy_sg"></a> [rds\_proxy\_sg](#module\_rds\_proxy\_sg) | terraform-aws-modules/security-group/aws | ~> 4.0 |
51-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
48+
| <a name="module_rds_proxy_sg"></a> [rds\_proxy\_sg](#module\_rds\_proxy\_sg) | terraform-aws-modules/security-group/aws | ~> 5.0 |
49+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
5250

5351
## Resources
5452

5553
| Name | Type |
5654
|------|------|
57-
| [aws_db_parameter_group.aurora_db_mysql57_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group) | resource |
58-
| [aws_rds_cluster_parameter_group.aurora_cluster_mysql57_parameter_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/rds_cluster_parameter_group) | resource |
59-
| [aws_secretsmanager_secret.superuser](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
60-
| [aws_secretsmanager_secret_version.superuser](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
61-
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
62-
| [random_pet.users](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
63-
| [aws_kms_alias.secretsmanager](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_alias) | data source |
55+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
6456

6557
## Inputs
6658

examples/mysql-iam-cluster/main.tf

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
data "aws_availability_zones" "available" {}
6+
7+
locals {
8+
name = "ex-${basename(path.cwd)}"
9+
region = "eu-west-1"
10+
11+
vpc_cidr = "10.0.0.0/16"
12+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
13+
14+
tags = {
15+
Example = local.name
16+
GithubRepo = "terraform-aws-rds-proxy"
17+
GithubOrg = "terraform-aws-modules"
18+
}
19+
}
20+
21+
################################################################################
22+
# RDS Proxy
23+
################################################################################
24+
25+
module "rds_proxy" {
26+
source = "../../"
27+
28+
name = local.name
29+
iam_role_name = local.name
30+
vpc_subnet_ids = module.vpc.private_subnets
31+
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
32+
33+
endpoints = {
34+
read_write = {
35+
name = "read-write-endpoint"
36+
vpc_subnet_ids = module.vpc.private_subnets
37+
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
38+
tags = local.tags
39+
},
40+
read_only = {
41+
name = "read-only-endpoint"
42+
vpc_subnet_ids = module.vpc.private_subnets
43+
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
44+
target_role = "READ_ONLY"
45+
tags = local.tags
46+
}
47+
}
48+
49+
auth = {
50+
"root" = {
51+
description = "Cluster generated master user password"
52+
secret_arn = module.rds.cluster_master_user_secret[0].secret_arn
53+
}
54+
}
55+
56+
engine_family = "MYSQL"
57+
debug_logging = true
58+
59+
# Target Aurora cluster
60+
target_db_cluster = true
61+
db_cluster_identifier = module.rds.cluster_id
62+
63+
tags = local.tags
64+
}
65+
66+
################################################################################
67+
# Supporting Resources
68+
################################################################################
69+
70+
module "vpc" {
71+
source = "terraform-aws-modules/vpc/aws"
72+
version = "~> 5.0"
73+
74+
name = local.name
75+
cidr = local.vpc_cidr
76+
77+
azs = local.azs
78+
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
79+
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 3)]
80+
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 6)]
81+
82+
tags = local.tags
83+
}
84+
85+
module "rds" {
86+
source = "terraform-aws-modules/rds-aurora/aws"
87+
version = "~> 8.0"
88+
89+
name = local.name
90+
engine = "aurora-mysql"
91+
engine_version = "8.0"
92+
master_username = "root"
93+
94+
# When using RDS Proxy w/ IAM auth - Database must be username/password auth, not IAM
95+
iam_database_authentication_enabled = false
96+
97+
instance_class = "db.r6g.large"
98+
instances = {
99+
1 = {}
100+
2 = {}
101+
}
102+
103+
vpc_id = module.vpc.vpc_id
104+
db_subnet_group_name = module.vpc.database_subnet_group_name
105+
security_group_rules = {
106+
vpc_ingress = {
107+
cidr_blocks = module.vpc.private_subnets_cidr_blocks
108+
}
109+
}
110+
111+
apply_immediately = true
112+
skip_final_snapshot = true
113+
114+
tags = local.tags
115+
}
116+
117+
module "rds_proxy_sg" {
118+
source = "terraform-aws-modules/security-group/aws"
119+
version = "~> 5.0"
120+
121+
name = "${local.name}-proxy"
122+
description = "PostgreSQL RDS Proxy example security group"
123+
vpc_id = module.vpc.vpc_id
124+
125+
revoke_rules_on_delete = true
126+
127+
ingress_with_cidr_blocks = [
128+
{
129+
description = "Private subnet MySQL access"
130+
rule = "mysql-tcp"
131+
cidr_blocks = join(",", module.vpc.private_subnets_cidr_blocks)
132+
}
133+
]
134+
135+
egress_with_cidr_blocks = [
136+
{
137+
description = "Database subnet MySQL access"
138+
rule = "mysql-tcp"
139+
cidr_blocks = join(",", module.vpc.database_subnets_cidr_blocks)
140+
},
141+
]
142+
143+
tags = local.tags
144+
}

examples/mysql_iam_instance/outputs.tf renamed to examples/mysql-iam-cluster/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ output "proxy_target_type" {
6666
value = module.rds_proxy.proxy_target_type
6767
}
6868

69-
# DB proxy endponts
69+
# DB proxy endpoints
7070
output "db_proxy_endpoints" {
7171
description = "Array containing the full resource object and attributes for all DB proxy endpoints created"
7272
value = module.rds_proxy.db_proxy_endpoints
File renamed without changes.

0 commit comments

Comments
 (0)