Skip to content

Commit

Permalink
fix: default to AWS provided option and parameter groups when not cre…
Browse files Browse the repository at this point in the history
…ating nor providing (#308)
bryantbiggs authored Mar 10, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 77c5e44 commit 8b8f9b7
Showing 14 changed files with 339 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -231,12 +231,12 @@ No resources.
| multi\_az | Specifies if the RDS instance is multi-AZ | `bool` | `false` | no |
| name | The DB name to create. If omitted, no database is created initially | `string` | `""` | no |
| option\_group\_description | The description of the option group | `string` | `""` | no |
| option\_group\_name | Name of the option group | `string` | `""` | no |
| option\_group\_name | Name of the option group | `string` | `null` | no |
| option\_group\_timeouts | Define maximum timeout for deletion of `aws_db_option_group` resource | `map(string)` | <pre>{<br> "delete": "15m"<br>}</pre> | no |
| option\_group\_use\_name\_prefix | Determines whether to use `option_group_name` as is or create a unique name beginning with the `option_group_name` as the prefix | `bool` | `true` | no |
| options | A list of Options to apply. | `any` | `[]` | no |
| parameter\_group\_description | Description of the DB parameter group to create | `string` | `""` | no |
| parameter\_group\_name | Name of the DB parameter group to associate or create | `string` | `""` | no |
| parameter\_group\_name | Name of the DB parameter group to associate or create | `string` | `null` | no |
| parameter\_group\_use\_name\_prefix | Determines whether to use `parameter_group_name` as is or create a unique name beginning with the `parameter_group_name` as the prefix | `bool` | `true` | no |
| parameters | A list of DB parameters (map) to apply | `list(map(string))` | `[]` | no |
| password | Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file | `string` | n/a | yes |
17 changes: 17 additions & 0 deletions examples/complete-mysql/README.md
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ No provider.
| Name | Source | Version |
|------|--------|---------|
| db | ../../ | |
| db_default | ../../ | |
| security_group | terraform-aws-modules/security-group/aws | ~> 3 |
| vpc | terraform-aws-modules/vpc/aws | ~> 2 |

@@ -46,6 +47,22 @@ No input.

| Name | Description |
|------|-------------|
| db\_default\_instance\_address | The address of the RDS instance |
| db\_default\_instance\_arn | The ARN of the RDS instance |
| db\_default\_instance\_availability\_zone | The availability zone of the RDS instance |
| db\_default\_instance\_endpoint | The connection endpoint |
| db\_default\_instance\_hosted\_zone\_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| db\_default\_instance\_id | The RDS instance ID |
| db\_default\_instance\_name | The database name |
| db\_default\_instance\_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| db\_default\_instance\_port | The database port |
| db\_default\_instance\_resource\_id | The RDS Resource ID of this instance |
| db\_default\_instance\_status | The RDS instance status |
| db\_default\_instance\_username | The master username for the database |
| db\_default\_parameter\_group\_arn | The ARN of the db parameter group |
| db\_default\_parameter\_group\_id | The db parameter group id |
| db\_default\_subnet\_group\_arn | The ARN of the db subnet group |
| db\_default\_subnet\_group\_id | The db subnet group name |
| this\_db\_instance\_address | The address of the RDS instance |
| this\_db\_instance\_arn | The ARN of the RDS instance |
| this\_db\_instance\_availability\_zone | The availability zone of the RDS instance |
48 changes: 32 additions & 16 deletions examples/complete-mysql/main.tf
Original file line number Diff line number Diff line change
@@ -106,22 +106,38 @@ module "db" {
}
]

options = [
{
option_name = "MARIADB_AUDIT_PLUGIN"

option_settings = [
{
name = "SERVER_AUDIT_EVENTS"
value = "CONNECT"
},
{
name = "SERVER_AUDIT_FILE_ROTATIONS"
value = "37"
},
]
},
]
tags = local.tags
}

module "db_default" {
source = "../../"

identifier = "${local.name}-default"

create_db_option_group = false
create_db_parameter_group = false

# All available versions: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html#MySQL.Concepts.VersionMgmt
engine = "mysql"
engine_version = "8.0.20"
family = "mysql8.0" # DB parameter group
major_engine_version = "8.0" # DB option group
instance_class = "db.t3.large"

allocated_storage = 20

name = "completeMysql"
username = "complete_mysql"
password = "YourPwdShouldBeLongAndSecure!"
port = 3306

subnet_ids = module.vpc.database_subnets
vpc_security_group_ids = [module.security_group.this_security_group_id]

maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00"

backup_retention_period = 0

tags = local.tags
}
82 changes: 82 additions & 0 deletions examples/complete-mysql/outputs.tf
Original file line number Diff line number Diff line change
@@ -78,3 +78,85 @@ output "this_db_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.db.this_db_parameter_group_arn
}

