-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
173 lines (140 loc) · 3.37 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
#
# VARIABLES
#
variable "aws_region" {
description = "AWS region to launch servers."
default = "us-east-1"
}
variable "aws_availability_zone" {
default = "us-east-1a"
}
variable "linux_target" {
default = "ami-0baab88f069fe5d32"
}
variable "windows_target" {
default = "ami-49088d33"
}
variable "docker_target" {
default = "learnchef/inspec_nginx:latest"
}
#
# Creation
#
# docker container
resource "docker_image" "target" {
name = "${var.docker_target}"
keep_locally = true
}
resource "docker_container" "target" {
name = "target-instance"
image = "${docker_image.target.latest}"
command = [ "/bin/sleep", "infinity" ]
}
# instances
resource "aws_instance" "linux" {
ami = "${var.linux_target}"
instance_type = "t2.micro"
vpc_security_group_ids = ["${aws_security_group.ssh.id}"]
subnet_id = "${aws_subnet.public.id}"
availability_zone = "${var.aws_availability_zone}"
tags {
Name = "linux-target"
}
}
resource "aws_instance" "windows" {
ami = "${var.windows_target}"
instance_type = "t2.medium"
vpc_security_group_ids = ["${aws_security_group.winrm.id}"]
subnet_id = "${aws_subnet.public.id}"
availability_zone = "${var.aws_availability_zone}"
tags {
Name = "windows-target"
}
}
# networking
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
}
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.default.id}"
}
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.default.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
availability_zone = "${var.aws_availability_zone}"
}
resource "aws_security_group" "ssh" {
name = "inspec_ssh"
description = "Grant SSH access to all"
vpc_id = "${aws_vpc.default.id}"
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "winrm" {
name = "inspec_winrm"
description = "Grant WinRM access to all"
vpc_id = "${aws_vpc.default.id}"
# Allow inbound WinRM connection from all
ingress {
from_port = 5985
to_port = 5985
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# Allow inbound RDP connection from all
ingress {
from_port = 3389
to_port = 3389
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
#
# OUTPUT
#
output "linux.target" {
value = "${aws_instance.linux.public_ip}"
}
output "linux.target.Name" {
value = "${aws_instance.linux.tags.Name}"
}
output "linux.target.id" {
value = "${aws_instance.linux.id}"
}
output "windows.target" {
value = "${aws_instance.windows.public_ip}"
}
output "windows.target.Name" {
value = "${aws_instance.windows.tags.Name}"
}
output "windows.target.id" {
value = "${aws_instance.windows.id}"
}
output "docker.target" {
value = "${docker_container.target.id}"
}