-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathmain.tf
119 lines (109 loc) · 3.29 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
/**
* 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.
*/
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 5.16.0"
}
}
}
provider "google" {
project = var.project
}
# [START anthosconfig_fleet_scopes]
resource "google_gke_hub_scope" "scope" {
provider = google
for_each = toset([
"backend",
"frontend",
])
scope_id = each.value
}
# [END anthosconfig_fleet_scopes]
# [START anthosconfig_fleet_membership_bindings]
resource "google_gke_hub_membership_binding" "membership-binding" {
provider = google
for_each = {
us-east-backend = {
membership_binding_id = "us-east-backend"
scope = google_gke_hub_scope.scope["backend"].name
membership_id = "us-east-cluster"
location = "us-east1"
}
us-west-backend = {
membership_binding_id = "us-west-backend"
scope = google_gke_hub_scope.scope["backend"].name
membership_id = "us-west-cluster"
location = "us-west1"
}
us-east-frontend = {
membership_binding_id = "us-east-frontend"
scope = google_gke_hub_scope.scope["frontend"].name
membership_id = "us-east-cluster"
location = "us-east1"
}
us-west-frontend = {
membership_binding_id = "us-west-frontend"
scope = google_gke_hub_scope.scope["frontend"].name
membership_id = "us-west-cluster"
location = "us-west1"
}
us-central-frontend = {
membership_binding_id = "us-central-frontend"
scope = google_gke_hub_scope.scope["frontend"].name
membership_id = "us-central-cluster"
location = "us-central1"
}
}
membership_binding_id = each.value.membership_binding_id
scope = each.value.scope
membership_id = each.value.membership_id
location = each.value.location
depends_on = [google_gke_hub_scope.scope]
}
# [END anthosconfig_fleet_membership_bindings]
# [START anthosconfig_fleet_namespaces]
resource "google_gke_hub_namespace" "fleet_namespace" {
provider = google
for_each = {
bookstore = {
scope_id = "backend"
scope_namespace_id = "bookstore"
scope = google_gke_hub_scope.scope["backend"].name
}
shoestore = {
scope_id = "backend"
scope_namespace_id = "shoestore"
scope = google_gke_hub_scope.scope["backend"].name
}
frontend_a = {
scope_id = "frontend"
scope_namespace_id = "frontend-a"
scope = google_gke_hub_scope.scope["frontend"].name
}
frontend_b = {
scope_id = "frontend"
scope_namespace_id = "frontend-b"
scope = google_gke_hub_scope.scope["frontend"].name
}
}
scope_namespace_id = each.value.scope_namespace_id
scope_id = each.value.scope_id
scope = each.value.scope
depends_on = [google_gke_hub_scope.scope]
}
# [END anthosconfig_fleet_namespaces]