Skip to content

Commit

Permalink
Add Optional elasticache_subnet_group (#34)
Browse files Browse the repository at this point in the history
* [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: aknysh <[email protected]>

* Update variables.tf

Co-Authored-By: aknysh <[email protected]>

* Update variables.tf

Co-Authored-By: aknysh <[email protected]>

* Update main.tf

Co-Authored-By: aknysh <[email protected]>

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

* Update example

* Update README
  • Loading branch information
joshmyers authored and aknysh committed Apr 15, 2019
1 parent 1841eaa commit 307e630
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 131 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ install:
- make init

script:
- make terraform:install
- make terraform:get-plugins
- make terraform:get-modules
- make terraform:lint
- make terraform:validate
- make terraform/install
- make terraform/get-plugins
- make terraform/get-modules
- make terraform/lint
- make terraform/validate
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
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");
you may not use this file except in compliance with the License.
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are

## 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
// Generate a random string for auth token, no special chars
Expand Down Expand Up @@ -113,6 +117,7 @@ Available targets:
| availability_zones | Availability zone ids | list | `<list>` | no |
| cluster_size | Count of nodes in cluster | string | `1` | 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 |
| engine_version | Redis engine version | string | `4.0.10` | no |
| family | Redis family | string | `redis4.0` | no |
Expand All @@ -127,20 +132,20 @@ 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 |
| security_groups | AWS security group ids | list | `<list>` | 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 |
| 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 |

## Outputs

| Name | Description |
|------|-------------|
| host | Redis host |
| id | Redis cluster id |
| id | Redis cluster ID |
| port | Redis port |
| security_group_id | Security group id |
| security_group_id | Security group ID |



Expand Down Expand Up @@ -207,7 +212,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright)
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)



Expand Down
215 changes: 107 additions & 108 deletions README.yaml
Original file line number Diff line number Diff line change
@@ -1,108 +1,107 @@
---
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#

# Name of this project
name: terraform-aws-elasticache-redis

# Tags of this project
tags:
- aws
- terraform
- terraform-modules
- databases
- redis
- elasticache
- cache

# Categories of this project
categories:
- terraform-modules/databases

# Logo for this project
#logo: docs/logo.png

# License of this project
license: "APACHE2"

# Canonical GitHub repo
github_repo: cloudposse/terraform-aws-elasticache-redis

# Badges to display
badges:
- name: "Build Status"
image: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis.svg?branch=master"
url: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis"
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-elasticache-redis.svg"
url: "https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/releases/latest"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"

