Repository navigation
Expand file tree
/
Copy pathnetwork.tf
More file actions
67 lines (62 loc) · 1.9 KB
/
Copy pathnetwork.tf
File metadata and controls
67 lines (62 loc) · 1.9 KB
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
data "nutanix_subnets_v2" "ext_nat" {
filter = "name eq 'overlay-external-subnet-nat'"
}
resource "nutanix_vpc_v2" "app" {
name = "vpc-app"
description = "application VPC, NAT egress via the NC2 transit VPC"
external_subnets {
subnet_reference = data.nutanix_subnets_v2.ext_nat.subnets[0].ext_id
}
}
locals {
# AWS resolver is the VPC's .2; derived from the PC address the same way the provider's NC2 sample does it
dns_server = replace(var.pc_endpoint, "/^([0-9]+\\.[0-9]+)\\.[0-9]+\\.[0-9]+$/", "$1.0.2")
subnets = {
"app-web" = "192.168.10"
"app-db" = "192.168.20"
}
}
resource "nutanix_subnet_v2" "app" {
for_each = local.subnets
name = each.key
subnet_type = "OVERLAY"
vpc_reference = nutanix_vpc_v2.app.id
ip_config {
ipv4 {
ip_subnet {
ip { value = "${each.value}.0" }
prefix_length = 24
}
default_gateway_ip { value = "${each.value}.1" }
pool_list {
start_ip { value = "${each.value}.10" }
end_ip { value = "${each.value}.200" }
}
dhcp_server_address { value = "${each.value}.2" }
}
}
dhcp_options {
domain_name_servers { ipv4 { value = local.dns_server } }
}
}
# Default route out through the external NAT subnet. The VPC's route table is created with the VPC; look it up.
data "nutanix_route_tables_v2" "app" {
filter = "vpcReference eq '${nutanix_vpc_v2.app.id}'"
depends_on = [nutanix_subnet_v2.app]
}
resource "nutanix_routes_v2" "app_default" {
name = "vpc-app-default"
vpc_reference = nutanix_vpc_v2.app.id
route_table_ext_id = data.nutanix_route_tables_v2.app.route_tables[0].ext_id
route_type = "STATIC"
destination {
ipv4 {
ip { value = "0.0.0.0" }
prefix_length = 0
}
}
next_hop {
next_hop_type = "EXTERNAL_SUBNET"
next_hop_reference = data.nutanix_subnets_v2.ext_nat.subnets[0].ext_id
}
}