-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
245 lines (223 loc) · 10.6 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.11.0"
}
}
}
provider "azurerm" {
# Configuration options
# For test
features {
virtual_machine {
delete_os_disk_on_deletion = true
graceful_shutdown = false
skip_shutdown_and_force_delete = false
}
}
}
/*data "azurerm_shared_image" "example" {
name = "my-image"
gallery_name =
resource_group_name = "ise"
}
output "ciscoise_aci_bindings_example" {
value = data.azurerm_shared_image.example.id
}*/
//Create resource group
resource "azurerm_resource_group" "ise" {
count = var.create_resource_group ? 1 : 0
name = var.azure_resource_group_name
location = var.azure_resource_group_location
}
//Look for resource group
data "azurerm_resource_group" "example" {
count = var.create_resource_group ? 0 : 1
name = var.azure_resource_group_name
}
//Create virtual network
resource "azurerm_virtual_network" "ise" {
count = var.create_virtual_network ? 1 : 0
name = var.azure_virtual_network_name
location = var.create_resource_group ? azurerm_resource_group.ise[0].location : data.azurerm_resource_group.example[0].location
resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
address_space = var.azure_virtual_network_address_space
dns_servers = var.azure_virtual_network_dns_servers
/*subnet {
name = "subnet1"
address_prefix = "10.0.1.0/24"
}
subnet {
name = "subnet2"
address_prefix = "10.0.2.0/24"
security_group = var.create_security_group ? azurerm_network_security_group.ise[0].id : data.azurerm_network_security_group.example[0].id
}
tags = {
environment = "Production"
}*/
}
//Look for virtual network
data "azurerm_virtual_network" "example" {
count = var.create_virtual_network ? 0 : 1
name = var.azure_virtual_network_name
resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
}
// Create Subnet
resource "azurerm_subnet" "internal" {
count = var.create_subnet ? 1 : 0
name = var.azure_subnet_name
resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
virtual_network_name = var.create_virtual_network ? azurerm_virtual_network.ise[0].name : data.azurerm_virtual_network.example[0].name
address_prefixes = var.azure_subnet_address_prefixes
}
// Look for Subnet
data "azurerm_subnet" "example" {
count = var.create_subnet ? 0 : 1
name = var.azure_subnet_name
virtual_network_name = var.create_virtual_network ? azurerm_virtual_network.ise[0].name : data.azurerm_virtual_network.example[0].name
resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
}
// Create security group
resource "azurerm_network_security_group" "ise" {
count = var.create_security_group ? 1 : 0
name = var.azure_network_security_group_name
location = var.create_resource_group ? azurerm_resource_group.ise[0].location : data.azurerm_resource_group.example[0].location
resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
security_rule {
name = "AllowSSH"
priority = 101
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "AllowHTTPSAccess"
priority = 104
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "AllowMultiplePorts"
priority = 102
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "AllowICMP"
priority = 103
direction = "Inbound"
access = "Allow"
protocol = "Icmp"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
// Look for security group
data "azurerm_network_security_group" "example" {
count = var.create_security_group ? 0 : 1
name = var.azure_network_security_group_name
resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
}
// Create (and display) an SSH key
resource "tls_private_key" "ise_ssh" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "local_file" "linuxkey" {
filename = "azure_key.pem"
content = tls_private_key.ise_ssh.private_key_pem
file_permission = "0600"
}
# resource "azurerm_ssh_public_key" "example" {
# name = "ise_azure_key"
# resource_group_name = var.azure_resource_group_name
# location = var.azure_resource_group_location
# public_key = file("~/.ssh/id_rsa.pub")
# }
module "single" {
count = var.ise_deployment == "single_node" ? 1 : 0
source = "./modules/single_node"
azure_resource_group_location = var.create_resource_group ? azurerm_resource_group.ise[0].location : data.azurerm_resource_group.example[0].location
azure_resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
ssh_key = tls_private_key.ise_ssh.public_key_openssh
internal_id = var.create_subnet ? azurerm_subnet.internal[0].id : data.azurerm_subnet.example[0].id
azure_security_group_id = var.create_security_group ? azurerm_network_security_group.ise[0].id : data.azurerm_network_security_group.example[0].id
ise_username = var.ise_username
ise_password = var.ise_password
ise_base_hostname = var.ise_base_hostname
ise_dns_server = var.ise_dns_server
ise_domain = var.ise_domain
ise_ntp_server = var.ise_ntp_server
ise_timezone = var.ise_timezone
source_image_id = var.source_image_id
}
module "small" {
count = var.ise_deployment == "small_deployment" ? 1 : 0
source = "./modules/small_deployment"
azure_resource_group_location = var.create_resource_group ? azurerm_resource_group.ise[0].location : data.azurerm_resource_group.example[0].location
azure_resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
ssh_key = tls_private_key.ise_ssh.public_key_openssh
internal_id = var.create_subnet ? azurerm_subnet.internal[0].id : data.azurerm_subnet.example[0].id
azure_security_group_id = var.create_security_group ? azurerm_network_security_group.ise[0].id : data.azurerm_network_security_group.example[0].id
ise_username = var.ise_username
ise_password = var.ise_password
ise_base_hostname = var.ise_base_hostname
ise_dns_server = var.ise_dns_server
ise_domain = var.ise_domain
ise_ntp_server = var.ise_ntp_server
ise_timezone = var.ise_timezone
source_image_id = var.source_image_id
}
module "medium" {
count = var.ise_deployment == "medium_deployment" ? 1 : 0
source = "./modules/medium_deployment"
azure_resource_group_location = var.create_resource_group ? azurerm_resource_group.ise[0].location : data.azurerm_resource_group.example[0].location
azure_resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
ssh_key = tls_private_key.ise_ssh.public_key_openssh
ise_psn_instances = var.ise_psn_instances
internal_id = var.create_subnet ? azurerm_subnet.internal[0].id : data.azurerm_subnet.example[0].id
azure_security_group_id = var.create_security_group ? azurerm_network_security_group.ise[0].id : data.azurerm_network_security_group.example[0].id
ise_username = var.ise_username
ise_password = var.ise_password
ise_base_hostname = var.ise_base_hostname
ise_dns_server = var.ise_dns_server
ise_domain = var.ise_domain
ise_ntp_server = var.ise_ntp_server
ise_timezone = var.ise_timezone
source_image_id = var.source_image_id
}
module "large" {
count = var.ise_deployment == "large_deployment" ? 1 : 0
source = "./modules/large_deployment"
azure_resource_group_location = var.create_resource_group ? azurerm_resource_group.ise[0].location : data.azurerm_resource_group.example[0].location
azure_resource_group_name = var.create_resource_group ? azurerm_resource_group.ise[0].name : var.azure_resource_group_name
ssh_key = tls_private_key.ise_ssh.public_key_openssh
ise_psn_instances = var.ise_psn_instances
internal_id = var.create_subnet ? azurerm_subnet.internal[0].id : data.azurerm_subnet.example[0].id
azure_security_group_id = var.create_security_group ? azurerm_network_security_group.ise[0].id : data.azurerm_network_security_group.example[0].id
ise_username = var.ise_username
ise_password = var.ise_password
ise_base_hostname = var.ise_base_hostname
ise_dns_server = var.ise_dns_server
ise_domain = var.ise_domain
ise_ntp_server = var.ise_ntp_server
ise_timezone = var.ise_timezone
source_image_id = var.source_image_id
}