Skip to content

Commit

Permalink
Add enabled flag (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh authored May 11, 2018
1 parent 6666493 commit df90b4e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module "rds_cluster_aurora_postgres" {
admin_user = "admin"
admin_password = "Test123"
db_name = "dbname"
instance_type = "db.t2.small"
instance_type = "db.r4.large"
vpc_id = "vpc-xxxxxxx"
availability_zones = ["us-east-1a", "us-east-1b"]
security_groups = ["sg-0a6d5a3a"]
Expand All @@ -32,7 +32,7 @@ module "rds_cluster_aurora_postgres" {
With [cluster parameters](examples/with_cluster_parameters)

```hcl
module "rds_cluster_aurora" {
module "rds_cluster_aurora_mysql" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=master"
engine = "aurora"
cluster_size = "2"
Expand Down
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module "rds_cluster_aurora_postgres" {
With [cluster parameters](examples/with_cluster_parameters)

```hcl
module "rds_cluster_aurora" {
module "rds_cluster_aurora_mysql" {
source = "git::https://github.com/cloudposse/terraform-aws-rds-cluster.git?ref=master"
engine = "aurora"
cluster_size = "2"
Expand Down Expand Up @@ -112,6 +112,7 @@ module "rds_cluster_aurora" {
| db_name |__REQUIRED__ |Database name|
| db_port |"3306" |Database port|
| delimiter |"-" |Delimiter to be used between `name`, `namespace`, `stage` and `attributes`|
| enabled |"true" |Set to false to prevent the module from creating any resources|
| engine |"aurora" |The name of the database engine to be used for this DB cluster. Valid values: `aurora`, `aurora-postgresql`|
| engine_version |"" |The version number of the database engine to use|
| instance_type |"db.t2.small" |Instance type to use|
Expand Down Expand Up @@ -145,6 +146,7 @@ module "rds_cluster_aurora" {

File a GitHub [issue](https://github.com/cloudposse/terraform-aws-rds-cluster/issues), send us an [email](mailto:[email protected]) or reach out to us on [Gitter](https://gitter.im/cloudposse/).


## Contributing

### Bug Reports & Feature Requests
Expand All @@ -165,9 +167,10 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

**NOTE:** Be sure to merge the latest from "upstream" before making a pull request!


## License

[APACHE 2.0](LICENSE) © 2017 [Cloud Posse, LLC](https://cloudposse.com)
[APACHE 2.0](LICENSE) © 2017-2018 [Cloud Posse, LLC](https://cloudposse.com)

See [LICENSE](LICENSE) for full details.

Expand All @@ -188,41 +191,34 @@ See [LICENSE](LICENSE) for full details.
specific language governing permissions and limitations
under the License.


## About

This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at <[email protected]>
`terraform-aws-rds-cluster` is maintained and funded by [Cloud Posse, LLC][website].

![Cloud Posse](https://cloudposse.com/logo-300x69.png)


Like it? Please let us know at <[email protected]>

We love [Open Source Software](https://github.com/cloudposse/)!

See [our other projects][community]
or [hire us][hire] to help build your next cloud-platform.
or [hire us][hire] to help build your next cloud platform.

[website]: http://cloudposse.com/
[website]: https://cloudposse.com/
[community]: https://github.com/cloudposse/
[hire]: http://cloudposse.com/contact/
[hire]: https://cloudposse.com/contact/

### Contributors

|[![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] |[![Igor Rodionov][igor_img]][igor_web]<br/>[Igor Rodionov][igor_img] |[![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web] |[![Sergey Vasilyev][sergey_img]][sergey_web]<br/>[Sergey Vasilyev][sergey_web] |
|---|---|---|---|
## Contributors

[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[andriy_web]: https://github.com/aknysh/
| [![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] | [![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web] |[![Igor Rodionov][igor_img]][igor_web]<br/>[Igor Rodionov][igor_img]
|-------------------------------------------------------|------------------------------------------------------------------|------------------------------------------------------------------|

[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144
[erik_web]: https://github.com/osterman/

[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[andriy_web]: https://github.com/aknysh/
[igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144
[igor_web]: https://github.com/goruha/

[konstantin_img]: https://avatars1.githubusercontent.com/u/11299538?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[konstantin_web]: https://github.com/comeanother/

[sergey_img]: https://avatars1.githubusercontent.com/u/1134449?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[sergey_web]: https://github.com/s2504s/

[valeriy_img]: https://avatars1.githubusercontent.com/u/10601658?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[valeriy_web]: https://github.com/drama17/

[vladimir_img]: https://avatars1.githubusercontent.com/u/26582191?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[vladimir_web]: https://github.com/SweetOps/
2 changes: 1 addition & 1 deletion examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module "rds_cluster_aurora_postgres" {
admin_user = "admin"
admin_password = "Test123"
db_name = "dbname"
instance_type = "db.t2.small"
instance_type = "db.r4.large"
vpc_id = "vpc-xxxxxxx"
availability_zones = ["us-east-1a", "us-east-1b"]
security_groups = ["sg-0a6d5a3a"]
Expand Down
2 changes: 1 addition & 1 deletion examples/with_cluster_parameters/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module "rds_cluster_aurora" {
module "rds_cluster_aurora_mysql" {
source = "../../"
engine = "aurora"
cluster_size = "2"
Expand Down
19 changes: 13 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ module "label" {
delimiter = "${var.delimiter}"
attributes = "${var.attributes}"
tags = "${var.tags}"
enabled = "${var.enabled}"
}

resource "aws_security_group" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.label.id}"
description = "Allow inbound traffic from Sgs and CIDRs"
description = "Allow inbound traffic from Security Groups and CIDRs"
vpc_id = "${var.vpc_id}"

ingress {
Expand Down Expand Up @@ -38,6 +40,7 @@ resource "aws_security_group" "default" {
}

resource "aws_rds_cluster" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
cluster_identifier = "${module.label.id}"
availability_zones = ["${var.availability_zones}"]
database_name = "${var.db_name}"
Expand All @@ -59,7 +62,7 @@ resource "aws_rds_cluster" "default" {
}

resource "aws_rds_cluster_instance" "default" {
count = "${var.cluster_size}"
count = "${var.enabled == "true" ? var.cluster_size : 0}"
identifier = "${module.label.id}-${count.index+1}"
cluster_identifier = "${aws_rds_cluster.default.id}"
instance_class = "${var.instance_type}"
Expand All @@ -71,13 +74,15 @@ resource "aws_rds_cluster_instance" "default" {
}

resource "aws_db_subnet_group" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.label.id}"
description = "Allowed subnets for DB cluster instances"
subnet_ids = ["${var.subnets}"]
tags = "${module.label.tags}"
}

resource "aws_rds_cluster_parameter_group" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
name = "${module.label.id}"
description = "DB cluster parameter group"
family = "${var.cluster_family}"
Expand All @@ -86,19 +91,21 @@ resource "aws_rds_cluster_parameter_group" "default" {
}

module "dns_master" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.1"
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.2"
namespace = "${var.namespace}"
name = "master.${var.name}"
stage = "${var.stage}"
zone_id = "${var.zone_id}"
records = ["${aws_rds_cluster.default.endpoint}"]
records = ["${coalescelist(aws_rds_cluster.default.*.endpoint, list(""))}"]
enabled = "${var.enabled}"
}

module "dns_replicas" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.1"
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.2"
namespace = "${var.namespace}"
name = "replicas.${var.name}"
stage = "${var.stage}"
zone_id = "${var.zone_id}"
records = ["${aws_rds_cluster.default.reader_endpoint}"]
records = ["${coalescelist(aws_rds_cluster.default.*.reader_endpoint, list(""))}"]
enabled = "${var.enabled}"
}
16 changes: 8 additions & 8 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
output "name" {
value = "${aws_rds_cluster.default.database_name}"
value = "${join("", aws_rds_cluster.default.*.database_name)}"
description = "Database name"
}

output "user" {
value = "${aws_rds_cluster.default.master_username}"
value = "${join("", aws_rds_cluster.default.*.master_username)}"
description = "Username for the master DB user"
}

output "password" {
value = "${aws_rds_cluster.default.master_password}"
value = "${join("", aws_rds_cluster.default.*.master_password)}"
description = "Password for the master DB user"
}

output "cluster_name" {
value = "${join("", aws_rds_cluster.default.*.cluster_identifier)}"
description = "Cluster Identifier"
}

output "master_host" {
value = "${module.dns_master.hostname}"
description = "DB Master hostname"
Expand All @@ -22,8 +27,3 @@ output "replicas_host" {
value = "${module.dns_replicas.hostname}"
description = "Replicas hostname"
}

output "cluster_name" {
value = "${aws_rds_cluster.default.cluster_identifier}"
description = "Cluster Identifier"
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ variable "allowed_cidr_blocks" {
default = []
description = "List of CIDR blocks allowed to access"
}

variable "enabled" {
description = "Set to false to prevent the module from creating any resources"
default = "true"
}

0 comments on commit df90b4e

Please sign in to comment.