forked from GoogleCloudPlatform/cloud-foundation-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
122 lines (110 loc) · 4.58 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
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
# Creates a map of additional clusters objects, including their parent private cloud
additional_cluster_configs = merge(
[for pcc_name, pcc in var.vmw_private_cloud_configs
: { for cluster_name, cluster in pcc.additional_cluster_configs
: (cluster_name) => merge(
cluster,
{ parent = try(google_vmwareengine_private_cloud.vmw_engine_private_clouds[pcc_name].id, null) }
)
}
]...)
vmw_network = (
var.vmw_network_config.create
? try(google_vmwareengine_network.private_cloud_network[0], null)
: try(data.google_vmwareengine_network.private_cloud_network[0], null)
)
}
resource "google_vmwareengine_network" "private_cloud_network" {
provider = google-beta
count = var.vmw_network_config.create ? 1 : 0
project = var.project_id
name = "${var.prefix}-${var.vmw_network_config.name}"
description = var.vmw_network_config.description
location = "global"
type = "STANDARD"
}
data "google_vmwareengine_network" "private_cloud_network" {
provider = google-beta
count = var.vmw_network_config.create ? 0 : 1
project = var.project_id
name = "${var.prefix}-${var.vmw_network_config.name}"
location = "global"
}
resource "google_vmwareengine_network_policy" "vmw_engine_network_policies" {
provider = google-beta
for_each = var.vmw_network_config.network_policies
project = var.project_id
name = "${var.prefix}-${each.key}"
description = each.value.description
edge_services_cidr = each.value.edge_services_cidr
location = each.value.region
vmware_engine_network = local.vmw_network.id
external_ip {
enabled = each.value.expose_on_internet
}
internet_access {
enabled = each.value.outbound_internet_access
}
}
resource "google_vmwareengine_network_peering" "vmw_engine_network_peerings" {
provider = google-beta
for_each = var.vmw_network_peerings
project = var.project_id
name = "${var.prefix}-${each.key}"
description = each.value.description
export_custom_routes = each.value.export_custom_routes
export_custom_routes_with_public_ip = each.value.export_custom_routes_with_public_ip
import_custom_routes = each.value.import_custom_routes
import_custom_routes_with_public_ip = each.value.import_custom_routes_with_public_ip
peer_network = each.value.peer_network
peer_network_type = each.value.peer_to_vmware_engine_network ? "VMWARE_ENGINE_NETWORK" : "STANDARD"
vmware_engine_network = local.vmw_network.id
}
resource "google_vmwareengine_private_cloud" "vmw_engine_private_clouds" {
provider = google-beta
for_each = var.vmw_private_cloud_configs
project = var.project_id
location = each.value.zone
name = "${var.prefix}-${each.key}"
description = each.value.description
type = each.value.management_cluster_config.node_count == 1 ? "TIME_LIMITED" : "STANDARD"
network_config {
management_cidr = each.value.cidr
vmware_engine_network = local.vmw_network.id
}
management_cluster {
cluster_id = "${var.prefix}-${each.key}-${each.value.management_cluster_config.name}"
node_type_configs {
node_type_id = each.value.management_cluster_config.node_type_id
node_count = each.value.management_cluster_config.node_count
custom_core_count = each.value.management_cluster_config.custom_core_count
}
}
}
resource "google_vmwareengine_cluster" "vmw_engine_additional_clusters" {
provider = google-beta
for_each = local.additional_cluster_configs
name = "${var.prefix}-${each.key}"
parent = each.value.parent
node_type_configs {
custom_core_count = each.value.custom_core_count
node_count = each.value.node_count
node_type_id = each.value.node_type_id
}
}