Skip to content

Commit 2bd3b57

Browse files
committed
feat(gke): add policycontroller samples
1 parent b75c1b9 commit 2bd3b57

File tree

2 files changed

+126
-0
lines changed
  • gke

2 files changed

+126
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
"anthospolicycontroller.googleapis.com"
23+
])
24+
25+
service = each.value
26+
disable_on_destroy = false
27+
}
28+
29+
resource "google_container_cluster" "default" {
30+
name = "gke-autopilot-mesh"
31+
location = "us-central1"
32+
33+
enable_autopilot = true
34+
35+
fleet {
36+
project = data.google_project.default.project_id
37+
}
38+
39+
# Set `deletion_protection` to `true` will ensure that one cannot
40+
# accidentally delete this instance by use of Terraform.
41+
deletion_protection = false
42+
}
43+
44+
resource "google_gke_hub_feature" "default" {
45+
name = "policycontroller"
46+
location = "global"
47+
48+
depends_on = [google_project_service.default]
49+
}
50+
51+
52+
resource "google_gke_hub_feature_membership" "default" {
53+
location = "global"
54+
55+
feature = google_gke_hub_feature.default.name
56+
membership = google_container_cluster.default.fleet[0].membership_id
57+
membership_location = google_container_cluster.default.fleet[0].membership_location
58+
59+
policycontroller {
60+
policy_controller_hub_config {
61+
install_spec = "INSTALL_SPEC_ENABLED"
62+
policy_content {
63+
bundles {
64+
bundle_name = "policy-essentials-v2022"
65+
}
66+
template_library {
67+
installation = "ALL"
68+
}
69+
}
70+
audit_interval_seconds = 30
71+
referential_rules_enabled = true
72+
}
73+
}
74+
}
75+
# [END gke_autopilot_policycontroller]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
"anthospolicycontroller.googleapis.com"
21+
])
22+
23+
service = each.value
24+
disable_on_destroy = false
25+
}
26+
27+
resource "google_gke_hub_feature" "default" {
28+
name = "policycontroller"
29+
location = "global"
30+
31+
fleet_default_member_config {
32+
policycontroller {
33+
policy_controller_hub_config {
34+
install_spec = "INSTALL_SPEC_ENABLED"
35+
policy_content {
36+
bundles {
37+
bundle = "policy-essentials-v2022"
38+
}
39+
template_library {
40+
installation = "ALL"
41+
}
42+
}
43+
audit_interval_seconds = 30
44+
referential_rules_enabled = true
45+
}
46+
}
47+
}
48+
49+
depends_on = [google_project_service.default]
50+
}
51+
# [END gke_enterprise_policycontroller]

0 commit comments

Comments
 (0)