Commit 8dac72ef authored by Bryant Biggs's avatar Bryant Biggs Committed by GitHub

fix: update parameter group to fix name vs. name_prefix (#304)

parent a5495a4c
......@@ -237,6 +237,7 @@ No resources.
| 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\_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 |
| performance\_insights\_enabled | Specifies whether Performance Insights are enabled | `bool` | `false` | no |
......@@ -254,7 +255,6 @@ No resources.
| tags | A mapping of tags to assign to all resources | `map(string)` | `{}` | no |
| timeouts | (Optional) Updated Terraform resource management timeouts. Applies to `aws_db_instance` in particular to permit resource management times | `map(string)` | <pre>{<br> "create": "40m",<br> "delete": "40m",<br> "update": "80m"<br>}</pre> | no |
| timezone | (Optional) Time zone of the DB instance. timezone is currently only supported by Microsoft SQL Server. The timezone can only be set on creation. See MSSQL User Guide for more information. | `string` | `""` | no |
| use\_parameter\_group\_name\_prefix | Whether to use the parameter group name prefix or not | `bool` | `true` | no |
| username | Username for the master DB user | `string` | n/a | yes |
| vpc\_security\_group\_ids | List of VPC security groups to associate | `list(string)` | `[]` | no |
......
# Example usage of option groups
# Example usage of option and parameter groups
Configuration in this directory creates various option groups depending on the configuration specified - no other resources are created.
Configuration in this directory creates various option and parameter groups depending on the configuration specified - no other resources are created.
## Usage
......@@ -49,10 +49,18 @@ No input.
|------|-------------|
| byo\_mysql\_option\_group\_arn | The ARN of the BYO MySQL option group (should be blank) |
| 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\_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 |
| default\_mysql\_name\_parameter\_group\_id | The db parameter group id |
| default\_mysql\_option\_group\_arn | The ARN of the default MySQL option group |
| default\_mysql\_option\_group\_id | The ID of the default MySQL option group |
| default\_mysql\_parameter\_group\_arn | The ARN of the db parameter group |
| default\_mysql\_parameter\_group\_id | The db parameter group id |
| default\_postgres\_option\_group\_arn | The ARN of the default PostgreSQL option group (should be blank) |
| default\_postgres\_option\_group\_id | The ID of the default PostgreSQL option group (should be blank) |
| default\_postgres\_parameter\_group\_arn | The ARN of the db parameter group |
| default\_postgres\_parameter\_group\_id | The db parameter group id |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -12,9 +12,7 @@ locals {
}
################################################################################
# Default Postgres option group
# This should NOT create anything since option groups are not supported for PostgreSQL
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html
# Default Postgres
################################################################################
module "default_postgres" {
......@@ -22,13 +20,16 @@ module "default_postgres" {
identifier = local.name
create_db_instance = false
parameter_group_name = "foo"
create_db_parameter_group = false
# This should NOT create an option group since they are not supported for PostgreSQL
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html
parameter_group_name = "${local.name}-default-postgresql"
db_subnet_group_name = "foo"
create_db_subnet_group = false
# All available versions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts
create_db_instance = false
engine = "postgres"
engine_version = "11.10"
family = "postgres11" # DB parameter group
......@@ -48,9 +49,7 @@ module "default_postgres" {
}
################################################################################
# Default MySQL Option Group w/ name prefix used
# This should create a MySQL option group
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html
# Default MySQL
################################################################################
module "default_mysql" {
......@@ -60,13 +59,13 @@ module "default_mysql" {
option_group_name = "${local.name}-default-mysql"
create_db_instance = false
parameter_group_name = "foo"
create_db_parameter_group = false
parameter_group_name = "${local.name}-default-mysql"
db_subnet_group_name = "foo"
create_db_subnet_group = false
# All available versions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts
create_db_instance = false
engine = "mysql"
engine_version = "8.0.20"
family = "mysql8.0" # DB parameter group
......@@ -86,9 +85,7 @@ module "default_mysql" {
}
################################################################################
# Default MySQL option group w/o name prefix
# This should create a MySQL option group
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html
# Default MySQL w/o name prefix
################################################################################
module "default_mysql_name" {
......@@ -96,16 +93,17 @@ module "default_mysql_name" {
identifier = local.name
option_group_name = "${local.name}-default-mysql"
option_group_name = "${local.name}-default-mysql-name"
option_group_use_name_prefix = false
create_db_instance = false
parameter_group_name = "foo"
create_db_parameter_group = false
parameter_group_name = "${local.name}-default-mysql-name"
parameter_group_use_name_prefix = false
db_subnet_group_name = "foo"
create_db_subnet_group = false
# All available versions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts
create_db_instance = false
engine = "mysql"
engine_version = "8.0.20"
family = "mysql8.0" # DB parameter group
......@@ -125,9 +123,7 @@ module "default_mysql_name" {
}
################################################################################
# BYO MySQL Option Group
# This should NOT create a MySQL option group - the user is specifying an option group to use
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithOptionGroups.html
# BYO MySQL
################################################################################
module "byo_mysql" {
......@@ -138,13 +134,14 @@ module "byo_mysql" {
create_db_option_group = false
option_group_name = "bringMyOwnOptionGroupName"
create_db_instance = false
parameter_group_name = "foo"
create_db_parameter_group = false
parameter_group_name = "bringMyOwnParameterGroupName"
db_subnet_group_name = "foo"
create_db_subnet_group = false
# All available versions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts
create_db_instance = false
engine = "mysql"
engine_version = "8.0.20"
family = "mysql8.0" # DB parameter group
......
......@@ -9,6 +9,16 @@ output "default_postgres_option_group_arn" {
value = module.default_postgres.this_db_option_group_arn
}
output "default_postgres_parameter_group_id" {
description = "The db parameter group id"
value = module.default_postgres.this_db_parameter_group_id
}
output "default_postgres_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.default_postgres.this_db_parameter_group_arn
}
# Default MySQL
output "default_mysql_option_group_id" {
description = "The ID of the default MySQL option group"
......@@ -20,6 +30,16 @@ output "default_mysql_option_group_arn" {
value = module.default_mysql.this_db_option_group_arn
}
output "default_mysql_parameter_group_id" {
description = "The db parameter group id"
value = module.default_mysql.this_db_parameter_group_id
}
output "default_mysql_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.default_mysql.this_db_parameter_group_arn
}
# Default MySQL name
output "default_mysql_name_option_group_id" {
description = "The ID of the default MySQL option group using `name`"
......@@ -31,6 +51,16 @@ output "default_mysql_name_option_group_arn" {
value = module.default_mysql_name.this_db_option_group_arn
}
output "default_mysql_name_parameter_group_id" {
description = "The db parameter group id"
value = module.default_mysql_name.this_db_parameter_group_id
}
output "default_mysql_name_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.default_mysql_name.this_db_parameter_group_arn
}
# BYO MySQL
output "byo_mysql_option_group_id" {
description = "The ID of the BYO MySQL option group (should be blank)"
......@@ -42,3 +72,12 @@ output "byo_mysql_option_group_arn" {
value = module.byo_mysql.this_db_option_group_arn
}
output "byo_mysql_parameter_group_id" {
description = "The db parameter group id"
value = module.byo_mysql.this_db_parameter_group_id
}
output "byo_mysql_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = module.byo_mysql.this_db_parameter_group_arn
}
locals {
enable_create_db_subnet_group = var.db_subnet_group_name == "" ? var.create_db_subnet_group : false
create_db_subnet_group = var.db_subnet_group_name == "" ? var.create_db_subnet_group : false
db_subnet_group_name = coalesce(var.db_subnet_group_name, module.db_subnet_group.this_db_subnet_group_id)
parameter_group_name_id = coalesce(var.parameter_group_name, module.db_parameter_group.this_db_parameter_group_id)
enable_create_db_option_group = var.create_db_option_group && var.engine != "postgres"
create_db_option_group = var.create_db_option_group && var.engine != "postgres"
option_group = var.engine != "postgres" ? coalesce(module.db_option_group.this_db_option_group_id, var.option_group_name) : null
}
module "db_subnet_group" {
source = "./modules/db_subnet_group"
create = local.enable_create_db_subnet_group
create = local.create_db_subnet_group
identifier = var.identifier
name_prefix = "${var.identifier}-"
subnet_ids = var.subnet_ids
......@@ -23,11 +23,10 @@ module "db_parameter_group" {
source = "./modules/db_parameter_group"
create = var.create_db_parameter_group
identifier = var.identifier
name = var.parameter_group_name
use_name_prefix = var.parameter_group_use_name_prefix
description = var.parameter_group_description
name_prefix = "${var.identifier}-"
use_name_prefix = var.use_parameter_group_name_prefix
family = var.family
parameters = var.parameters
......@@ -35,12 +34,10 @@ module "db_parameter_group" {
tags = var.tags
}
# "${var.identifier}-${var.engine}-${var.major_engine_version}"
module "db_option_group" {
source = "./modules/db_option_group"
create = local.enable_create_db_option_group
create = local.create_db_option_group
name = var.option_group_name
use_name_prefix = var.option_group_use_name_prefix
......
......@@ -31,12 +31,10 @@ No Modules.
| create | Whether to create this resource or not? | `bool` | `true` | no |
| description | The description of the DB parameter group | `string` | `""` | no |
| family | The family of the DB parameter group | `string` | n/a | yes |
| identifier | The identifier of the resource | `string` | n/a | yes |
| name | The name of the DB parameter group | `string` | `""` | no |
| name\_prefix | Creates a unique name beginning with the specified prefix | `string` | `""` | no |
| parameters | A list of DB parameter maps to apply | `list(map(string))` | `[]` | no |
| tags | A mapping of tags to assign to the resource | `map(string)` | `{}` | no |
| use\_name\_prefix | Whether to use name\_prefix or not | `bool` | `true` | no |
| use\_name\_prefix | Determines whether to use `name` as is or create a unique name beginning with `name` as the specified prefix | `bool` | `true` | no |
## Outputs
......
locals {
description = coalesce(var.description, "Database parameter group for ${var.identifier}")
}
resource "aws_db_parameter_group" "this_no_prefix" {
count = var.create && false == var.use_name_prefix ? 1 : 0
name = var.name
description = local.description
family = var.family
name = var.use_name_prefix ? null : var.name
name_prefix = var.use_name_prefix ? "${var.name}-" : null
dynamic "parameter" {
for_each = var.parameters
content {
name = parameter.value.name
value = parameter.value.value
apply_method = lookup(parameter.value, "apply_method", null)
}
}
tags = merge(
var.tags,
{
"Name" = format("%s", var.name)
},
)
lifecycle {
create_before_destroy = true
}
description = coalesce(var.description, format("%s parameter group", var.name))
}
resource "aws_db_parameter_group" "this" {
count = var.create && var.use_name_prefix ? 1 : 0
count = var.create ? 1 : 0
name_prefix = var.name_prefix
name = local.name
name_prefix = local.name_prefix
description = local.description
family = var.family
......@@ -49,7 +25,7 @@ resource "aws_db_parameter_group" "this" {
tags = merge(
var.tags,
{
"Name" = format("%s", var.identifier)
"Name" = var.name
},
)
......
output "this_db_parameter_group_id" {
description = "The db parameter group id"
value = element(concat(aws_db_parameter_group.this.*.id, aws_db_parameter_group.this_no_prefix.*.id, [""]), 0)
value = element(concat(aws_db_parameter_group.this.*.id, [""]), 0)
}
output "this_db_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = element(concat(aws_db_parameter_group.this.*.arn, aws_db_parameter_group.this_no_prefix.*.arn, [""]), 0)
value = element(concat(aws_db_parameter_group.this.*.arn, [""]), 0)
}
......@@ -4,27 +4,22 @@ variable "create" {
default = true
}
variable "description" {
description = "The description of the DB parameter group"
type = string
default = ""
}
variable "name" {
description = "The name of the DB parameter group"
type = string
default = ""
}
variable "name_prefix" {
description = "Creates a unique name beginning with the specified prefix"
type = string
default = ""
variable "use_name_prefix" {
description = "Determines whether to use `name` as is or create a unique name beginning with `name` as the specified prefix"
type = bool
default = true
}
variable "identifier" {
description = "The identifier of the resource"
variable "description" {
description = "The description of the DB parameter group"
type = string
default = ""
}
variable "family" {
......@@ -43,10 +38,3 @@ variable "tags" {
type = map(string)
default = {}
}
variable "use_name_prefix" {
description = "Whether to use name_prefix or not"
type = bool
default = true
}
......@@ -116,18 +116,6 @@ variable "db_subnet_group_name" {
default = ""
}
variable "parameter_group_description" {
description = "Description of the DB parameter group to create"
type = string
default = ""
}
variable "parameter_group_name" {
description = "Name of the DB parameter group to associate or create"
type = string
default = ""
}
variable "availability_zone" {
description = "The Availability Zone of the RDS instance"
type = string
......@@ -242,6 +230,30 @@ variable "subnet_ids" {
}
# DB parameter group
variable "create_db_parameter_group" {
description = "Whether to create a database parameter group"
type = bool
default = true
}
variable "parameter_group_name" {
description = "Name of the DB parameter group to associate or create"
type = string
default = ""
}
variable "parameter_group_use_name_prefix" {
description = "Determines whether to use `parameter_group_name` as is or create a unique name beginning with the `parameter_group_name` as the prefix"
type = bool
default = true
}
variable "parameter_group_description" {
description = "Description of the DB parameter group to create"
type = string
default = ""
}
variable "family" {
description = "The family of the DB parameter group"
type = string
......@@ -255,6 +267,12 @@ variable "parameters" {
}
# DB option group
variable "create_db_option_group" {
description = "(Optional) Create a database option group"
type = bool
default = true
}
variable "option_group_name" {
description = "Name of the option group"
type = string
......@@ -291,18 +309,6 @@ variable "create_db_subnet_group" {
default = true
}
variable "create_db_parameter_group" {
description = "Whether to create a database parameter group"
type = bool
default = true
}
variable "create_db_option_group" {
description = "(Optional) Create a database option group"
type = bool
default = true
}
variable "create_db_instance" {
description = "Whether to create a database instance"
type = bool
......@@ -351,12 +357,6 @@ variable "deletion_protection" {
default = false
}
variable "use_parameter_group_name_prefix" {
description = "Whether to use the parameter group name prefix or not"
type = bool
default = true
}
variable "performance_insights_enabled" {
description = "Specifies whether Performance Insights are enabled"
type = bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment