-
Notifications
You must be signed in to change notification settings - Fork 48
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
Better use of tags as map #18
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,26 +36,28 @@ | |
* } | ||
* | ||
* module "aurora_db_56" { | ||
* source = "../.." | ||
* name = "test-aurora-db-56" | ||
* envname = "test56" | ||
* envtype = "test" | ||
* subnets = ["${module.vpc.private_subnets}"] | ||
* azs = ["${module.vpc.availability_zones}"] | ||
* replica_count = "1" | ||
* security_groups = ["${aws_security_group.allow_all.id}"] | ||
* instance_type = "db.t2.medium" | ||
* username = "root" | ||
* password = "changeme" | ||
* backup_retention_period = "5" | ||
* final_snapshot_identifier = "final-db-snapshot-prod" | ||
* storage_encrypted = "true" | ||
* apply_immediately = "true" | ||
* monitoring_interval = "10" | ||
* cw_alarms = true | ||
* cw_sns_topic = "${aws_sns_topic.db_alarms_56.id}" | ||
* db_parameter_group_name = "${aws_db_parameter_group.aurora_db_56_parameter_group.id}" | ||
* db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.aurora_cluster_56_parameter_group.id}" | ||
* source = "../.." | ||
* name = "test-aurora-db-56" | ||
* subnets = ["${module.vpc.private_subnets}"] | ||
* azs = ["${module.vpc.availability_zones}"] | ||
* replica_count = "1" | ||
* security_groups = ["${aws_security_group.allow_all.id}"] | ||
* instance_type = "db.t2.medium" | ||
* username = "root" | ||
* password = "changeme" | ||
* backup_retention_period = "5" | ||
* final_snapshot_identifier = "final-db-snapshot-prod" | ||
* storage_encrypted = "true" | ||
* apply_immediately = "true" | ||
* monitoring_interval = "10" | ||
* cw_alarms = true | ||
* cw_sns_topic = "${aws_sns_topic.db_alarms_56.id}" | ||
* db_parameter_group_name = "${aws_db_parameter_group.aurora_db_56_parameter_group.id}" | ||
* db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.aurora_cluster_56_parameter_group.id}" | ||
* tags = { | ||
* envname = "test56" | ||
* envtype = "test" | ||
* } | ||
* } | ||
* | ||
* resource "aws_db_parameter_group" "aurora_db_56_parameter_group" { | ||
|
@@ -82,8 +84,6 @@ | |
* engine = "aurora-mysql" | ||
* engine-version = "5.7.12" | ||
* name = "test-aurora-db-57" | ||
* envname = "test-57" | ||
* envtype = "test" | ||
* subnets = ["${module.vpc.private_subnets}"] | ||
* azs = ["${module.vpc.availability_zones}"] | ||
* replica_count = "1" | ||
|
@@ -100,6 +100,10 @@ | |
* cw_sns_topic = "${aws_sns_topic.db_alarms.id}" | ||
* db_parameter_group_name = "${aws_db_parameter_group.aurora_db_57_parameter_group.id}" | ||
* db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.aurora_57_cluster_parameter_group.id}" | ||
* tags = { | ||
* envname = "test-57" | ||
* envtype = "test" | ||
* } | ||
* } | ||
* | ||
* resource "aws_db_parameter_group" "aurora_db_57_parameter_group" { | ||
|
@@ -126,8 +130,6 @@ | |
* engine = "aurora-postgresql" | ||
* engine-version = "9.6.3" | ||
* name = "test-aurora-db-postgres96" | ||
* envname = "test-pg96" | ||
* envtype = "test" | ||
* subnets = ["${module.vpc.private_subnets}"] | ||
* azs = ["${module.vpc.availability_zones}"] | ||
* replica_count = "1" | ||
|
@@ -144,6 +146,10 @@ | |
* cw_sns_topic = "${aws_sns_topic.db_alarms_postgres96.id}" | ||
* db_parameter_group_name = "${aws_db_parameter_group.aurora_db_postgres96_parameter_group.id}" | ||
* db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.aurora_cluster_postgres96_parameter_group.id}" | ||
* tags = { | ||
* envname = "test-pg96" | ||
* envtype = "test" | ||
* } | ||
* } | ||
* | ||
* resource "aws_db_parameter_group" "aurora_db_postgres96_parameter_group" { | ||
|
@@ -166,15 +172,12 @@ resource "aws_db_subnet_group" "main" { | |
description = "Group of DB subnets" | ||
subnet_ids = ["${var.subnets}"] | ||
|
||
tags { | ||
envname = "${var.envname}" | ||
envtype = "${var.envtype}" | ||
} | ||
tags = "${merge(var.tags, map("Name", format("%s", var.identifier_prefix)))}" | ||
} | ||
|
||
// Create single DB instance | ||
resource "aws_rds_cluster_instance" "cluster_instance_0" { | ||
identifier = "${var.identifier_prefix != "" ? format("%s-node-0", var.identifier_prefix) : format("%s-aurora-node-0", var.envname)}" | ||
identifier = "${format("%s-node-0", var.identifier_prefix)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allow the identifier_prefix to be empty |
||
cluster_identifier = "${aws_rds_cluster.default.id}" | ||
engine = "${var.engine}" | ||
engine_version = "${var.engine-version}" | ||
|
@@ -189,10 +192,7 @@ resource "aws_rds_cluster_instance" "cluster_instance_0" { | |
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}" | ||
promotion_tier = "0" | ||
|
||
tags { | ||
envname = "${var.envname}" | ||
envtype = "${var.envtype}" | ||
} | ||
tags = "${merge(var.tags, map("Name", format("%s", var.identifier_prefix)))}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
} | ||
|
||
// Create 'n' number of additional DB instance(s) in same cluster | ||
|
@@ -201,7 +201,7 @@ resource "aws_rds_cluster_instance" "cluster_instance_n" { | |
count = "${var.replica_scale_enabled ? var.replica_scale_min : var.replica_count}" | ||
engine = "${var.engine}" | ||
engine_version = "${var.engine-version}" | ||
identifier = "${var.identifier_prefix != "" ? format("%s-node-%d", var.identifier_prefix, count.index + 1) : format("%s-aurora-node-%d", var.envname, count.index + 1)}" | ||
identifier = "${format("%s-node-%d", var.identifier_prefix, count.index + 1)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
cluster_identifier = "${aws_rds_cluster.default.id}" | ||
instance_class = "${var.instance_type}" | ||
publicly_accessible = "${var.publicly_accessible}" | ||
|
@@ -214,15 +214,12 @@ resource "aws_rds_cluster_instance" "cluster_instance_n" { | |
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}" | ||
promotion_tier = "${count.index + 1}" | ||
|
||
tags { | ||
envname = "${var.envname}" | ||
envtype = "${var.envtype}" | ||
} | ||
tags = "${merge(var.tags, map("Name", format("%s", var.identifier_prefix)))}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
} | ||
|
||
// Create DB Cluster | ||
resource "aws_rds_cluster" "default" { | ||
cluster_identifier = "${var.identifier_prefix != "" ? format("%s-cluster", var.identifier_prefix) : format("%s-aurora-cluster", var.envname)}" | ||
cluster_identifier = "${format("%s-cluster", var.identifier_prefix)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
availability_zones = ["${var.azs}"] | ||
engine = "${var.engine}" | ||
|
||
|
@@ -266,7 +263,7 @@ data "aws_iam_policy_document" "monitoring-rds-assume-role-policy" { | |
|
||
resource "aws_iam_role" "rds-enhanced-monitoring" { | ||
count = "${var.monitoring_interval > 0 ? 1 : 0}" | ||
name = "rds-enhanced-monitoring-${var.envname}" | ||
name = "rds-enhanced-monitoring-${var.identifier_prefix}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest the iam_role name is parameterised |
||
assume_role_policy = "${data.aws_iam_policy_document.monitoring-rds-assume-role-policy.json}" | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,8 @@ variable "subnets" { | |
description = "List of subnet IDs to use" | ||
} | ||
|
||
variable "envname" { | ||
type = "string" | ||
description = "Environment name (eg,test, stage or prod)" | ||
} | ||
|
||
variable "envtype" { | ||
type = "string" | ||
description = "Environment type (eg,prod or nonprod)" | ||
} | ||
|
||
variable "identifier_prefix" { | ||
type = "string" | ||
default = "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we leave the default for the identifier_prefix? |
||
description = "Prefix for cluster and instance identifier" | ||
} | ||
|
||
|
@@ -217,3 +206,9 @@ variable "replica_scale_out_cooldown" { | |
default = "300" | ||
description = "Cooldown in seconds before allowing further scaling operations after a scale out" | ||
} | ||
|
||
variable "tags" { | ||
description = "A mapping of tags to assign to the resource" | ||
default = {} | ||
type = "map" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are forcing the use of a Name tag assigned to the identifier_prefix, as well as any tags in the map. Can we not have this?