-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.tf
188 lines (157 loc) · 4.29 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
#
# Set minimum Terraform version and Terraform Cloud backend
#
terraform {
required_version = ">= 0.12"
}
#
# Configure AWS provider
#
provider "aws" {
region = var.region
access_key = var.AccessKeyID
secret_key = var.SecretAccessKey
}
#
# Create a random id
#
resource "random_id" "id" {
byte_length = 2
}
#
# Create the VPC
#
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = format("%s-vpc-%s", var.prefix, random_id.id.hex)
cidr = var.cidr
enable_dns_hostnames = true
enable_dns_support = true
azs = var.azs
public_subnets = [
for num in range(length(var.azs)) :
cidrsubnet(var.cidr, 8, num)
]
private_subnets = [
for num in range(length(var.azs)) :
cidrsubnet(var.cidr, 8, num + 10)
]
enable_nat_gateway = true
tags = {
Name = format("%s-vpc-%s", var.prefix, random_id.id.hex)
Terraform = "true"
Environment = "dev"
}
}
#
# Create a security group for BIG-IP
#
module "bigip_sg" {
source = "terraform-aws-modules/security-group/aws"
name = format("%s-bigip-%s", var.prefix, random_id.id.hex)
description = "Security group for BIG-IP Demo"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = [var.allowed_app_cidr]
ingress_rules = ["http-80-tcp", "https-443-tcp"]
ingress_with_source_security_group_id = [
{
rule = "all-all"
source_security_group_id = module.bigip_sg.this_security_group_id
}
]
# Allow ec2 instances outbound Internet connectivity
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
#
# Create a security group for BIG-IP Management
#
module "bigip_mgmt_sg" {
source = "terraform-aws-modules/security-group/aws"
name = format("%s-bigip-mgmt-%s", var.prefix, random_id.id.hex)
description = "Security group for BIG-IP Demo"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = [var.allowed_mgmt_cidr]
ingress_rules = ["https-443-tcp", "https-8443-tcp", "ssh-tcp"]
ingress_with_source_security_group_id = [
{
rule = "all-all"
source_security_group_id = module.bigip_mgmt_sg.this_security_group_id
}
]
# Allow ec2 instances outbound Internet connectivity
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
#
# Create a security group for demo app
#
module "demo_app_sg" {
source = "terraform-aws-modules/security-group/aws"
name = format("%s-demo-app-%s", var.prefix, random_id.id.hex)
description = "Security group for BIG-IP Demo"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = [var.cidr]
ingress_rules = ["all-all"]
# Allow ec2 instances outbound Internet connectivity
egress_cidr_blocks = ["0.0.0.0/0"]
egress_rules = ["all-all"]
}
#
# Create the demo NGINX app
#
module "nginx-demo-app" {
source = "codygreen/nginx-demo-app/aws"
version = "0.1.2"
prefix = format(
"%s-%s",
var.prefix,
random_id.id.hex
)
ec2_key_name = var.ec2_key_name
# associate_public_ip_address = true
vpc_security_group_ids = [
module.demo_app_sg.this_security_group_id
]
vpc_subnet_ids = module.vpc.private_subnets
ec2_instance_count = 4
}
#
# Create random password for BIG-IP
#
resource "random_password" "password" {
length = 16
special = true
override_special = "_%@"
}
#
# Create Secret Store and Store BIG-IP Password
#
resource "aws_secretsmanager_secret" "bigip" {
name = format("%s-bigip-secret-%s", var.prefix, random_id.id.hex)
}
resource "aws_secretsmanager_secret_version" "bigip-pwd" {
secret_id = aws_secretsmanager_secret.bigip.id
secret_string = random_password.password.result
}
#
# Create the BIG-IP appliances
#
module "bigip" {
source = "f5devcentral/bigip/aws"
version = "0.1.2"
prefix = format(
"%s-bigip-1-nic_with_new_vpc-%s",
var.prefix,
random_id.id.hex
)
aws_secretmanager_secret_id = aws_secretsmanager_secret.bigip.id
f5_instance_count = length(var.azs)
ec2_key_name = var.ec2_key_name
ec2_instance_type = "m4.large"
mgmt_subnet_security_group_ids = [
module.bigip_sg.this_security_group_id,
module.bigip_mgmt_sg.this_security_group_id
]
vpc_mgmt_subnet_ids = module.vpc.public_subnets
}