Skip to content

Commit c3a08a9

Browse files
committed
add redis configuration
1 parent 8343438 commit c3a08a9

File tree

7 files changed

+517
-1
lines changed

7 files changed

+517
-1
lines changed

Makefile

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
ifneq (,)
2+
.error This Makefile requires GNU Make.
3+
endif
4+
5+
.PHONY: gen _gen-main _gen-examples _update-tf-docs
6+
7+
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
8+
TF_EXAMPLES = $(sort $(dir $(wildcard $(CURRENT_DIR)examples/*/)))
9+
TF_DOCS_VERSION = 0.6.0
10+
11+
# Adjust your delimiter here or overwrite via make arguments
12+
DELIM_START = <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13+
DELIM_CLOSE = <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
14+
15+
gen: _update-tf-docs
16+
@echo "################################################################################"
17+
@echo "# Terraform-docs generate"
18+
@echo "################################################################################"
19+
@$(MAKE) --no-print-directory _gen-main
20+
@$(MAKE) --no-print-directory _gen-examples
21+
22+
_gen-main:
23+
@echo "------------------------------------------------------------"
24+
@echo "# Main module"
25+
@echo "------------------------------------------------------------"
26+
@if docker run --rm \
27+
-v $(CURRENT_DIR):/data \
28+
-e DELIM_START='$(DELIM_START)' \
29+
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
30+
cytopia/terraform-docs:$(TF_DOCS_VERSION) \
31+
terraform-docs-replace-012 --sort-inputs-by-required --with-aggregate-type-defaults md README.md; then \
32+
echo "OK"; \
33+
else \
34+
echo "Failed"; \
35+
exit 1; \
36+
fi
37+
38+
_gen-examples:
39+
@$(foreach example,\
40+
$(TF_EXAMPLES),\
41+
DOCKER_PATH="examples/$(notdir $(patsubst %/,%,$(example)))"; \
42+
echo "------------------------------------------------------------"; \
43+
echo "# $${DOCKER_PATH}"; \
44+
echo "------------------------------------------------------------"; \
45+
if docker run --rm \
46+
-v $(CURRENT_DIR):/data \
47+
-e DELIM_START='$(DELIM_START)' \
48+
-e DELIM_CLOSE='$(DELIM_CLOSE)' \
49+
cytopia/terraform-docs:$(TF_DOCS_VERSION) \
50+
terraform-docs-replace-012 --sort-inputs-by-required --with-aggregate-type-defaults md $${DOCKER_PATH}/README.md; then \
51+
echo "OK"; \
52+
else \
53+
echo "Failed"; \
54+
exit 1; \
55+
fi; \
56+
)
57+
58+
_update-tf-docs:
59+
docker pull cytopia/terraform-docs:$(TF_DOCS_VERSION)

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,54 @@ Module is to be used with Terraform > 0.12.
3535

3636
Module managed by [Marcin Cuber](https://github.com/marcincuber) [linkedin](https://www.linkedin.com/in/marcincuber/).
3737

38+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
39+
## Inputs
40+
41+
| Name | Description | Type | Default | Required |
42+
|------|-------------|:----:|:-----:|:-----:|
43+
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | string | n/a | yes |
44+
| node\_type | The compute and memory capacity of the nodes in the node group. | string | n/a | yes |
45+
| number\_cache\_clusters | The number of cache clusters (primary and replicas) this replication group will have. | string | n/a | yes |
46+
| subnet\_ids | List of VPC Subnet IDs for the cache subnet group. | list(string) | n/a | yes |
47+
| vpc\_id | VPC Id to associate with Redis ElastiCache. | string | n/a | yes |
48+
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. | string | `"false"` | no |
49+
| at\_rest\_encryption\_enabled | Whether to enable encryption at rest. | string | `"true"` | no |
50+
| auth\_token | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | string | `""` | no |
51+
| auto\_minor\_version\_upgrade | | string | `"true"` | no |
52+
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | string | `"true"` | no |
53+
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
54+
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.0"` | no |
55+
| family | The family of the ElastiCache parameter group. | string | `"redis5.0"` | no |
56+
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | list(string) | `[]` | no |
57+
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | string | `""` | no |
58+
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | string | `""` | no |
59+
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `[]` | no |
60+
| port | The port number on which each of the cache nodes will accept connections. | string | `"6379"` | no |
61+
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | string | `"30"` | no |
62+
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
63+
| source\_security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
64+
| tags | A mapping of tags to assign to all resources. | map(string) | `{}` | no |
65+
| transit\_encryption\_enabled | Whether to enable encryption in transit. | string | `"true"` | no |
66+
67+
## Outputs
68+
69+
| Name | Description |
70+
|------|-------------|
71+
| elasticache\_parameter\_group\_id | The ElastiCache parameter group name. |
72+
| elasticache\_replication\_group\_id | The ID of the ElastiCache Replication Group. |
73+
| elasticache\_replication\_group\_member\_clusters | The identifiers of all the nodes that are part of this replication group. |
74+
| elasticache\_replication\_group\_primary\_endpoint\_address | The address of the endpoint for the primary node in the replication group. |
75+
| security\_group\_arn | The ARN of the Redis ElastiCache security group. |
76+
| security\_group\_description | The description of the Redis ElastiCache security group. |
77+
| security\_group\_egress | The egress rules of the Redis ElastiCache security group. |
78+
| security\_group\_id | The ID of the Redis ElastiCache security group. |
79+
| security\_group\_ingress | The ingress rules of the Redis ElastiCache security group. |
80+
| security\_group\_name | The name of the Redis ElastiCache security group. |
81+
| security\_group\_owner\_id | The owner ID of the Redis ElastiCache security group. |
82+
| security\_group\_vpc\_id | The VPC ID of the Redis ElastiCache security group. |
83+
84+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
85+
3886
## License
3987

40-
See LICENSE for full details.
88+
See LICENSE for full details.

examples/core/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Example deployment flow
2+
3+
```bash
4+
terraform init
5+
terraform validate
6+
terraform plan
7+
terraform apply --auto-approve
8+
```
9+
10+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
11+
## Inputs
12+
13+
| Name | Description | Type | Default | Required |
14+
|------|-------------|:----:|:-----:|:-----:|
15+
| name\_prefix | The replication group identifier. This parameter is stored as a lowercase string. | string | n/a | yes |
16+
| node\_type | The compute and memory capacity of the nodes in the node group. | string | n/a | yes |
17+
| number\_cache\_clusters | The number of cache clusters (primary and replicas) this replication group will have. | string | n/a | yes |
18+
| subnet\_ids | List of VPC Subnet IDs for the cache subnet group. | list(string) | n/a | yes |
19+
| vpc\_id | VPC Id to associate with Redis ElastiCache. | string | n/a | yes |
20+
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. | string | `"false"` | no |
21+
| at\_rest\_encryption\_enabled | Whether to enable encryption at rest. | string | `"true"` | no |
22+
| auth\_token | The password used to access a password protected server. Can be specified only if `transit_encryption_enabled = true`. | string | `""` | no |
23+
| auto\_minor\_version\_upgrade | | string | `"true"` | no |
24+
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | string | `"true"` | no |
25+
| description | The description of the all resources. | string | `"Managed by Terraform"` | no |
26+
| engine\_version | The version number of the cache engine to be used for the cache clusters in this replication group. | string | `"5.0.0"` | no |
27+
| family | The family of the ElastiCache parameter group. | string | `"redis5.0"` | no |
28+
| ingress\_cidr\_blocks | List of Ingress CIDR blocks. | list(string) | `[]` | no |
29+
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if `at_rest_encryption_enabled = true` | string | `""` | no |
30+
| maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. | string | `""` | no |
31+
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `[]` | no |
32+
| port | The port number on which each of the cache nodes will accept connections. | string | `"6379"` | no |
33+
| snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. | string | `"30"` | no |
34+
| snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. | string | `""` | no |
35+
| source\_security\_group\_ids | List of Security Groups. | list(string) | `[]` | no |
36+
| tags | A mapping of tags to assign to all resources. | map(string) | `{}` | no |
37+
| transit\_encryption\_enabled | Whether to enable encryption in transit. | string | `"true"` | no |
38+
39+
## Outputs
40+
41+
| Name | Description |
42+
|------|-------------|
43+
| elasticache\_parameter\_group\_id | The ElastiCache parameter group name. |
44+
| elasticache\_replication\_group\_id | The ID of the ElastiCache Replication Group. |
45+
| elasticache\_replication\_group\_member\_clusters | The identifiers of all the nodes that are part of this replication group. |
46+
| elasticache\_replication\_group\_primary\_endpoint\_address | The address of the endpoint for the primary node in the replication group. |
47+
| security\_group\_arn | The ARN of the Redis ElastiCache security group. |
48+
| security\_group\_description | The description of the Redis ElastiCache security group. |
49+
| security\_group\_egress | The egress rules of the Redis ElastiCache security group. |
50+
| security\_group\_id | The ID of the Redis ElastiCache security group. |
51+
| security\_group\_ingress | The ingress rules of the Redis ElastiCache security group. |
52+
| security\_group\_name | The name of the Redis ElastiCache security group. |
53+
| security\_group\_owner\_id | The owner ID of the Redis ElastiCache security group. |
54+
| security\_group\_vpc\_id | The VPC ID of the Redis ElastiCache security group. |
55+
56+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/core/main.tf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
#####
6+
# VPC and subnets
7+
#####
8+
module "vpc" {
9+
source = "terraform-aws-modules/vpc/aws"
10+
version = "2.21.0"
11+
12+
name = "simple-vpc"
13+
14+
cidr = "10.0.0.0/16"
15+
16+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
17+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
18+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
19+
20+
enable_nat_gateway = false
21+
22+
tags = {
23+
Environment = "test"
24+
}
25+
}
26+
27+
#####
28+
# Elasticache Redis
29+
#####
30+
module "redis" {
31+
source = "../../"
32+
33+
name_prefix = "core-example-redis"
34+
number_cache_clusters = 2
35+
node_type = "cache.t3.small"
36+
37+
engine_version = "5.0.6"
38+
port = 6379
39+
maintenance_window = "mon:03:00-mon:04:00"
40+
snapshot_window = "04:00-06:00"
41+
snapshot_retention_limit = 7
42+
43+
automatic_failover_enabled = true
44+
45+
at_rest_encryption_enabled = true
46+
transit_encryption_enabled = true
47+
auth_token = "1234567890asdfghjkl"
48+
49+
apply_immediately = true
50+
family = "redis5.0"
51+
description = "Test elasticache redis."
52+
53+
subnet_ids = module.vpc.private_subnets
54+
vpc_id = module.vpc.vpc_id
55+
56+
ingress_cidr_blocks = ["0.0.0.0/0"]
57+
58+
parameter = [
59+
{
60+
name = "repl-backlog-size"
61+
value = "16384"
62+
}
63+
]
64+
65+
tags = {
66+
Project = "Test"
67+
}
68+
}

main.tf

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
resource "aws_elasticache_replication_group" "redis" {
2+
engine = "redis"
3+
4+
parameter_group_name = aws_elasticache_parameter_group.redis.name
5+
subnet_group_name = aws_elasticache_subnet_group.redis.name
6+
security_group_ids = [aws_security_group.redis.id]
7+
8+
replication_group_id = var.name_prefix
9+
number_cache_clusters = var.number_cache_clusters
10+
node_type = var.node_type
11+
12+
engine_version = var.engine_version
13+
port = var.port
14+
15+
maintenance_window = var.maintenance_window
16+
snapshot_window = var.snapshot_window
17+
snapshot_retention_limit = var.snapshot_retention_limit
18+
automatic_failover_enabled = var.automatic_failover_enabled
19+
auto_minor_version_upgrade = var.auto_minor_version_upgrade
20+
21+
at_rest_encryption_enabled = var.at_rest_encryption_enabled
22+
transit_encryption_enabled = var.transit_encryption_enabled
23+
auth_token = var.auth_token != "" ? var.auth_token : null
24+
kms_key_id = var.kms_key_id
25+
26+
apply_immediately = var.apply_immediately
27+
28+
replication_group_description = var.description
29+
30+
tags = merge(
31+
{
32+
"Name" = var.name_prefix
33+
},
34+
var.tags,
35+
)
36+
}
37+
38+
resource "aws_elasticache_parameter_group" "redis" {
39+
name = var.name_prefix
40+
family = var.family
41+
description = var.description
42+
43+
dynamic "parameter" {
44+
for_each = var.parameter
45+
content {
46+
name = parameter.value.name
47+
value = parameter.value.value
48+
}
49+
}
50+
}
51+
52+
resource "aws_elasticache_subnet_group" "redis" {
53+
name = var.name_prefix
54+
subnet_ids = var.subnet_ids
55+
description = var.description
56+
}
57+
58+
resource "aws_security_group" "redis" {
59+
name_prefix = "${var.name_prefix}-"
60+
vpc_id = var.vpc_id
61+
62+
tags = merge(
63+
{
64+
"Name" = "${var.name_prefix}"
65+
},
66+
var.tags
67+
)
68+
}
69+
70+
resource "aws_security_group_rule" "redis_ingress_cidr_blocks" {
71+
count = length(var.ingress_cidr_blocks) != 0 ? 1 : 0
72+
73+
type = "ingress"
74+
from_port = var.port
75+
to_port = var.port
76+
protocol = "tcp"
77+
cidr_blocks = var.ingress_cidr_blocks
78+
security_group_id = aws_security_group.redis.id
79+
}
80+
81+
resource "aws_security_group_rule" "redis_egress" {
82+
type = "egress"
83+
from_port = 0
84+
to_port = 0
85+
protocol = "-1"
86+
cidr_blocks = ["0.0.0.0/0"]
87+
security_group_id = aws_security_group.redis.id
88+
}
89+

outputs.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
output "elasticache_replication_group_id" {
2+
value = aws_elasticache_replication_group.redis.id
3+
description = "The ID of the ElastiCache Replication Group."
4+
}
5+
6+
output "elasticache_replication_group_primary_endpoint_address" {
7+
value = aws_elasticache_replication_group.redis.primary_endpoint_address
8+
description = "The address of the endpoint for the primary node in the replication group."
9+
}
10+
11+
output "elasticache_replication_group_member_clusters" {
12+
value = aws_elasticache_replication_group.redis.member_clusters
13+
description = "The identifiers of all the nodes that are part of this replication group."
14+
}
15+
16+
output "elasticache_parameter_group_id" {
17+
value = aws_elasticache_parameter_group.redis.id
18+
description = "The ElastiCache parameter group name."
19+
}
20+
21+
output "security_group_id" {
22+
value = aws_security_group.redis.id
23+
description = "The ID of the Redis ElastiCache security group."
24+
}
25+
26+
output "security_group_arn" {
27+
value = aws_security_group.redis.arn
28+
description = "The ARN of the Redis ElastiCache security group."
29+
}
30+
31+
output "security_group_vpc_id" {
32+
value = aws_security_group.redis.vpc_id
33+
description = "The VPC ID of the Redis ElastiCache security group."
34+
}
35+
36+
output "security_group_owner_id" {
37+
value = aws_security_group.redis.owner_id
38+
description = "The owner ID of the Redis ElastiCache security group."
39+
}
40+
41+
output "security_group_name" {
42+
value = aws_security_group.redis.name
43+
description = "The name of the Redis ElastiCache security group."
44+
}
45+
46+
output "security_group_description" {
47+
value = aws_security_group.redis.description
48+
description = "The description of the Redis ElastiCache security group."
49+
}
50+
51+
output "security_group_ingress" {
52+
value = aws_security_group.redis.ingress
53+
description = "The ingress rules of the Redis ElastiCache security group."
54+
}
55+
56+
output "security_group_egress" {
57+
value = aws_security_group.redis.egress
58+
description = "The egress rules of the Redis ElastiCache security group."
59+
}
60+

0 commit comments

Comments
 (0)