Commit afc7dcf6 authored by zachawilson's avatar zachawilson Committed by Anton Babenko

Add option group support (#55)

* Support database option group

* support option group with latest
parent 13ef27f8
......@@ -7,12 +7,14 @@ These types of resources are supported:
* [DB Instance](https://www.terraform.io/docs/providers/aws/r/db_instance.html)
* [DB Subnet Group](https://www.terraform.io/docs/providers/aws/r/db_subnet_group.html)
* [DB Parameter Group](https://www.terraform.io/docs/providers/aws/r/db_parameter_group.html)
* [DB Option Group](https://www.terraform.io/docs/providers/aws/r/db_option_group.html)
Root module calls these modules which can also be used separately to create independent resources:
* [db_instance](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_instance) - creates RDS DB instance
* [db_subnet_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_subnet_group) - creates RDS DB subnet group
* [db_parameter_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_parameter_group) - creates RDS DB group
* [db_parameter_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_parameter_group) - creates RDS DB parameter group
* [db_option_group](https://github.com/terraform-aws-modules/terraform-aws-rds/tree/master/modules/db_option_group) - creates RDS DB option group
## Usage
......@@ -56,6 +58,9 @@ module "db" {
# DB parameter group
family = "mysql5.7"
# DB option group
major_engine_version = "5.7"
# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"
......@@ -69,6 +74,12 @@ module "db" {
value = "utf8"
}
]
options = [
{
option_name = "MARIADB_AUDIT_PLUGIN"
}
]
}
```
......
......@@ -58,6 +58,9 @@ module "db" {
# DB parameter group
family = "mysql5.7"
# DB option group
major_engine_version = "5.7"
# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"
}
......@@ -58,6 +58,9 @@ module "db" {
# DB parameter group
family = "oracle-ee-12.1"
# DB option group
major_engine_version = "12.1"
# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"
......
......@@ -62,6 +62,9 @@ module "db" {
# DB parameter group
family = "postgres9.6"
# DB option group
major_engine_version = "9.6"
# Snapshot name upon DB deletion
final_snapshot_identifier = "demodb"
}
......@@ -78,6 +78,8 @@ module "db" {
subnet_ids = ["${data.aws_subnet_ids.all.ids}"]
# DB parameter group
family = "mysql5.7"
# DB option group
major_engine_version = "5.7"
monitoring_interval = "30"
monitoring_role_arn = "${aws_iam_role.rds_enhanced_monitoring.arn}"
}
......@@ -3,6 +3,8 @@ locals {
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}"
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.create_db_option_group : 0}"
}
module "db_subnet_group" {
......@@ -29,6 +31,20 @@ module "db_parameter_group" {
tags = "${var.tags}"
}
module "db_option_group" {
source = "./modules/db_option_group"
create = "${local.enable_create_db_option_group}"
identifier = "${var.identifier}"
name_prefix = "${var.identifier}-"
engine_name = "${var.engine}"
major_engine_version = "${var.major_engine_version}"
options = ["${var.options}"]
tags = "${var.tags}"
}
module "db_instance" {
source = "./modules/db_instance"
......@@ -56,6 +72,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}"
option_group_name = "${local.option_group_name}"
availability_zone = "${var.availability_zone}"
multi_az = "${var.multi_az}"
......
......@@ -43,6 +43,7 @@ resource "aws_db_instance" "this" {
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
db_subnet_group_name = "${var.db_subnet_group_name}"
parameter_group_name = "${var.parameter_group_name}"
option_group_name = "${var.option_group_name}"
availability_zone = "${var.availability_zone}"
multi_az = "${var.multi_az}"
......@@ -94,6 +95,7 @@ resource "aws_db_instance" "this_mssql" {
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
db_subnet_group_name = "${var.db_subnet_group_name}"
parameter_group_name = "${var.parameter_group_name}"
option_group_name = "${var.option_group_name}"
availability_zone = "${var.availability_zone}"
multi_az = "${var.multi_az}"
......
......@@ -178,6 +178,11 @@ variable "tags" {
default = {}
}
variable "option_group_name" {
description = "Name of the DB option group to associate."
default = ""
}
variable "timezone" {
description = "(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."
default = ""
......
#####################
# DB option group
#####################
resource "aws_db_option_group" "this" {
count = "${var.create ? 1 : 0}"
name_prefix = "${var.name_prefix}"
option_group_description = "${var.option_group_description == "" ? format("Option group for %s", var.identifier) : var.option_group_description}"
engine_name = "${var.engine_name}"
major_engine_version = "${var.major_engine_version}"
option = ["${var.options}"]
tags = "${merge(var.tags, map("Name", format("%s", var.identifier)))}"
}
# DB option group
output "this_db_option_group_id" {
description = "The db option group id"
value = "${element(split(",", join(",", aws_db_option_group.this.*.id)), 0)}"
}
output "this_db_option_group_arn" {
description = "The ARN of the db option group"
value = "${element(split(",", join(",", aws_db_option_group.this.*.arn)), 0)}"
}
variable "create" {
description = "Whether to create this resource or not?"
default = true
}
variable "name_prefix" {
description = "Creates a unique name beginning with the specified prefix"
}
variable "identifier" {
description = "The identifier of the resource"
}
variable "option_group_description" {
description = "The description of the option group"
default = ""
}
variable "engine_name" {
description = "Specifies the name of the engine that this option group should be associated with"
}
variable "major_engine_version" {
description = "Specifies the major version of the engine that this option group should be associated with"
}
variable "options" {
type = "list"
description = "A list of Options to apply."
default = []
}
variable "tags" {
type = "map"
description = "A mapping of tags to assign to the resource"
default = {}
}
......@@ -77,3 +77,14 @@ output "this_db_parameter_group_arn" {
description = "The ARN of the db parameter group"
value = "${module.db_parameter_group.this_db_parameter_group_arn}"
}
# DB option group
output "this_db_option_group_id" {
description = "The db option group id"
value = "${module.db_option_group.this_db_option_group_id}"
}
output "this_db_option_group_arn" {
description = "The ARN of the db option group"
value = "${module.db_option_group.this_db_option_group_arn}"
}
......@@ -90,6 +90,11 @@ variable "parameter_group_name" {
default = ""
}
variable "option_group_name" {
description = "Name of the DB option group to associate. Setting this automatically disables option_group creation"
default = ""
}
variable "availability_zone" {
description = "The Availability Zone of the RDS instance"
default = ""
......@@ -191,6 +196,23 @@ variable "parameters" {
default = []
}
# DB option group
variable "option_group_description" {
description = "The description of the option group"
default = ""
}
variable "major_engine_version" {
description = "Specifies the major version of the engine that this option group should be associated with"
default = ""
}
variable "options" {
type = "list"
description = "A list of Options to apply."
default = []
}
variable "create_db_subnet_group" {
description = "Whether to create a database subnet group"
default = true
......@@ -201,6 +223,11 @@ variable "create_db_parameter_group" {
default = true
}
variable "create_db_option_group" {
description = "Whether to create a database option group"
default = true
}
variable "create_db_instance" {
description = "Whether to create a database instance"
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