Skip to content

Commit

Permalink
feat(gke): add policycontroller samples (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored Jan 8, 2025
1 parent b75c1b9 commit f248b0d
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
76 changes: 76 additions & 0 deletions gke/autopilot/policycontroller/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright 2025 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.
*/

# [START gke_autopilot_policycontroller]
data "google_project" "default" {}

resource "google_project_service" "default" {
for_each = toset([
"anthos.googleapis.com",
"anthospolicycontroller.googleapis.com"
])

service = each.value
disable_on_destroy = false
}

resource "google_container_cluster" "default" {
name = "gke-autopilot-policycontroller"
location = "us-central1"

enable_autopilot = true

fleet {
project = data.google_project.default.project_id
}

# Set `deletion_protection` to `true` will ensure that one cannot
# accidentally delete this instance by use of Terraform.
deletion_protection = false
}

resource "google_gke_hub_feature" "default" {
name = "policycontroller"
location = "global"

depends_on = [google_project_service.default]
}


resource "google_gke_hub_feature_membership" "default" {
location = "global"

feature = google_gke_hub_feature.default.name
membership = google_container_cluster.default.fleet[0].membership_id
membership_location = google_container_cluster.default.fleet[0].membership_location

policycontroller {
policy_controller_hub_config {
install_spec = "INSTALL_SPEC_ENABLED"
policy_content {
bundles {
bundle_name = "policy-essentials-v2022"
}
template_library {
installation = "ALL"
}
}
audit_interval_seconds = 30
referential_rules_enabled = true
}
}
}
# [END gke_autopilot_policycontroller]
52 changes: 52 additions & 0 deletions gke/enterprise/policycontroller/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2025 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.
*/

# [START gke_enterprise_policycontroller]
resource "google_project_service" "default" {
for_each = toset([
"anthos.googleapis.com",
"anthospolicycontroller.googleapis.com"
])

service = each.value
disable_on_destroy = false
}

resource "google_gke_hub_feature" "default" {
name = "policycontroller"
location = "global"

fleet_default_member_config {
policycontroller {
policy_controller_hub_config {
install_spec = "INSTALL_SPEC_ENABLED"
policy_content {
bundles {
bundle = "policy-essentials-v2022"
}
template_library {
installation = "ALL"
}
}
audit_interval_seconds = 30
referential_rules_enabled = true
}
}
}

depends_on = [google_project_service.default]
}
# [END gke_enterprise_policycontroller]

0 comments on commit f248b0d

Please sign in to comment.