Skip to content

Commit dd873e9

Browse files
committed
Fix security group
1 parent f7050b4 commit dd873e9

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

main.tf

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ resource "aws_security_group" "default" {
1818
vpc_id = "${var.vpc_id}"
1919
name = "${module.label.id}"
2020

21-
ingress {
22-
from_port = "${var.port}" # Redis
23-
to_port = "${var.port}"
24-
protocol = "tcp"
25-
security_groups = ["${var.security_groups}"]
26-
}
27-
2821
egress {
2922
from_port = 0
3023
to_port = 0
@@ -34,6 +27,26 @@ resource "aws_security_group" "default" {
3427

3528
tags = "${module.label.tags}"
3629
}
30+
/*
31+
resource "aws_security_group_rule" "redis_sg" {
32+
count = "${var.enabled == "true" && length(var.security_group) > 0 ? 1 : 0}"
33+
type = "ingress"
34+
from_port = "${var.port}"
35+
to_port = "${var.port}"
36+
protocol = "tcp"
37+
source_security_group_id = "${var.security_group}"
38+
security_group_id = "${aws_security_group.default.id}"
39+
}
40+
/**/
41+
resource "aws_security_group_rule" "redis_cidr" {
42+
count = "${var.enabled == "true" && length(var.cidr_blocks) > 0 ? 1 : 0}"
43+
type = "ingress"
44+
from_port = "${var.port}"
45+
to_port = "${var.port}"
46+
protocol = "tcp"
47+
cidr_blocks = ["${var.cidr_blocks}"]
48+
security_group_id = "${aws_security_group.default.id}"
49+
}
3750

3851
resource "aws_elasticache_subnet_group" "default" {
3952
count = "${var.enabled == "true" ? 1 : 0}"

variables.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ variable "name" {
1818
description = "Name"
1919
}
2020

21-
variable "security_groups" {
22-
type = "list"
23-
default = []
24-
description = "AWS security group ids"
21+
variable "security_group" {
22+
description = "AWS security group id"
23+
default = ""
2524
}
2625

2726
variable "vpc_id" {
@@ -34,7 +33,10 @@ variable "subnets" {
3433
description = "AWS subnet ids"
3534
default = []
3635
}
37-
36+
variable "cidr_blocks" {
37+
description = "CIDR blocks to allow accress from"
38+
default = ""
39+
}
3840
variable "maintenance_window" {
3941
default = "wed:03:00-wed:04:00"
4042
description = "Maintenance window"

0 commit comments

Comments
 (0)