Skip to content

Commit 4326cb3

Browse files
authored
Merge pull request #1 from pbs/initial_setup
Initial Setup
2 parents ebbccda + f1fb485 commit 4326cb3

22 files changed

+653
-84
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
.DS_Store
33
target
44
CHANGELOG.md
5-
*.tfstate
6-
*.tfstate.backup
5+
*tfstate*

README-HEADER.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PBS TF MOD_TITLE
1+
# PBS TF ElastiCache Redis Standalone Module
22

33
## Installation
44

@@ -7,7 +7,7 @@
77
Use this URL for the source of the module. See the usage examples below for more details.
88

99
```hcl
10-
github.com/pbs/terraform-aws-MOD_NAME?ref=x.y.z
10+
github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=x.y.z
1111
```
1212

1313
### Alternative Installation Methods
@@ -16,20 +16,17 @@ More information can be found on these install methods and more in [the document
1616

1717
## Usage
1818

19-
<!-- TODO -->
20-
This should be a basic description of what this module does.
21-
Fill this out before completing usage of this template.
22-
<!-- TODO -->
19+
Provisions an Elasticache Redis cluster (with Cluster Mode Disabled).
20+
21+
> ℹ️ Note the confusing terminology around `Cluster Mode`. The `Cluster Mode` setting is a Redis feature that allows data to be sharded among nodes in a cluster, and requires some additional configuration to connect with it correctly. A Redis cluster that does not have `Cluster Mode` enabled is a set of standalone Redis nodes that have a single primary node for reading and writing and replica nodes for reading.
22+
23+
By default, it will provision one writer and one reader node, but that can be adjusted by setting the `nodes` variable to a different value.
2324

2425
Integrate this module like so:
2526

2627
```hcl
27-
module "MOD_SHORTNAME" {
28-
source = "github.com/pbs/terraform-aws-MOD_NAME?ref=x.y.z"
29-
30-
<!-- TODO -->
31-
Show some examples of valid values for required parameters.
32-
<!-- TODO -->
28+
module "elasticache-redis-standalone" {
29+
source = "github.com/pbs/terraform-aws-elasticache-redis-standalone-module?ref=x.y.z"
3330
3431
# Tagging Parameters
3532
organization = var.organization

README.md

Lines changed: 137 additions & 19 deletions
Large diffs are not rendered by default.

data.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
data "aws_vpc" "vpc" {
2+
count = var.vpc_id == null ? 1 : 0
3+
tags = local.vpc_data_lookup_tags
4+
}
5+
6+
data "aws_subnets" "private_subnets" {
7+
count = var.subnets == null ? 1 : 0
8+
dynamic "filter" {
9+
for_each = local.subnet_data_lookup_filters
10+
content {
11+
name = filter.key
12+
values = filter.value
13+
}
14+
}
15+
}

docs/general/install/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ All the techniques for installing modules are based around the ways that Terrafo
1111
Assuming you don't have manual modifications that you need to make to serve the purposes of an application, the most convenient method of integrating modules might be by using the repo source of this module like so:
1212

1313
```hcl
14-
module "MOD_SHORTNAME" {
15-
source = "github.com/pbs/terraform-MOD_NAME?ref=x.y.z"
14+
module "elasticache-redis-standalone" {
15+
source = "github.com/pbs/terraform-elasticache-redis-standalone-module?ref=x.y.z"
1616
}
1717
```
1818

@@ -29,9 +29,9 @@ Note that the provider being used might also have availability or security impli
2929
You can install the minified module directly in your repo manually like so:
3030

3131
```bash
32-
mkdir -p 'terraform/modules/MOD_SHORTNAME'
33-
gh -R 'pbs/terraform-MOD_NAME' release download -p 'release.tar.gz' x.y.z
34-
tar -xvf release.tar.gz -C 'terraform/modules/MOD_SHORTNAME'
32+
mkdir -p 'terraform/modules/elasticache-redis-standalone'
33+
gh -R 'pbs/terraform-elasticache-redis-standalone-module' release download -p 'release.tar.gz' x.y.z
34+
tar -xvf release.tar.gz -C 'terraform/modules/elasticache-redis-standalone'
3535
rm -f release.tar.gz
3636
```
3737

@@ -46,14 +46,14 @@ Please [read this][atlassian-subtree] for information about Git Subtrees, as tha
4646
The simplest use case would work like so:
4747

4848
```bash
49-
git remote add -f MOD_SHORTNAME [email protected]:pbs/terraform-MOD_NAME.git
50-
git subtree add --prefix terraform/modules/MOD_SHORTNAME MOD_SHORTNAME main --squash
49+
git remote add -f elasticache-redis-standalone [email protected]:pbs/terraform-elasticache-redis-standalone-module.git
50+
git subtree add --prefix terraform/modules/elasticache-redis-standalone elasticache-redis-standalone main --squash
5151
```
5252

5353
If necessary, pin the repo version, rather than adding `main` as your subtree:
5454

5555
```bash
56-
git subtree add --prefix terraform/modules/MOD_SHORTNAME MOD_SHORTNAME $REF --squash
56+
git subtree add --prefix terraform/modules/elasticache-redis-standalone elasticache-redis-standalone $REF --squash
5757
```
5858

5959
Where `$REF` is a commit SHA, tag, or branch name.

docs/module/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# MOD_TITLE
1+
# elasticache redis standalone module
22

33
This directory will be used for any documentation that is unique to this module.

examples/basic/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module "MOD_SHORTNAME" {
1+
module "redis" {
22
source = "../.."
33

44
organization = var.organization

examples/basic/outputs.tf

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1-
output "hello_world" {
2-
description = "Hello World"
3-
value = module.MOD_SHORTNAME.hello_world
1+
output "name" {
2+
description = "The name of the ElastiCache replication group"
3+
value = module.redis.name
4+
}
5+
6+
output "arn" {
7+
description = "The ARN of the ElastiCache replication group"
8+
value = module.redis.arn
9+
}
10+
11+
output "sg_ids" {
12+
description = "The security group ids"
13+
value = module.redis.sg_ids
14+
}
15+
16+
output "engine_version_actual" {
17+
description = "Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine."
18+
value = module.redis.engine_version_actual
19+
}
20+
21+
output "member_clusters" {
22+
description = "Identifiers of all the nodes that are part of this replication group."
23+
value = module.redis.member_clusters
24+
}
25+
26+
output "primary_endpoint_address" {
27+
description = "Address of the endpoint for the primary node in the replication group."
28+
value = module.redis.primary_endpoint_address
29+
}
30+
31+
output "reader_endpoint_address" {
32+
description = "Address of the endpoint for the reader node in the replication group."
33+
value = module.redis.reader_endpoint_address
34+
}
35+
36+
output "tags" {
37+
description = "The tags"
38+
value = module.redis.tags
439
}

examples/basic/sample-backend.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# terraform {
22
# backend "s3" {
33
# bucket = "my-bucket-tfstate"
4-
# key = "example-terraform-aws-MOD_SHORTNAME-basic"
4+
# key = "example-terraform-aws-elasticache-redis-standalone-basic"
55
# profile = "my-profile"
66
# region = "us-east-1"
77
# dynamodb_table = "terraform-lock"

examples/basic/tags.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ variable "environment" {
1313
variable "product" {
1414
description = "Tag used to group resources according to application"
1515

16-
default = "example-tf-MOD_SHORTNAME-basic"
16+
default = "ex-tf-redis-basic"
1717

1818
validation {
1919
condition = can(regex("[a-z\\-]+", var.product))
@@ -24,7 +24,7 @@ variable "product" {
2424
variable "repo" {
2525
description = "Tag used to point to the repo using this module"
2626

27-
default = "https://github.com/pbs/terraform-MOD_NAME.git"
27+
default = "https://github.com/pbs/terraform-elasticache-redis-standalone-module.git"
2828

2929
validation {
3030
condition = can(regex("(?:git|ssh|https?|git@[-\\w.]+):(\\/\\/)?(.*?)(\\.git)(\\/?|\\#[-\\d\\w._]+?)$", var.repo))

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
github.com/googleapis/go-type-adapters v1.0.0 h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA=
2+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
3+
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=

locals.tf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
locals {
2-
name = var.name != null ? var.name : var.product
2+
name = var.name != null ? var.name : var.product
3+
security_group_ids = var.security_group_ids != null ? var.security_group_ids : [aws_security_group.sg.id]
4+
subnet_group_name = var.subnet_group_name != null ? var.subnet_group_name : aws_elasticache_subnet_group.subnet_group.id
5+
vpc_id = var.vpc_id != null ? var.vpc_id : data.aws_vpc.vpc[0].id
6+
subnets = var.subnets != null ? var.subnets : data.aws_subnets.private_subnets[0].ids
7+
parameter_group_name = var.parameter_group_name != null ? var.parameter_group_name : aws_elasticache_parameter_group.parameter_group.id
8+
9+
vpc_data_lookup_tags = var.vpc_data_lookup_tags != null ? var.vpc_data_lookup_tags : {
10+
"environment" : var.environment
11+
}
12+
13+
subnet_data_lookup_filters = var.subnet_data_lookup_filters != null ? var.subnet_data_lookup_filters : {
14+
"vpc-id" = [local.vpc_id]
15+
"tag:Name" = ["*-private-*"]
16+
}
17+
18+
replication_group_description = var.replication_group_description != null ? var.replication_group_description : "Replication group for ${local.name}"
19+
replication_group_id = var.replication_group_id != null ? var.replication_group_id : local.name
20+
21+
sg_name = var.use_prefix ? null : var.sg_name != null ? var.sg_name : local.name
22+
sg_name_prefix = var.use_prefix ? var.sg_name != null ? var.sg_name : local.name : null
23+
24+
automatic_failover_enabled = var.automatic_failover_enabled != null ? var.automatic_failover_enabled : var.nodes >= 2
25+
26+
engine = "redis"
27+
328
creator = "terraform"
429

530
tags = merge(

main.tf

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
# Resources go here!
1+
resource "aws_elasticache_replication_group" "replication_group" {
2+
description = local.replication_group_description
3+
replication_group_id = substr(local.replication_group_id, 0, 40) # Max length is 40
4+
5+
apply_immediately = var.apply_immediately
6+
at_rest_encryption_enabled = var.at_rest_encryption_enabled
7+
auth_token = var.auth_token
8+
auto_minor_version_upgrade = var.auto_minor_version_upgrade
9+
automatic_failover_enabled = local.automatic_failover_enabled
10+
data_tiering_enabled = var.data_tiering_enabled
11+
engine = local.engine
12+
engine_version = var.engine_version
13+
final_snapshot_identifier = var.final_snapshot_identifier
14+
global_replication_group_id = var.global_replication_group_id
15+
kms_key_id = var.kms_key_id
16+
maintenance_window = var.maintenance_window
17+
multi_az_enabled = var.multi_az_enabled
18+
node_type = var.node_type
19+
notification_topic_arn = var.notification_topic_arn
20+
num_cache_clusters = var.nodes
21+
parameter_group_name = local.parameter_group_name
22+
port = var.port
23+
preferred_cache_cluster_azs = var.preferred_cache_cluster_azs
24+
security_group_ids = local.security_group_ids
25+
snapshot_arns = var.snapshot_arns
26+
snapshot_retention_limit = var.snapshot_retention_limit
27+
snapshot_window = var.snapshot_window
28+
subnet_group_name = local.subnet_group_name
29+
transit_encryption_enabled = var.transit_encryption_enabled
30+
user_group_ids = var.user_group_ids
31+
32+
tags = local.tags
33+
}

0 commit comments

Comments
 (0)