Skip to content

Commit 22be77b

Browse files
committed
[breaking] Fix aws-redis-node security groups
1 parent 20df8cf commit 22be77b

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

aws-redis-node/README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ parameters.
88

99
| Name | Description | Type | Default | Required |
1010
|------|-------------|:----:|:-----:|:-----:|
11-
| apply\_immediately | Whether changes should be applied immediately or during the next maintenance window. | string | `"true"` | no |
12-
| availability\_zone | Availability zone in which this instance should run. | string | n/a | yes |
13-
| engine\_version | The version of Redis to run. See [supported versions](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/supported-engine-versions.html) | string | `"4.0.10"` | no |
11+
| apply\_immediately | Whether changes should be applied immediately or during the next maintenance window. | bool | `true` | no |
12+
| availability\_zone | Availability zone in which this instance should run. | string | `null` | no |
13+
| engine\_version | The version of Redis to run. See [supported versions](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/supported-engine-versions.html) | string | `"5.0.5"` | no |
1414
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
1515
| ingress\_security\_group\_ids | Source security groups which should be able to contact this instance. | list | n/a | yes |
1616
| instance\_type | The type of instance to run. See [supported node types](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/CacheNodes.SupportedTypes.html) | string | `"cache.m4.large"` | no |
1717
| owner | Owner for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
18-
| parameter\_group\_name | | string | `"default.redis3.2"` | no |
19-
| port | | string | `"6379"` | no |
18+
| parameter\_group\_name | | string | `"default.redis5.0"` | no |
19+
| port | Port to host Redis on. | number | `6379` | no |
2020
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
2121
| resource\_name | If not set, name will be [var.project]-[var.env]-[var.name]. | string | `""` | no |
22-
| service | Service for tagging and naming. See [doc](../README.md#consistent-tagging) | string | `"redis"` | no |
22+
| service | Service for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
2323
| subnets | List of subnets to which this EC instance should be attached. They should probably be private. | list | n/a | yes |
24+
| vpc\_id | VPC where the cache will be deployed. | string | n/a | yes |
2425

2526
## Outputs
2627

aws-redis-node/main.tf

+22-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ locals {
1111
}
1212
}
1313

14+
module "sg" {
15+
source = "terraform-aws-modules/security-group/aws"
16+
version = "3.1.0"
17+
name = local.name
18+
description = "Allow traffic to Redis."
19+
vpc_id = var.vpc_id
20+
tags = local.tags
21+
22+
ingress_with_source_security_group_id = [
23+
for sg in var.ingress_security_group_ids : {
24+
from_port = var.port
25+
to_port = var.port
26+
protocol = "tcp"
27+
description = "Redis port"
28+
source_security_group_id = sg
29+
}
30+
]
31+
32+
egress_rules = ["all-all"]
33+
}
34+
1435
resource "aws_elasticache_subnet_group" "default" {
1536
name = "${var.resource_name != "" ? var.resource_name : local.name}"
1637
subnet_ids = "${var.subnets}"
@@ -25,7 +46,7 @@ resource "aws_elasticache_cluster" "default" {
2546
num_cache_nodes = 1
2647
parameter_group_name = "${var.parameter_group_name}"
2748
subnet_group_name = "${aws_elasticache_subnet_group.default.name}"
28-
security_group_ids = "${var.ingress_security_group_ids}"
49+
security_group_ids = [module.sg.this_security_group_id]
2950
apply_immediately = "${var.apply_immediately}"
3051
availability_zone = "${var.availability_zone}"
3152
tags = "${local.tags}"

aws-redis-node/variables.tf

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,66 @@
11
variable "project" {
2-
type = "string"
2+
type = string
33
description = "Project for tagging and naming. See [doc](../README.md#consistent-tagging)"
44
}
55

66
variable "env" {
7-
type = "string"
7+
type = string
88
description = "Env for tagging and naming. See [doc](../README.md#consistent-tagging)."
99
}
1010

11+
variable "service" {
12+
type = string
13+
description = "Service for tagging and naming. See [doc](../README.md#consistent-tagging)"
14+
default = "redis"
15+
}
16+
1117
variable "owner" {
12-
type = "string"
18+
type = string
1319
description = "Owner for tagging and naming. See [doc](../README.md#consistent-tagging)."
1420
}
1521

1622
variable "subnets" {
17-
type = "list"
23+
type = list(string)
1824
description = "List of subnets to which this EC instance should be attached. They should probably be private."
1925
}
2026

2127
variable "availability_zone" {
22-
type = "string"
28+
type = string
2329
description = "Availability zone in which this instance should run."
2430
default = null
2531
}
2632

2733
variable "ingress_security_group_ids" {
28-
type = "list"
34+
type = list(string)
2935
description = "Source security groups which should be able to contact this instance."
3036
}
3137

32-
variable "service" {
33-
type = "string"
34-
description = "Service for tagging and naming. See [doc](../README.md#consistent-tagging)"
35-
default = "redis"
36-
}
37-
3838
variable "port" {
39-
type = "string"
40-
default = "6379"
39+
type = number
40+
description = "Port to host Redis on."
41+
default = 6379
4142
}
4243

4344
variable "instance_type" {
44-
type = "string"
45+
type = string
4546
description = "The type of instance to run. See [supported node types](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/CacheNodes.SupportedTypes.html)"
4647
default = "cache.m5.large"
4748
}
4849

4950
variable "parameter_group_name" {
50-
default = "default.redis5.0"
51+
type = string
52+
description = "Parameter group to use for this Redis cache."
53+
default = "default.redis5.0"
5154
}
5255

5356
variable "engine_version" {
54-
type = "string"
57+
type = string
5558
description = "The version of Redis to run. See [supported versions](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/supported-engine-versions.html)"
5659
default = "5.0.5"
5760
}
5861

5962
variable "apply_immediately" {
60-
type = "string"
63+
type = bool
6164
description = "Whether changes should be applied immediately or during the next maintenance window."
6265
default = true
6366
}
@@ -66,6 +69,11 @@ variable "apply_immediately" {
6669
# only 20 characters long. Use it only if you get that error.
6770
variable "resource_name" {
6871
description = "If not set, name will be [var.project]-[var.env]-[var.name]."
69-
type = "string"
72+
type = string
7073
default = ""
7174
}
75+
76+
variable "vpc_id" {
77+
type = string
78+
description = "VPC where the cache will be deployed."
79+
}

0 commit comments

Comments
 (0)