# Short description of this project
description: |-
Terraform module to provision an [`ElastiCache`](https://aws.amazon.com/elasticache/) Redis Cluster
# How to use this project
usage: |-
Include this repository as a module in your existing terraform code:
```hcl
// Generate a random string for auth token, no special chars
resource "random_string" "auth_token" {
length = 64
special = false
}
module "example_redis" {
source = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=master"
namespace = "general"
name = "redis"
stage = "prod"
zone_id = "${var.route53_zone_id}"
security_groups = ["${var.security_group_id}"]
auth_token = "${random_string.auth_token.result}"
vpc_id = "${var.vpc_id}"
subnets = "${var.private_subnets}"
maintenance_window = "wed:03:00-wed:04:00"
cluster_size = "2"
instance_type = "cache.t2.micro"
engine_version = "4.0.10"
alarm_cpu_threshold_percent = "${var.cache_alarm_cpu_threshold_percent}"
alarm_memory_threshold_bytes = "${var.cache_alarm_memory_threshold_bytes}"
apply_immediately = "true"
availability_zones = "${var.availability_zones}"
automatic_failover = "false"
}
output "auth_token" {
value = "${random_string.auth_token.result}"
}
```
examples: |-
Review the [complete example](examples/simple) to see how to use this module.
include:
- "docs/targets.md"
- "docs/terraform.md"

# Contributors to this project
contributors:
- name: "Erik Osterman"
github: "osterman"
- name: "Igor Rodionov"
github: "goruha"
- name: "Andriy Knysh"
github: "aknysh"
- name: "Daren Desjardins"
github: "darend"
- name: "Max Moon"
github: "MoonMoon1919"
- name: "Christopher Riley"
github: "christopherriley"
---
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#

# Name of this project
name: terraform-aws-elasticache-redis

# Tags of this project
tags:
- aws
- terraform
- terraform-modules
- databases
- redis
- elasticache
- cache

# Categories of this project
categories:
- terraform-modules/databases

# Logo for this project
#logo: docs/logo.png

# License of this project
license: "APACHE2"

# Canonical GitHub repo
github_repo: cloudposse/terraform-aws-elasticache-redis

# Badges to display
badges:
- name: "Build Status"
image: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis.svg?branch=master"
url: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis"
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-elasticache-redis.svg"
url: "https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/releases/latest"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"

# Short description of this project
description: |-
Terraform module to provision an [`ElastiCache`](https://aws.amazon.com/elasticache/) Redis Cluster
# How to use this project
usage: |-
```hcl
// Generate a random string for auth token, no special chars
resource "random_string" "auth_token" {
length = 64
special = false
}
module "example_redis" {
source = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=master"
namespace = "general"
name = "redis"
stage = "prod"
zone_id = "${var.route53_zone_id}"
security_groups = ["${var.security_group_id}"]
auth_token = "${random_string.auth_token.result}"
vpc_id = "${var.vpc_id}"
subnets = "${var.private_subnets}"
maintenance_window = "wed:03:00-wed:04:00"
cluster_size = "2"
instance_type = "cache.t2.micro"
engine_version = "4.0.10"
alarm_cpu_threshold_percent = "${var.cache_alarm_cpu_threshold_percent}"
alarm_memory_threshold_bytes = "${var.cache_alarm_memory_threshold_bytes}"
apply_immediately = "true"
availability_zones = "${var.availability_zones}"
automatic_failover = "false"
}
output "auth_token" {
value = "${random_string.auth_token.result}"
}
```
examples: |-
Review the [complete example](examples/simple) to see how to use this module.
include:
- "docs/targets.md"
- "docs/terraform.md"

# Contributors to this project
contributors:
- name: "Erik Osterman"
github: "osterman"
- name: "Igor Rodionov"
github: "goruha"
- name: "Andriy Knysh"
github: "aknysh"
- name: "Daren Desjardins"
github: "darend"
- name: "Max Moon"
github: "MoonMoon1919"
- name: "Christopher Riley"
github: "christopherriley"
9 changes: 5 additions & 4 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| availability_zones | Availability zone ids | list | `<list>` | no |
| cluster_size | Count of nodes in cluster | string | `1` | 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 |
| engine_version | Redis engine version | string | `4.0.10` | no |
| family | Redis family | string | `redis4.0` | no |
Expand All @@ -27,18 +28,18 @@
| 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 |
| 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 |
| 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 |

## Outputs

| Name | Description |
|------|-------------|
| host | Redis host |
| id | Redis cluster id |
| id | Redis cluster ID |
| port | Redis port |
| security_group_id | Security group id |
| security_group_id | Security group ID |

5 changes: 5 additions & 0 deletions examples/simple/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace = "eg"

name = "redis"

stage = "testing"

zone_id = "Z3SO0TKDDQ0RGG"

region = "us-west-2"

availability_zones = ["us-west-2a", "us-west-2b"]
10 changes: 7 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ resource "aws_security_group" "default" {
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" {
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}"
subnet_ids = ["${var.subnets}"]
}
Expand All @@ -60,7 +64,7 @@ resource "aws_elasticache_replication_group" "default" {
parameter_group_name = "${aws_elasticache_parameter_group.default.name}"
availability_zones = ["${slice(var.availability_zones, 0, var.cluster_size)}"]
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}"]
maintenance_window = "${var.maintenance_window}"
notification_topic_arn = "${var.notification_topic_arn}"
Expand Down Expand Up @@ -119,7 +123,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
}

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"}"
namespace = "${var.namespace}"
name = "${var.name}"
Expand Down
4 changes: 2 additions & 2 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
output "id" {
value = "${join("", aws_elasticache_replication_group.default.*.id)}"
description = "Redis cluster id"
description = "Redis cluster ID"
}

output "security_group_id" {
value = "${join("", aws_security_group.default.*.id)}"
description = "Security group id"
description = "Security group ID"
}

output "port" {
Expand Down
Loading

0 comments on commit 307e630

Please sign in to comment.