Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add security group name #120

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
locals {
port = "${var.port == "" ? "${var.engine == "aurora-postgresql" ? "5432" : "3306"}" : var.port}"
master_password = "${var.password == "" ? random_id.master_password.b64 : var.password}"
backtrack_window = "${var.backtrack_window == "" ? "${var.engine == "aurora" ? "0" : ""}" : var.backtrack_window}"
port = "${var.port == "" ? "${var.engine == "aurora-postgresql" ? "5432" : "3306"}" : var.port}"
master_password = "${var.password == "" ? random_id.master_password.b64 : var.password}"
db_subnet_group_name = "${var.db_subnet_group_name == "" ? join("", aws_db_subnet_group.this.*.name) : var.db_subnet_group_name}"
backtrack_window = "${var.backtrack_window == "" ? "${var.engine == "aurora" ? "0" : ""}" : var.backtrack_window}"
}

# Random string to use as master password unless one is specified
Expand All @@ -10,6 +11,8 @@ resource "random_id" "master_password" {
}

resource "aws_db_subnet_group" "this" {
count = "${var.db_subnet_group_name == "" ? 1 : 0}"

name = "${var.name}"
description = "For Aurora cluster ${var.name}"
subnet_ids = ["${var.subnets}"]
Expand All @@ -36,7 +39,7 @@ resource "aws_rds_cluster" "this" {
preferred_backup_window = "${var.preferred_backup_window}"
preferred_maintenance_window = "${var.preferred_maintenance_window}"
port = "${local.port}"
db_subnet_group_name = "${aws_db_subnet_group.this.name}"
db_subnet_group_name = "${local.db_subnet_group_name}"
vpc_security_group_ids = ["${concat(list(aws_security_group.this.id), var.vpc_security_group_ids)}"]
scaling_configuration = "${var.scaling_configuration}"
snapshot_identifier = "${var.snapshot_identifier}"
Expand All @@ -60,7 +63,7 @@ resource "aws_rds_cluster_instance" "this" {
engine_version = "${var.engine_version}"
instance_class = "${var.instance_type}"
publicly_accessible = "${var.publicly_accessible}"
db_subnet_group_name = "${aws_db_subnet_group.this.name}"
db_subnet_group_name = "${local.db_subnet_group_name}"
db_parameter_group_name = "${var.db_parameter_group_name}"
preferred_maintenance_window = "${var.preferred_maintenance_window}"
apply_immediately = "${var.apply_immediately}"
Expand Down Expand Up @@ -144,7 +147,9 @@ resource "aws_security_group" "this" {
name_prefix = "${var.name}-"
vpc_id = "${var.vpc_id}"

tags = "${var.tags}"
description = "${var.security_group_description == "" ? "Control traffic to/from RDS Aurora ${var.name}" : var.security_group_description}"

tags = "${merge(var.tags, map("Name", "${var.name}"))}"
}

resource "aws_security_group_rule" "default_ingress" {
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ variable "vpc_security_group_ids" {
default = []
}

variable "db_subnet_group_name" {
description = "The existing subnet group name to use"
default = ""
}

variable "backtrack_window" {
description = "The target backtrack window, in seconds. Only available for aurora engine currently. To disable backtracking, set this value to 0. Defaults to 0. Must be between 0 and 259200 (72 hours)"
default = "0"
Expand All @@ -244,3 +249,8 @@ variable "copy_tags_to_snapshot" {
description = "Indicates whether to copy all of the user-defined tags from the DB instance to snapshots of the DB instance."
default = false
}

variable "security_group_description" {
description = "The description of the security group. If value is set to empty string it will contain cluster name in the description."
default = ""
}