Commit 307e6300 authored by Josh Myers's avatar Josh Myers Committed by Andriy Knysh

Add Optional `elasticache_subnet_group` (#34)

* [issue-30] Optional elasticache_subnet_group ID

Add optional variable for the Elasticache subnet group ID so we can 
create the replication group in an already existing subnet group.

* Update main.tf
Co-Authored-By: default avataraknysh <aknysh@users.noreply.github.com>

* Update variables.tf
Co-Authored-By: default avataraknysh <aknysh@users.noreply.github.com>

* Update variables.tf
Co-Authored-By: default avataraknysh <aknysh@users.noreply.github.com>

* Update main.tf
Co-Authored-By: default avataraknysh <aknysh@users.noreply.github.com>

* Address comments, update LICENSE, update descriptions, update `README`

* Update example

* Update README
parent 1841eaae
...@@ -9,8 +9,8 @@ install: ...@@ -9,8 +9,8 @@ install:
- make init - make init
script: script:
- make terraform:install - make terraform/install
- make terraform:get-plugins - make terraform/get-plugins
- make terraform:get-modules - make terraform/get-modules
- make terraform:lint - make terraform/lint
- make terraform:validate - make terraform/validate
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier same "printed page" as the copyright notice for easier
identification within third-party archives. identification within third-party archives.
Copyright 2017 Cloud Posse, LLC Copyright 2017-2019 Cloud Posse, LLC
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
...@@ -42,7 +42,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are ...@@ -42,7 +42,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
## Usage ## Usage
Include this repository as a module in your existing terraform code:
**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases.
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-elasticache-redis/releases).
```hcl ```hcl
// Generate a random string for auth token, no special chars // Generate a random string for auth token, no special chars
...@@ -113,6 +117,7 @@ Available targets: ...@@ -113,6 +117,7 @@ Available targets:
| availability_zones | Availability zone ids | list | `<list>` | no | | availability_zones | Availability zone ids | list | `<list>` | no |
| cluster_size | Count of nodes in cluster | string | `1` | no | | cluster_size | Count of nodes in cluster | string | `1` | no |
| delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no | | delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
| elasticache_subnet_group_name | Subnet group name for the ElastiCache instance | string | `` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no | | enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| engine_version | Redis engine version | string | `4.0.10` | no | | engine_version | Redis engine version | string | `4.0.10` | no |
| family | Redis family | string | `redis4.0` | no | | family | Redis family | string | `redis4.0` | no |
...@@ -127,10 +132,10 @@ Available targets: ...@@ -127,10 +132,10 @@ Available targets:
| replication_group_id | Replication group ID with the following constraints: A name must contain from 1 to 20 alphanumeric characters or hyphens. The first character must be a letter. A name cannot end with a hyphen or contain two consecutive hyphens. | string | `` | no | | replication_group_id | Replication group ID with the following constraints: A name must contain from 1 to 20 alphanumeric characters or hyphens. The first character must be a letter. A name cannot end with a hyphen or contain two consecutive hyphens. | string | `` | no |
| security_groups | AWS security group ids | list | `<list>` | no | | security_groups | AWS security group ids | list | `<list>` | no |
| stage | Stage | string | `default` | no | | stage | Stage | string | `default` | no |
| subnets | AWS subnet ids | list | `<list>` | no | | subnets | AWS subnet IDs | list | `<list>` | no |
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map | `<map>` | no | | tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map | `<map>` | no |
| transit_encryption_enabled | Enable TLS | string | `true` | no | | transit_encryption_enabled | Enable TLS | string | `true` | no |
| vpc_id | AWS VPC id | string | `REQUIRED` | no | | vpc_id | AWS VPC id | string | - | yes |
| zone_id | Route53 DNS Zone id | string | `` | no | | zone_id | Route53 DNS Zone id | string | `` | no |
## Outputs ## Outputs
...@@ -138,9 +143,9 @@ Available targets: ...@@ -138,9 +143,9 @@ Available targets:
| Name | Description | | Name | Description |
|------|-------------| |------|-------------|
| host | Redis host | | host | Redis host |
| id | Redis cluster id | | id | Redis cluster ID |
| port | Redis port | | port | Redis port |
| security_group_id | Security group id | | security_group_id | Security group ID |
...@@ -207,7 +212,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. ...@@ -207,7 +212,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
## Copyright ## Copyright
Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright) Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)
......
...@@ -48,7 +48,6 @@ description: |- ...@@ -48,7 +48,6 @@ description: |-
# How to use this project # How to use this project
usage: |- usage: |-
Include this repository as a module in your existing terraform code:
```hcl ```hcl
// Generate a random string for auth token, no special chars // Generate a random string for auth token, no special chars
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
| availability_zones | Availability zone ids | list | `<list>` | no | | availability_zones | Availability zone ids | list | `<list>` | no |
| cluster_size | Count of nodes in cluster | string | `1` | no | | cluster_size | Count of nodes in cluster | string | `1` | no |
| delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no | | delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
| elasticache_subnet_group_name | Subnet group name for the ElastiCache instance | string | `` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no | | enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| engine_version | Redis engine version | string | `4.0.10` | no | | engine_version | Redis engine version | string | `4.0.10` | no |
| family | Redis family | string | `redis4.0` | no | | family | Redis family | string | `redis4.0` | no |
...@@ -27,10 +28,10 @@ ...@@ -27,10 +28,10 @@
| replication_group_id | Replication group ID with the following constraints: A name must contain from 1 to 20 alphanumeric characters or hyphens. The first character must be a letter. A name cannot end with a hyphen or contain two consecutive hyphens. | string | `` | no | | replication_group_id | Replication group ID with the following constraints: A name must contain from 1 to 20 alphanumeric characters or hyphens. The first character must be a letter. A name cannot end with a hyphen or contain two consecutive hyphens. | string | `` | no |
| security_groups | AWS security group ids | list | `<list>` | no | | security_groups | AWS security group ids | list | `<list>` | no |
| stage | Stage | string | `default` | no | | stage | Stage | string | `default` | no |
| subnets | AWS subnet ids | list | `<list>` | no | | subnets | AWS subnet IDs | list | `<list>` | no |
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map | `<map>` | no | | tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map | `<map>` | no |
| transit_encryption_enabled | Enable TLS | string | `true` | no | | transit_encryption_enabled | Enable TLS | string | `true` | no |
| vpc_id | AWS VPC id | string | `REQUIRED` | no | | vpc_id | AWS VPC id | string | - | yes |
| zone_id | Route53 DNS Zone id | string | `` | no | | zone_id | Route53 DNS Zone id | string | `` | no |
## Outputs ## Outputs
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
| Name | Description | | Name | Description |
|------|-------------| |------|-------------|
| host | Redis host | | host | Redis host |
| id | Redis cluster id | | id | Redis cluster ID |
| port | Redis port | | port | Redis port |
| security_group_id | Security group id | | security_group_id | Security group ID |
namespace = "eg" namespace = "eg"
name = "redis" name = "redis"
stage = "testing" stage = "testing"
zone_id = "Z3SO0TKDDQ0RGG" zone_id = "Z3SO0TKDDQ0RGG"
region = "us-west-2" region = "us-west-2"
availability_zones = ["us-west-2a", "us-west-2b"] availability_zones = ["us-west-2a", "us-west-2b"]
...@@ -35,8 +35,12 @@ resource "aws_security_group" "default" { ...@@ -35,8 +35,12 @@ resource "aws_security_group" "default" {
tags = "${module.label.tags}" tags = "${module.label.tags}"
} }
locals {
elasticache_subnet_group_name = "${var.elasticache_subnet_group_name != "" ? var.elasticache_subnet_group_name : join("", aws_elasticache_subnet_group.default.*.name) }"
}
resource "aws_elasticache_subnet_group" "default" { resource "aws_elasticache_subnet_group" "default" {
count = "${var.enabled == "true" ? 1 : 0}" count = "${var.enabled == "true" && var.elasticache_subnet_group_name == "" && length(var.subnets) > 0 ? 1 : 0}"
name = "${module.label.id}" name = "${module.label.id}"
subnet_ids = ["${var.subnets}"] subnet_ids = ["${var.subnets}"]
} }
...@@ -60,7 +64,7 @@ resource "aws_elasticache_replication_group" "default" { ...@@ -60,7 +64,7 @@ resource "aws_elasticache_replication_group" "default" {
parameter_group_name = "${aws_elasticache_parameter_group.default.name}" parameter_group_name = "${aws_elasticache_parameter_group.default.name}"
availability_zones = ["${slice(var.availability_zones, 0, var.cluster_size)}"] availability_zones = ["${slice(var.availability_zones, 0, var.cluster_size)}"]
automatic_failover_enabled = "${var.automatic_failover}" automatic_failover_enabled = "${var.automatic_failover}"
subnet_group_name = "${aws_elasticache_subnet_group.default.name}" subnet_group_name = "${local.elasticache_subnet_group_name}"
security_group_ids = ["${aws_security_group.default.id}"] security_group_ids = ["${aws_security_group.default.id}"]
maintenance_window = "${var.maintenance_window}" maintenance_window = "${var.maintenance_window}"
notification_topic_arn = "${var.notification_topic_arn}" notification_topic_arn = "${var.notification_topic_arn}"
...@@ -119,7 +123,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" { ...@@ -119,7 +123,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
} }
module "dns" { module "dns" {
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.6"
enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}" enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}"
namespace = "${var.namespace}" namespace = "${var.namespace}"
name = "${var.name}" name = "${var.name}"
......
output "id" { output "id" {
value = "${join("", aws_elasticache_replication_group.default.*.id)}" value = "${join("", aws_elasticache_replication_group.default.*.id)}"
description = "Redis cluster id" description = "Redis cluster ID"
} }
output "security_group_id" { output "security_group_id" {
value = "${join("", aws_security_group.default.*.id)}" value = "${join("", aws_security_group.default.*.id)}"
description = "Security group id" description = "Security group ID"
} }
output "port" { output "port" {
......
...@@ -25,16 +25,21 @@ variable "security_groups" { ...@@ -25,16 +25,21 @@ variable "security_groups" {
} }
variable "vpc_id" { variable "vpc_id" {
default = "REQUIRED"
description = "AWS VPC id" description = "AWS VPC id"
} }
variable "subnets" { variable "subnets" {
type = "list" type = "list"
description = "AWS subnet ids" description = "AWS subnet IDs"
default = [] default = []
} }
variable "elasticache_subnet_group_name" {
type = "string"
description = "Subnet group name for the ElastiCache instance"
default = ""
}
variable "maintenance_window" { variable "maintenance_window" {
default = "wed:03:00-wed:04:00" default = "wed:03:00-wed:04:00"
description = "Maintenance window" description = "Maintenance window"
......
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