Skip to content

Commit 27187e3

Browse files
committed
feat(gke): add policycontroller samples
1 parent b75c1b9 commit 27187e3

File tree

2 files changed

+128
-0
lines changed
  • gke

2 files changed

+128
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START gke_autopilot_policycontroller]
18+
data "google_project" "default" {}
19+
20+
resource "google_project_service" "default" {
21+
for_each = toset([
22+
"anthos.googleapis.com",
23+
"anthospolicycontroller.googleapis.com"
24+
])
25+
26+
service = each.value
27+
disable_on_destroy = false
28+
}
29+
30+
resource "google_container_cluster" "default" {
31+
name = "gke-autopilot-mesh"
32+
location = "us-central1"
33+
34+
enable_autopilot = true
35+
36+
fleet {
37+
project = data.google_project.default.project_id
38+
}
39+
40+
# Set `deletion_protection` to `true` will ensure that one cannot
41+
# accidentally delete this instance by use of Terraform.
42+
deletion_protection = false
43+
}
44+
45+
resource "google_gke_hub_feature" "default" {
46+
name = "policycontroller"
47+
location = "global"
48+
49+
depends_on = [google_project_service.default]
50+
}
51+
52+
53+
resource "google_gke_hub_feature_membership" "default" {
54+
location = "global"
55+
56+
feature = google_gke_hub_feature.default.name
57+
membership = google_container_cluster.default.fleet[0].membership_id
58+
membership_location = google_container_cluster.default.fleet[0].membership_location
59+
60+
policycontroller {
61+
policy_controller_hub_config {
62+
install_spec = "INSTALL_SPEC_ENABLED"
63+
policy_content {
64+
bundles {
65+
bundle_name = "policy-essentials-v2022"
66+
}
67+
template_library {
68+
installation = "ALL"
69+
}
70+
}
71+
audit_interval_seconds = 30
72+
referential_rules_enabled = true
73+
}
74+
}
75+
}
76+
# [END gke_autopilot_policycontroller]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
# [START gke_enterprise_policycontroller]
18+
resource "google_project_service" "default" {
19+
for_each = toset([
20+
"anthos.googleapis.com",
21+
"anthospolicycontroller.googleapis.com"
22+
])
23+
24+
service = each.value
25+
disable_on_destroy = false
26+
}
27+
28+
resource "google_gke_hub_feature" "default" {
29+
name = "policycontroller"
30+
location = "global"
31+
32+
fleet_default_member_config {
33+
policycontroller {
34+
policy_controller_hub_config {
35+
install_spec = "INSTALL_SPEC_ENABLED"
36+
policy_content {
37+
bundles {
38+
bundle = "policy-essentials-v2022"
39+
}
40+
template_library {
41+
installation = "ALL"
42+
}
43+
}
44+
audit_interval_seconds = 30
45+
referential_rules_enabled = true
46+
}
47+
}
48+
}
49+
50+
depends_on = [google_project_service.default]
51+
}
52+
# [END gke_enterprise_policycontroller]

0 commit comments

Comments
 (0)