-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
67 lines (56 loc) · 1.84 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**************************************************************************
# Overview:
This module is an abstraction of the subnet group and security group required to provision and restrict access to elasticache clusters (redis & memcached)
Inputs:
Required:
cluster_name - name of cluster. Should contain only lower case letters and '-'
security_group_ids - comma seperated list of security group ids which are allowed to access this Elasticache cluster
subnet_ids - comma seperated list of subnet ids available to this Elasticache cluster
vpc_id - VPC id for this Elasticache cluster
port - port to run on
Outputs:
subnet_group_name - name of the subnet group created
security_group_id - security group id created
**************************************************************************/
#
# Module Inputs
#
variable "cluster_name" {}
variable "subnet_ids" {}
variable "vpc_id" {}
variable "port" {}
variable "security_group_ids" {}
#
# Setup
#
resource "aws_elasticache_subnet_group" "elasticache-subnet-group" {
name = "${var.cluster_name}-elasticache-subnet-group"
description = "${var.cluster_name} elasticache subnet group"
subnet_ids = ["${split(",", "${var.subnet_ids}")}"]
}
resource "aws_security_group" "elasticache-traffic" {
name = "${var.cluster_name}-traffic"
vpc_id = "${var.vpc_id}"
description = "elasticache cluster security group"
ingress {
from_port = "${var.port}"
to_port = "${var.port}"
protocol = "tcp"
security_groups = ["${split(",", "${var.security_group_ids}")}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
#
# Module Outputs
#
output "subnet_group_name" {
value = "${aws_elasticache_subnet_group.elasticache-subnet-group.name}"
}
output "security_group_id" {
value = "${aws_security_group.elasticache-traffic.id}"
}