forked from GoogleCloudPlatform/cloud-foundation-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
151 lines (142 loc) · 4.56 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
/**
* Copyright 2022 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 {
_cluster_cm_config = flatten([
for template, clusters in var.configmanagement_clusters : [
for cluster in clusters : {
cluster = cluster
template = lookup(var.configmanagement_templates, template, null)
}
]
])
cluster_cm_config = {
for k in local._cluster_cm_config : k.cluster => k.template if(
k.template != null &&
var.features.configmanagement == true
)
}
hub_features = {
for k, v in var.features : k => v if v != null && v != false && v != ""
}
}
resource "google_gke_hub_membership" "default" {
provider = google-beta
for_each = var.clusters
project = var.project_id
membership_id = each.key
endpoint {
gke_cluster {
resource_link = each.value
}
}
dynamic "authority" {
for_each = (
contains(var.workload_identity_clusters, each.key) ? {} : { 1 = 1 }
)
content {
issuer = "https://container.googleapis.com/v1/${var.clusters[each.key]}"
}
}
}
resource "google_gke_hub_feature" "default" {
provider = google-beta
for_each = local.hub_features
project = var.project_id
name = each.key
location = "global"
dynamic "spec" {
for_each = each.key == "multiclusteringress" && each.value != null ? { 1 = 1 } : {}
content {
multiclusteringress {
config_membership = google_gke_hub_membership.default[each.value].id
}
}
}
}
resource "google_gke_hub_feature_membership" "default" {
provider = google-beta
for_each = local.cluster_cm_config
project = var.project_id
location = "global"
feature = google_gke_hub_feature.default["configmanagement"].name
membership = google_gke_hub_membership.default[each.key].membership_id
configmanagement {
version = each.value.version
dynamic "binauthz" {
for_each = each.value.binauthz != true ? {} : { 1 = 1 }
content {
enabled = true
}
}
dynamic "config_sync" {
for_each = each.value.config_sync == null ? {} : { 1 = 1 }
content {
prevent_drift = each.value.config_sync.prevent_drift
source_format = each.value.config_sync.source_format
dynamic "git" {
for_each = (
try(each.value.config_sync.git, null) == null ? {} : { 1 = 1 }
)
content {
gcp_service_account_email = (
each.value.config_sync.git.gcp_service_account_email
)
https_proxy = each.value.config_sync.git.https_proxy
policy_dir = each.value.config_sync.git.policy_dir
secret_type = each.value.config_sync.git.secret_type
sync_branch = each.value.config_sync.git.sync_branch
sync_repo = each.value.config_sync.git.sync_repo
sync_rev = each.value.config_sync.git.sync_rev
sync_wait_secs = each.value.config_sync.git.sync_wait_secs
}
}
}
}
dynamic "hierarchy_controller" {
for_each = each.value.hierarchy_controller == null ? {} : { 1 = 1 }
content {
enable_hierarchical_resource_quota = (
each.value.hierarchy_controller.enable_hierarchical_resource_quota
)
enable_pod_tree_labels = (
each.value.hierarchy_controller.enable_pod_tree_labels
)
enabled = true
}
}
dynamic "policy_controller" {
for_each = each.value.policy_controller == null ? {} : { 1 = 1 }
content {
audit_interval_seconds = (
each.value.policy_controller.audit_interval_seconds
)
exemptable_namespaces = (
each.value.policy_controller.exemptable_namespaces
)
log_denies_enabled = (
each.value.policy_controller.log_denies_enabled
)
referential_rules_enabled = (
each.value.policy_controller.referential_rules_enabled
)
template_library_installed = (
each.value.policy_controller.template_library_installed
)
enabled = true
}
}
}
}