-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
87 lines (70 loc) · 2.9 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
##############################################################################
# Create new VPC
##############################################################################
resource "ibm_is_vpc" "vpc" {
name = var.prefix != null ? "${var.prefix}-${var.name}-vpc" : "${var.name}-vpc"
resource_group = var.resource_group_id
classic_access = var.classic_access
address_prefix_management = var.use_manual_address_prefixes == false ? null : "manual"
default_network_acl_name = var.default_network_acl_name
default_security_group_name = var.default_security_group_name
default_routing_table_name = var.default_routing_table_name
tags = var.tags
}
##############################################################################
##############################################################################
# Address Prefixes
##############################################################################
locals {
# For each address prefix
address_prefixes = {
for prefix in module.dynamic_values.address_prefixes :
(prefix.name) => prefix
}
}
resource "ibm_is_vpc_address_prefix" "address_prefixes" {
for_each = local.address_prefixes
name = each.value.name
vpc = ibm_is_vpc.vpc.id
zone = each.value.zone
cidr = each.value.cidr
}
##############################################################################
##############################################################################
# ibm_is_vpc_route: Create vpc route resource
##############################################################################
locals {
routes_map = {
# Convert routes from list to map
for route in var.routes :
(route.name) => route
}
}
resource "ibm_is_vpc_route" "route" {
for_each = local.routes_map
name = "${var.prefix}-${var.name}-route-${each.value.name}"
vpc = ibm_is_vpc.vpc.id
zone = each.value.zone
destination = each.value.destination
next_hop = each.value.next_hop
}
##############################################################################
##############################################################################
# Public Gateways (Optional)
##############################################################################
locals {
# create object that only contains gateways that will be created
gateway_object = {
for zone in keys(var.use_public_gateways) :
zone => "${var.region}-${index(keys(var.use_public_gateways), zone) + 1}" if var.use_public_gateways[zone]
}
}
resource "ibm_is_public_gateway" "gateway" {
for_each = local.gateway_object
name = "${var.prefix}-${var.name}-public-gateway-${each.key}"
vpc = ibm_is_vpc.vpc.id
resource_group = var.resource_group_id
zone = each.value
tags = var.tags
}
##############################################################################