# Default
output "db_default_instance_address" {
description = "The address of the RDS instance"
value = module.db_default.this_db_instance_address
}

output "db_default_instance_arn" {
description = "The ARN of the RDS instance"
value = module.db_default.this_db_instance_arn
}

output "db_default_instance_availability_zone" {
description = "The availability zone of the RDS instance"
value = module.db_default.this_db_instance_availability_zone
}

output "db_default_instance_endpoint" {
description = "The connection endpoint"
value = module.db_default.this_db_instance_endpoint
}

output "db_default_instance_hosted_zone_id" {
description = "The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)"
value = module.db_default.this_db_instance_hosted_zone_id
}

output "db_default_instance_id" {
description = "The RDS instance ID"
value = module.db_default.this_db_instance_id
}

output "db_default_instance_resource_id" {
description = "The RDS Resource ID of this instance"
value = module.db_default.this_db_instance_resource_id
}

output "db_default_instance_status" {
description = "The RDS instance status"
value = module.db_default.this_db_instance_status
}

output "db_default_instance_name" {
description = "The database name"
value = module.db_default.this_db_instance_name
}

output "db_default_instance_username" {
description = "The master username for the database"
value = module.db_default.this_db_instance_username
}

output "db_default_instance_password" {
description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)"
value = module.db_default.this_db_instance_password
sensitive = true
}

output "db_default_instance_port" {
description = "The database port"
value = module.db_default.this_db_instance_port
}

output "db_default_subnet_group_id" {
description = "The db subnet group name"
value = module.db_default.this_db_subnet_group_id
}

output "db_default_subnet_group_arn" {
description = "The ARN of the db subnet group"
value = module.db_default.this_db_subnet_group_arn
}

output "db_default_parameter_group_id" {
description = "The db parameter group id"
value = module.db_default.this_db_parameter_group_id
}

output "db_default_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.db_default.this_db_parameter_group_arn
}
17 changes: 17 additions & 0 deletions examples/complete-postgres/README.md
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ No provider.
| Name | Source | Version |
|------|--------|---------|
| db | ../../ | |
| db_default | ../../ | |
| security_group | terraform-aws-modules/security-group/aws | ~> 3 |
| vpc | terraform-aws-modules/vpc/aws | ~> 2 |

@@ -46,6 +47,22 @@ No input.

| Name | Description |
|------|-------------|
| db\_default\_instance\_address | The address of the RDS instance |
| db\_default\_instance\_arn | The ARN of the RDS instance |
| db\_default\_instance\_availability\_zone | The availability zone of the RDS instance |
| db\_default\_instance\_endpoint | The connection endpoint |
| db\_default\_instance\_hosted\_zone\_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| db\_default\_instance\_id | The RDS instance ID |
| db\_default\_instance\_name | The database name |
| db\_default\_instance\_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| db\_default\_instance\_port | The database port |
| db\_default\_instance\_resource\_id | The RDS Resource ID of this instance |
| db\_default\_instance\_status | The RDS instance status |
| db\_default\_instance\_username | The master username for the database |
| db\_default\_parameter\_group\_arn | The ARN of the db parameter group |
| db\_default\_parameter\_group\_id | The db parameter group id |
| db\_default\_subnet\_group\_arn | The ARN of the db subnet group |
| db\_default\_subnet\_group\_id | The db subnet group name |
| this\_db\_instance\_address | The address of the RDS instance |
| this\_db\_instance\_arn | The ARN of the RDS instance |
| this\_db\_instance\_availability\_zone | The availability zone of the RDS instance |
37 changes: 37 additions & 0 deletions examples/complete-postgres/main.tf
Original file line number Diff line number Diff line change
@@ -111,3 +111,40 @@ module "db" {

tags = local.tags
}


