Commit 7805f160 authored by Robin Bowes's avatar Robin Bowes Committed by Anton Babenko

Allow create of parameter group with custom name (#99)

* Create parameter group with custom name

* Allow setting of parameter group description too

* Move locals into main.tf

* Include "no_prefix" resource in output

* Update all README files with terraform docs
parent 8f0c5a0a
This diff is collapsed.
......@@ -17,26 +17,25 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Outputs
| Name | Description |
|------|-------------|
| 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 |
| this_db_instance_endpoint | The connection endpoint |
| this_db_instance_hosted_zone_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this_db_instance_id | The RDS instance ID |
| this_db_instance_name | The database name |
| this_db_instance_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this_db_instance_port | The database port |
| this_db_instance_resource_id | The RDS Resource ID of this instance |
| this_db_instance_status | The RDS instance status |
| this_db_instance_username | The master username for the database |
| this_db_parameter_group_arn | The ARN of the db parameter group |
| this_db_parameter_group_id | The db parameter group id |
| this_db_subnet_group_arn | The ARN of the db subnet group |
| this_db_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 |
| this\_db\_instance\_endpoint | The connection endpoint |
| this\_db\_instance\_hosted\_zone\_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this\_db\_instance\_id | The RDS instance ID |
| this\_db\_instance\_name | The database name |
| this\_db\_instance\_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this\_db\_instance\_port | The database port |
| this\_db\_instance\_resource\_id | The RDS Resource ID of this instance |
| this\_db\_instance\_status | The RDS instance status |
| this\_db\_instance\_username | The master username for the database |
| this\_db\_parameter\_group\_arn | The ARN of the db parameter group |
| this\_db\_parameter\_group\_id | The db parameter group id |
| this\_db\_subnet\_group\_arn | The ARN of the db subnet group |
| this\_db\_subnet\_group\_id | The db subnet group name |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -17,26 +17,25 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Outputs
| Name | Description |
|------|-------------|
| 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 |
| this_db_instance_endpoint | The connection endpoint |
| this_db_instance_hosted_zone_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this_db_instance_id | The RDS instance ID |
| this_db_instance_name | The database name |
| this_db_instance_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this_db_instance_port | The database port |
| this_db_instance_resource_id | The RDS Resource ID of this instance |
| this_db_instance_status | The RDS instance status |
| this_db_instance_username | The master username for the database |
| this_db_parameter_group_arn | The ARN of the db parameter group |
| this_db_parameter_group_id | The db parameter group id |
| this_db_subnet_group_arn | The ARN of the db subnet group |
| this_db_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 |
| this\_db\_instance\_endpoint | The connection endpoint |
| this\_db\_instance\_hosted\_zone\_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this\_db\_instance\_id | The RDS instance ID |
| this\_db\_instance\_name | The database name |
| this\_db\_instance\_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this\_db\_instance\_port | The database port |
| this\_db\_instance\_resource\_id | The RDS Resource ID of this instance |
| this\_db\_instance\_status | The RDS instance status |
| this\_db\_instance\_username | The master username for the database |
| this\_db\_parameter\_group\_arn | The ARN of the db parameter group |
| this\_db\_parameter\_group\_id | The db parameter group id |
| this\_db\_subnet\_group\_arn | The ARN of the db subnet group |
| this\_db\_subnet\_group\_id | The db subnet group name |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -17,26 +17,25 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Outputs
| Name | Description |
|------|-------------|
| 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 |
| this_db_instance_endpoint | The connection endpoint |
| this_db_instance_hosted_zone_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this_db_instance_id | The RDS instance ID |
| this_db_instance_name | The database name |
| this_db_instance_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this_db_instance_port | The database port |
| this_db_instance_resource_id | The RDS Resource ID of this instance |
| this_db_instance_status | The RDS instance status |
| this_db_instance_username | The master username for the database |
| this_db_parameter_group_arn | The ARN of the db parameter group |
| this_db_parameter_group_id | The db parameter group id |
| this_db_subnet_group_arn | The ARN of the db subnet group |
| this_db_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 |
| this\_db\_instance\_endpoint | The connection endpoint |
| this\_db\_instance\_hosted\_zone\_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this\_db\_instance\_id | The RDS instance ID |
| this\_db\_instance\_name | The database name |
| this\_db\_instance\_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this\_db\_instance\_port | The database port |
| this\_db\_instance\_resource\_id | The RDS Resource ID of this instance |
| this\_db\_instance\_status | The RDS instance status |
| this\_db\_instance\_username | The master username for the database |
| this\_db\_parameter\_group\_arn | The ARN of the db parameter group |
| this\_db\_parameter\_group\_id | The db parameter group id |
| this\_db\_subnet\_group\_arn | The ARN of the db subnet group |
| this\_db\_subnet\_group\_id | The db subnet group name |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -17,26 +17,25 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Outputs
| Name | Description |
|------|-------------|
| 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 |
| this_db_instance_endpoint | The connection endpoint |
| this_db_instance_hosted_zone_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this_db_instance_id | The RDS instance ID |
| this_db_instance_name | The database name |
| this_db_instance_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this_db_instance_port | The database port |
| this_db_instance_resource_id | The RDS Resource ID of this instance |
| this_db_instance_status | The RDS instance status |
| this_db_instance_username | The master username for the database |
| this_db_parameter_group_arn | The ARN of the db parameter group |
| this_db_parameter_group_id | The db parameter group id |
| this_db_subnet_group_arn | The ARN of the db subnet group |
| this_db_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 |
| this\_db\_instance\_endpoint | The connection endpoint |
| this\_db\_instance\_hosted\_zone\_id | The canonical hosted zone ID of the DB instance (to be used in a Route 53 Alias record) |
| this\_db\_instance\_id | The RDS instance ID |
| this\_db\_instance\_name | The database name |
| this\_db\_instance\_password | The database password (this password may be old, because Terraform doesn't track it after initial creation) |
| this\_db\_instance\_port | The database port |
| this\_db\_instance\_resource\_id | The RDS Resource ID of this instance |
| this\_db\_instance\_status | The RDS instance status |
| this\_db\_instance\_username | The master username for the database |
| this\_db\_parameter\_group\_arn | The ARN of the db parameter group |
| this\_db\_parameter\_group\_id | The db parameter group id |
| this\_db\_subnet\_group\_arn | The ARN of the db subnet group |
| this\_db\_subnet\_group\_id | The db subnet group name |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -2,8 +2,8 @@ locals {
db_subnet_group_name = "${coalesce(var.db_subnet_group_name, module.db_subnet_group.this_db_subnet_group_id)}"
enable_create_db_subnet_group = "${var.db_subnet_group_name == "" ? var.create_db_subnet_group : 0}"
parameter_group_name = "${coalesce(var.parameter_group_name, module.db_parameter_group.this_db_parameter_group_id)}"
enable_create_db_parameter_group = "${var.parameter_group_name == "" ? var.create_db_parameter_group : 0}"
parameter_group_name = "${coalesce(var.parameter_group_name, var.identifier)}"
parameter_group_name_id = "${module.db_parameter_group.this_db_parameter_group_id}"
option_group_name = "${coalesce(var.option_group_name, module.db_option_group.this_db_option_group_id)}"
enable_create_db_option_group = "${var.option_group_name == "" && var.engine != "postgres" ? var.create_db_option_group : 0}"
......@@ -23,10 +23,13 @@ module "db_subnet_group" {
module "db_parameter_group" {
source = "./modules/db_parameter_group"
create = "${local.enable_create_db_parameter_group}"
identifier = "${var.identifier}"
name_prefix = "${var.identifier}-"
family = "${var.family}"
create = "${var.create_db_parameter_group}"
identifier = "${var.identifier}"
name = "${var.parameter_group_name}"
description = "${var.parameter_group_description}"
name_prefix = "${var.identifier}-"
use_name_prefix = "${var.use_parameter_group_name_prefix}"
family = "${var.family}"
parameters = ["${var.parameters}"]
......@@ -74,7 +77,7 @@ module "db_instance" {
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
db_subnet_group_name = "${local.db_subnet_group_name}"
parameter_group_name = "${local.parameter_group_name}"
parameter_group_name = "${local.parameter_group_name_id}"
option_group_name = "${local.option_group_name}"
availability_zone = "${var.availability_zone}"
......
This diff is collapsed.
# aws_db_option_group
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| create | Whether to create this resource or not? | string | `true` | no |
| engine_name | Specifies the name of the engine that this option group should be associated with | string | - | yes |
| identifier | The identifier of the resource | string | - | yes |
| major_engine_version | Specifies the major version of the engine that this option group should be associated with | string | - | yes |
| name_prefix | Creates a unique name beginning with the specified prefix | string | - | yes |
| option_group_description | The description of the option group | string | `` | no |
| create | Whether to create this resource or not? | string | `"true"` | no |
| engine\_name | Specifies the name of the engine that this option group should be associated with | string | n/a | yes |
| identifier | The identifier of the resource | string | n/a | yes |
| major\_engine\_version | Specifies the major version of the engine that this option group should be associated with | string | n/a | yes |
| name\_prefix | Creates a unique name beginning with the specified prefix | string | n/a | yes |
| option\_group\_description | The description of the option group | string | `""` | no |
| options | A list of Options to apply | list | `<list>` | no |
| tags | A mapping of tags to assign to the resource | map | `<map>` | no |
......@@ -19,7 +18,7 @@
| Name | Description |
|------|-------------|
| this_db_option_group_arn | The ARN of the db option group |
| this_db_option_group_id | The db option group id |
| this\_db\_option\_group\_arn | The ARN of the db option group |
| this\_db\_option\_group\_id | The db option group id |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
# aws_db_parameter_group
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| create | Whether to create this resource or not? | string | `true` | no |
| family | The family of the DB parameter group | string | - | yes |
| identifier | The identifier of the resource | string | - | yes |
| name_prefix | Creates a unique name beginning with the specified prefix | string | - | yes |
| parameters | A list of DB parameter maps to apply | string | `<list>` | no |
| create | Whether to create this resource or not? | string | `"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 | `<list>` | no |
| tags | A mapping of tags to assign to the resource | map | `<map>` | no |
| use\_name\_prefix | Whether to use name_prefix or not | string | `"true"` | no |
## Outputs
| Name | Description |
|------|-------------|
| this_db_parameter_group_arn | The ARN of the db parameter group |
| this_db_parameter_group_id | The db parameter group id |
| this\_db\_parameter\_group\_arn | The ARN of the db parameter group |
| this\_db\_parameter\_group\_id | The db parameter group id |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
locals {
description = "${coalesce(var.description, "Database parameter group for ${var.identifier}")}"
}
resource "aws_db_parameter_group" "this_no_prefix" {
count = "${var.create && ! var.use_name_prefix ? 1 : 0}"
name = "${var.name}"
description = "${local.description}"
family = "${var.family}"
parameter = ["${var.parameters}"]
tags = "${merge(var.tags, map("Name", format("%s", var.name)))}"
lifecycle {
create_before_destroy = true
}
}
resource "aws_db_parameter_group" "this" {
count = "${var.create ? 1 : 0}"
count = "${var.create && var.use_name_prefix ? 1 : 0}"
name_prefix = "${var.name_prefix}"
description = "Database parameter group for ${var.identifier}"
description = "${local.description}"
family = "${var.family}"
parameter = ["${var.parameters}"]
......
output "this_db_parameter_group_id" {
description = "The db parameter group id"
value = "${element(split(",", join(",", aws_db_parameter_group.this.*.id)), 0)}"
value = "${element(concat(coalescelist(aws_db_parameter_group.this.*.id, aws_db_parameter_group.this_no_prefix.*.id), list("")), 0)}"
}
output "this_db_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = "${element(split(",", join(",", aws_db_parameter_group.this.*.arn)), 0)}"
value = "${element(concat(coalescelist(aws_db_parameter_group.this.*.arn, aws_db_parameter_group.this_no_prefix.*.arn), list("")), 0)}"
}
......@@ -3,7 +3,18 @@ variable "create" {
default = true
}
variable "description" {
default = ""
description = "The description of the DB parameter group"
}
variable "name" {
default = ""
description = "The name of the DB parameter group"
}
variable "name_prefix" {
default = ""
description = "Creates a unique name beginning with the specified prefix"
}
......@@ -25,3 +36,8 @@ variable "tags" {
description = "A mapping of tags to assign to the resource"
default = {}
}
variable "use_name_prefix" {
description = "Whether to use name_prefix or not"
default = true
}
# aws_db_subnet_group
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| create | Whether to create this resource or not? | string | `true` | no |
| identifier | The identifier of the resource | string | - | yes |
| name_prefix | Creates a unique name beginning with the specified prefix | string | - | yes |
| subnet_ids | A list of VPC subnet IDs | list | `<list>` | no |
| create | Whether to create this resource or not? | string | `"true"` | no |
| identifier | The identifier of the resource | string | n/a | yes |
| name\_prefix | Creates a unique name beginning with the specified prefix | string | n/a | yes |
| subnet\_ids | A list of VPC subnet IDs | list | `<list>` | no |
| tags | A mapping of tags to assign to the resource | map | `<map>` | no |
## Outputs
| Name | Description |
|------|-------------|
| this_db_subnet_group_arn | The ARN of the db subnet group |
| this_db_subnet_group_id | The db subnet group name |
| this\_db\_subnet\_group\_arn | The ARN of the db subnet group |
| this\_db\_subnet\_group\_id | The db subnet group name |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -85,8 +85,13 @@ variable "db_subnet_group_name" {
default = ""
}
variable "parameter_group_description" {
description = "Description of the DB parameter group to create"
default = ""
}
variable "parameter_group_name" {
description = "Name of the DB parameter group to associate. Setting this automatically disables parameter_group creation"
description = "Name of the DB parameter group to associate or create"
default = ""
}
......@@ -263,3 +268,8 @@ variable "deletion_protection" {
description = "The database can't be deleted when this value is set to true."
default = false
}
variable "use_parameter_group_name_prefix" {
description = "Whether to use the parameter group name prefix or not"
default = true
}
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