-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
191 lines (176 loc) · 5.3 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
locals {
vpc_cidr = "10.0.0.0/16"
}
provider "aws" {
version = "~> 2.8"
region = "eu-west-1"
}
###########
### VPC ###
###########
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.15.0"
name = "vpc-ta"
cidr = local.vpc_cidr
azs = ["eu-west-1a"]
# private_subnets = ["10.0.2.0/24"]
public_subnets = ["10.0.1.0/24"]
enable_dns_hostnames = true
database_subnet_assign_ipv6_address_on_creation = false
elasticache_subnet_assign_ipv6_address_on_creation = false
enable_classiclink = false
enable_classiclink_dns_support = false
intra_subnet_assign_ipv6_address_on_creation = false
private_subnet_assign_ipv6_address_on_creation = false
public_subnet_assign_ipv6_address_on_creation = false
redshift_subnet_assign_ipv6_address_on_creation = false
}
##############
### QUEUES ###
##############
module "sqs-input" {
source = "terraform-aws-modules/sqs/aws"
version = "2.0.0"
name = "ta-input-queue"
# fifo_queue = true
# visibility_timeout_seconds = 2
tags = {
Name = "ta-input-queue"
Flow = "input"
}
}
module "sqs-output" {
source = "terraform-aws-modules/sqs/aws"
version = "2.0.0"
name = "ta-output-queue"
# fifo_queue = true
# visibility_timeout_seconds = 2
tags = {
Name = "ta-output-queue"
Flow = "output"
}
}
#################
### INSTANCES ###
#################
module "instance-echo-system" {
instance_count = 2
source = "terraform-aws-modules/ec2-instance/aws"
version = "2.8.0"
ami = "ami-06358f49b5839867c" # Ubuntu bionic id
instance_type = "t2.micro"
name = "ta-worker"
subnet_id = module.vpc.public_subnets[0]
vpc_security_group_ids = [
module.allow-public-http-security-group.this_security_group_id,
module.allow-public-https-security-group.this_security_group_id,
module.allow-public-ssh-security-group.this_security_group_id,
module.allow-public-icmp-security-group.this_security_group_id
]
associate_public_ip_address = true
key_name = "key-ta"
root_block_device = [
{
device_name = "/dev/sda1"
volume_type = "gp2"
volume_size = 8
encrypted = true
},
]
tags = {
Function = "ta-worker"
}
}
module "instance-frontend" {
instance_count = 1
source = "terraform-aws-modules/ec2-instance/aws"
version = "2.8.0"
ami = "ami-06358f49b5839867c" # Ubuntu bionic id
instance_type = "t2.micro"
name = "ta-web-server"
subnet_id = module.vpc.public_subnets[0]
vpc_security_group_ids = [
module.allow-public-http-security-group.this_security_group_id,
module.allow-public-https-security-group.this_security_group_id,
module.allow-public-ssh-security-group.this_security_group_id,
module.allow-public-icmp-security-group.this_security_group_id
]
associate_public_ip_address = true
key_name = "key-ta"
root_block_device = [
{
device_name = "/dev/sda1"
volume_type = "gp2"
volume_size = 8
encrypted = true
},
]
tags = {
Function = "ta-web-server"
}
}
##################
### S3 BUCKETS ###
##################
resource "aws_s3_bucket" "ta" {
force_destroy = true
bucket = "ta-bucket-josemarinas"
region = "eu-west-1"
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["PUT", "POST", "GET", "DELETE"]
allowed_origins = ["*"]
max_age_seconds = 3000
}
}
#######################
### SECURITY GROUPS ###
#######################
module "allow-public-http-security-group" {
source = "terraform-aws-modules/security-group/aws"
version = "3.1.0"
name = "allow-public-http-security-group"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp"]
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
module "allow-public-https-security-group" {
source = "terraform-aws-modules/security-group/aws"
version = "3.1.0"
name = "allow-public-https-security-group"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["https-443-tcp"]
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
module "allow-public-ssh-security-group" {
source = "terraform-aws-modules/security-group/aws"
version = "3.1.0"
name = "allow-public-ssh-security-group"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["ssh-tcp"]
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
module "allow-public-icmp-security-group" {
source = "terraform-aws-modules/security-group/aws"
version = "3.1.0"
name = "allow-public-icmp-security-group"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["all-icmp"]
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
###############
### SSH KEY ###
###############
resource "aws_key_pair" "ta" {
key_name = "key-ta"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC1AH8ri8JB7kUFQGGmR3YQI9W9Pbm8My/upb8JWlawgq5E5CGf57KhKSOKKVs+4KcWkRnpc/5F6K/cr3XPAKVo5dmpEMXnrGWFKiqrUK1j4ZMBt69O7jvS0BJ7lTWyM5ztpPbQupVRKt8Zg3D731/qWMHlqed84cxUCBXUP2rfMyNM9D/PJIcF7+Q2VyES9s67ejoS7EyS2T/KdLUnFDRYkgs2WtML/lO/BLRShurvQdrMuvGBk8o26zErVusSx4BMfm4puPU69hb1cPDAHFOlXP/xPTF+HDbctNGK3+IK9f3B02Jz+gCILXCEThVCamp4fgyEWyPiIRjOkN92lsER jose@jose-MSI"
}