-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtesting-environment.tf
151 lines (130 loc) · 3.82 KB
/
testing-environment.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
/*
testing-environment
Provides an environment for testing potential goflow releases.
Builds a server and vpc config but at this time does not run post-provisioning (setup_scripts).
Requires:
env vars:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_KEY
Outputs:
- Public DNS endpoint
- Instance ID
*/
provider "aws" {
region = "ap-southeast-2"
}
terraform {
backend "local" {
path = "..\\..\\..\\..\\..\\..\\..\\Temp\\terraform.tfstate"
}
}
variable "az" {
default = "ap-southeast-2a"
}
variable "vpc_config" {
type = "map",
default = {
network_block = "10.10.0.0/16",
name = "goflow-test-vpc",
}
}
variable "trusted-ips" {
type = "list"
default = ["124.171.205.1/32"]
}
variable "public_network_config" {
type = "map",
default = {
network = "10.10.10.0/24",
name = "goflow-test-subnet",
}
}
data "aws_route53_zone" "selected" {
name = "spaghettsucks.com."
}
resource "aws_route53_record" "goflow-test" {
name = "goflow-test.${data.aws_route53_zone.selected.name}"
type = "CNAME"
ttl = "300"
zone_id = "${data.aws_route53_zone.selected.zone_id}"
records = ["${aws_instance.goflow-test-instance.public_dns}"]
}
resource "aws_key_pair" "kp" {
key_name = "home-key"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAk9wAsRVSw0dWgcukpiamRe9KwWe5Itr1mKMXWcQZw2M6XwY9w67geUavuLOeia/GgcUax/fWa8Z2hwL3S8q2TuyBvpaWvKLfSWPm+U0zsNE2rFGa2Iw/rQxZUEL1N8njoPN+LURr47iZNATbtSRIDyUlpGF5ejUsDHRpvGD4VJTgYXP6scdgazqAFsex9pElvu1dLHFkzAOuHYEnFTkcPHTSTtgujoz82iFa0GfpTQ0wcI63/8dFRHKN+BEgWgdx35xHzQ9QLXwvVnEVWs5T6bg5Wvjd5sF6AdCcdfiQuzZpCGr/o6KjJAoE8yvBzzo1ycN8ulo8THlMshzhSqrn1Q== rsa-key-20180112"
}
resource "aws_instance" "goflow-test-instance" {
ami = "ami-07a3bd4944eb120a0"
instance_type = "t2.micro"
vpc_security_group_ids = ["${aws_vpc.main_vpc.default_security_group_id}"]
key_name = "${aws_key_pair.kp.key_name}"
subnet_id = "${aws_subnet.public_subnet.id}"
tags {
Name = "goflow-test-pgsql-instance"
}
}
resource "aws_vpc" "main_vpc" {
cidr_block = "${var.vpc_config["network_block"]}"
enable_dns_hostnames = true
tags {
Name = "${var.vpc_config["name"]}"
}
}
resource "aws_subnet" "public_subnet" {
vpc_id = "${aws_vpc.main_vpc.id}"
cidr_block = "${var.public_network_config["network"]}"
map_public_ip_on_launch = true
availability_zone = "${var.az}"
tags {
Name = "${var.public_network_config["name"]}"
}
}
/*
Internet Gateway
Provides inbound and outbound access to the internet
*/
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.main_vpc.id}"
tags {
Name = "${var.vpc_config["name"]}_igw"
}
}
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.main_vpc.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
/*
Security group rule
Configure a rule to allow access within a security group
*/
resource "aws_security_group_rule" "allow_all_from_trusted" {
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = "${var.trusted-ips}"
security_group_id = "${aws_vpc.main_vpc.default_security_group_id}"
}
resource "aws_security_group_rule" "allow_pgsql_from_any" {
type = "ingress"
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_vpc.main_vpc.default_security_group_id}"
}
resource "aws_security_group_rule" "allow_mysql_from_any" {
type = "ingress"
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = "${aws_vpc.main_vpc.default_security_group_id}"
}
output "instance-dns" {
value = "${aws_instance.goflow-test-instance.public_dns}"
}
output "instance-id" {
value = "${aws_instance.goflow-test-instance.id}"
}