module "db_default" {
source = "../../"

identifier = "${local.name}-default"

create_db_option_group = false
create_db_parameter_group = false

# All available versions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts
engine = "postgres"
engine_version = "11.10"
family = "postgres11" # DB parameter group
major_engine_version = "11" # DB option group
instance_class = "db.t3.large"

allocated_storage = 20

# NOTE: Do NOT use 'user' as the value for 'username' as it throws:
# "Error creating DB Instance: InvalidParameterValue: MasterUsername
# user cannot be used as it is a reserved word used by the engine"
name = "completePostgresql"
username = "complete_postgresql"
password = "YourPwdShouldBeLongAndSecure!"
port = 5432

subnet_ids = module.vpc.database_subnets
vpc_security_group_ids = [module.security_group.this_security_group_id]

maintenance_window = "Mon:00:00-Mon:03:00"
backup_window = "03:00-06:00"

backup_retention_period = 0

tags = local.tags
}
82 changes: 82 additions & 0 deletions examples/complete-postgres/outputs.tf
Original file line number Diff line number Diff line change
@@ -78,3 +78,85 @@ output "this_db_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.db.this_db_parameter_group_arn
}

# Default
output "db_default_instance_address" {
description = "The address of the RDS instance"
value = module.db_default.this_db_instance_address
}

output "db_default_instance_arn" {
description = "The ARN of the RDS instance"
value = module.db_default.this_db_instance_arn
}

output "db_default_instance_availability_zone" {
description = "The availability zone of the RDS instance"
value = module.db_default.this_db_instance_availability_zone
}

output "db_default_instance_endpoint" {
description = "The connection endpoint"
value = module.db_default.this_db_instance_endpoint
}

output "db_default_instance_hosted_zone_id" {
description = "The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record)"
value = module.db_default.this_db_instance_hosted_zone_id
}

output "db_default_instance_id" {
description = "The RDS instance ID"
value = module.db_default.this_db_instance_id
}

output "db_default_instance_resource_id" {
description = "The RDS Resource ID of this instance"
value = module.db_default.this_db_instance_resource_id
}

output "db_default_instance_status" {
description = "The RDS instance status"
value = module.db_default.this_db_instance_status
}

output "db_default_instance_name" {
description = "The database name"
value = module.db_default.this_db_instance_name
}

output "db_default_instance_username" {
description = "The master username for the database"
value = module.db_default.this_db_instance_username
}

output "db_default_instance_password" {
description = "The database password (this password may be old, because Terraform doesn't track it after initial creation)"
value = module.db_default.this_db_instance_password
sensitive = true
}

output "db_default_instance_port" {
description = "The database port"
value = module.db_default.this_db_instance_port
}

output "db_default_subnet_group_id" {
description = "The db subnet group name"
value = module.db_default.this_db_subnet_group_id
}

output "db_default_subnet_group_arn" {
description = "The ARN of the db subnet group"
value = module.db_default.this_db_subnet_group_arn
}

output "db_default_parameter_group_id" {
description = "The db parameter group id"
value = module.db_default.this_db_parameter_group_id
}

output "db_default_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.db_default.this_db_parameter_group_arn
}
5 changes: 5 additions & 0 deletions examples/groups/README.md
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ No provider.
|------|--------|---------|
| byo_mysql | ../../ | |
| default_mysql | ../../ | |
| default_mysql_default_aws | ../../ | |
| default_mysql_name | ../../ | |
| default_postgres | ../../ | |

@@ -51,6 +52,10 @@ No input.
| byo\_mysql\_option\_group\_id | The ID of the BYO MySQL option group (should be blank) |
| byo\_mysql\_parameter\_group\_arn | The ARN of the db parameter group |
| byo\_mysql\_parameter\_group\_id | The db parameter group id |
| default\_mysql\_default\_aws\_option\_group\_arn | The ARN of the default MySQL option group |
| default\_mysql\_default\_aws\_option\_group\_id | The ID of the default MySQL option group |
| default\_mysql\_default\_aws\_parameter\_group\_arn | The ARN of the db parameter group |
| default\_mysql\_default\_aws\_parameter\_group\_id | The db parameter group id |
| default\_mysql\_name\_option\_group\_arn | The ARN of the default MySQL option group using `name` |
| default\_mysql\_name\_option\_group\_id | The ID of the default MySQL option group using `name` |
| default\_mysql\_name\_parameter\_group\_arn | The ARN of the db parameter group |
Loading

0 comments on commit 8b8f9b7

Please sign in to comment.