-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
156 lines (125 loc) · 4.02 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
provider "aws" {
region = var.aws_region
profile = var.aws_profile
}
resource "random_id" "instance_id" {
byte_length = 4
}
locals {
name = "cloud-playground"
region = var.cloudplayground_region
amazon2_ami = data.aws_ami.amazon2.id
}
////////////////////////////////
// VPC Configuration
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.2"
name = var.vpc_name
cidr = var.vpc_cidr
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
private_subnets = var.vpc_private_subnets
public_subnets = var.vpc_public_subnets
enable_nat_gateway = var.vpc_enable_nat_gateway
tags = var.vpc_tags
}
////////////////////////////////
// Linux Security Groups
module "linux_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.3"
name = "cloudplayground-linux-sg"
description = "Security group for cloudplayground linux instances"
vpc_id = module.vpc.vpc_id
ingress_with_cidr_blocks = [
{
from_port = 22
to_port = 22
protocol = "tcp"
description = "SSH ports"
cidr_blocks = "0.0.0.0/0"
}
]
}
////////////////////////////////
// Linux Instances
module "amazon2_instances" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.19"
name = "cloudplayground-amazon2"
instance_count = var.amazon2_instance_count
ami = data.aws_ami.amazon2.id
instance_type = var.linux_instance_type
vpc_security_group_ids = [module.vpc.default_security_group_id, module.linux_sg.security_group_id]
subnet_id = module.vpc.public_subnets[0]
key_name = var.aws_key_pair_name
tags = var.ec2_tags
}
module "ubuntu2004_instances" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.19"
name = "cloudplayground-ubuntu2004"
instance_count = var.ubuntu2004_instance_count
ami = data.aws_ami.ubuntu2004.id
instance_type = var.linux_instance_type
vpc_security_group_ids = [module.vpc.default_security_group_id, module.linux_sg.security_group_id]
subnet_id = module.vpc.public_subnets[0]
key_name = var.aws_key_pair_name
tags = var.ec2_tags
}
////////////////////////////////
// Windows Security Groups
module "windows_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4.3"
name = "cloudplayground-windows-sg"
description = "Security group for cloudplayground windows instances"
vpc_id = module.vpc.vpc_id
ingress_with_cidr_blocks = [
{
from_port = 5985
to_port = 5986
protocol = "tcp"
description = "Winrm ports"
cidr_blocks = "0.0.0.0/0"
},
{
from_port = 3389
to_port = 3389
protocol = "tcp"
description = "Remote Desktop ports"
cidr_blocks = "0.0.0.0/0"
}
]
egress_with_cidr_blocks = [
{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = "0.0.0.0/0"
}
]
}
////////////////////////////////////
// Windows WinRM Bootstrap Template
data "template_file" "winrm_user_data" {
template = "${file("${path.module}/templates/win_bootstrap.tpl")}"
vars = {
admin_password = "${var.windows_admin_password}"
}
}
////////////////////////////////
// Windows Security Groups
module "windows2019_instances" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "~> 2.19"
name = "cloudplayground-win2019"
instance_count = var.winserver2019_instance_count
ami = data.aws_ami.winserver2019.id
instance_type = var.winserver2019_instance_type
vpc_security_group_ids = [module.vpc.default_security_group_id, module.windows_sg.security_group_id]
subnet_id = module.vpc.public_subnets[0]
key_name = var.aws_key_pair_name
user_data = data.template_file.winrm_user_data.rendered
tags = var.ec2_tags
}