From f0bf7be5d1d043ffc521acfeb392ecc14d1c53fd Mon Sep 17 00:00:00 2001 From: Andrew Peabody Date: Wed, 8 Jan 2025 00:32:42 +0000 Subject: [PATCH 1/2] feat(gke): add config_sync fleet examples --- gke/enterprise/config_sync/git/main.tf | 55 ++++++++++++++++++++++++ gke/enterprise/config_sync/git/test.yaml | 21 +++++++++ gke/enterprise/config_sync/oci/main.tf | 54 +++++++++++++++++++++++ gke/enterprise/config_sync/oci/test.yaml | 21 +++++++++ 4 files changed, 151 insertions(+) create mode 100644 gke/enterprise/config_sync/git/main.tf create mode 100644 gke/enterprise/config_sync/git/test.yaml create mode 100644 gke/enterprise/config_sync/oci/main.tf create mode 100644 gke/enterprise/config_sync/oci/test.yaml diff --git a/gke/enterprise/config_sync/git/main.tf b/gke/enterprise/config_sync/git/main.tf new file mode 100644 index 000000000..b94045d1b --- /dev/null +++ b/gke/enterprise/config_sync/git/main.tf @@ -0,0 +1,55 @@ +/** +* Copyright 2024-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_config_sync_git] +data "google_project" "default" {} + +resource "google_container_cluster" "default" { + name = "gke-autopilot-basic" + location = "us-central1" + + fleet { + project = data.google_project.default.project_id + } + + enable_autopilot = true + + # 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 = "configmanagement" + location = "global" + + fleet_default_member_config { + configmanagement { + config_sync { + # The field `enabled` was introduced in Terraform version 5.41.0, and + # needs to be set to `true` explicitly to install Config Sync. + enabled = true + git { + sync_repo = "REPO" + sync_branch = "BRANCH" + policy_dir = "DIRECTORY" + secret_type = "SECRET" + } + } + } + } +} +# [END gke_enterprise_config_sync_git] diff --git a/gke/enterprise/config_sync/git/test.yaml b/gke/enterprise/config_sync/git/test.yaml new file mode 100644 index 000000000..aa85d6edd --- /dev/null +++ b/gke/enterprise/config_sync/git/test.yaml @@ -0,0 +1,21 @@ +# 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. + +# The kubernetes_manifest resource can only be used with pre-existing clusters. +apiVersion: blueprints.cloud.google.com/v1alpha1 +kind: BlueprintTest +metadata: + name: config_sync_git +spec: + skip: true diff --git a/gke/enterprise/config_sync/oci/main.tf b/gke/enterprise/config_sync/oci/main.tf new file mode 100644 index 000000000..76f1d2a02 --- /dev/null +++ b/gke/enterprise/config_sync/oci/main.tf @@ -0,0 +1,54 @@ +/** +* Copyright 2024-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_config_sync_oci] +data "google_project" "default" {} + +resource "google_container_cluster" "default" { + name = "gke-autopilot-basic" + location = "us-central1" + + fleet { + project = data.google_project.default.project_id + } + + enable_autopilot = true + + # 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" "configmanagement_feature_member" { + name = "configmanagement" + location = "global" + + fleet_default_member_config { + configmanagement { + config_sync { + # The field `enabled` was introduced in Terraform version 5.41.0, and + # needs to be set to `true` explicitly to install Config Sync. + enabled = true + oci { + sync_repo = "REPO" + policy_dir = "DIRECTORY" + secret_type = "SECRET" + } + } + } + } +} +# [END gke_enterprise_config_sync_oci] diff --git a/gke/enterprise/config_sync/oci/test.yaml b/gke/enterprise/config_sync/oci/test.yaml new file mode 100644 index 000000000..0b9f37b49 --- /dev/null +++ b/gke/enterprise/config_sync/oci/test.yaml @@ -0,0 +1,21 @@ +# 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. + +# The kubernetes_manifest resource can only be used with pre-existing clusters. +apiVersion: blueprints.cloud.google.com/v1alpha1 +kind: BlueprintTest +metadata: + name: config_sync_oci +spec: + skip: true From bfb50af0f5b3f0a87974038193b67886c38f2358 Mon Sep 17 00:00:00 2001 From: Andrew Peabody Date: Wed, 8 Jan 2025 12:20:37 -0800 Subject: [PATCH 2/2] fixes --- gke/enterprise/config_sync/git/main.tf | 17 ----------------- gke/enterprise/config_sync/git/test.yaml | 2 +- gke/enterprise/config_sync/oci/main.tf | 17 ----------------- gke/enterprise/config_sync/oci/test.yaml | 2 +- 4 files changed, 2 insertions(+), 36 deletions(-) diff --git a/gke/enterprise/config_sync/git/main.tf b/gke/enterprise/config_sync/git/main.tf index b94045d1b..88a3a828a 100644 --- a/gke/enterprise/config_sync/git/main.tf +++ b/gke/enterprise/config_sync/git/main.tf @@ -15,23 +15,6 @@ */ # [START gke_enterprise_config_sync_git] -data "google_project" "default" {} - -resource "google_container_cluster" "default" { - name = "gke-autopilot-basic" - location = "us-central1" - - fleet { - project = data.google_project.default.project_id - } - - enable_autopilot = true - - # 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 = "configmanagement" location = "global" diff --git a/gke/enterprise/config_sync/git/test.yaml b/gke/enterprise/config_sync/git/test.yaml index aa85d6edd..ba0d2b2bc 100644 --- a/gke/enterprise/config_sync/git/test.yaml +++ b/gke/enterprise/config_sync/git/test.yaml @@ -1,4 +1,4 @@ -# Copyright 2024 Google LLC +# Copyright 2024-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. diff --git a/gke/enterprise/config_sync/oci/main.tf b/gke/enterprise/config_sync/oci/main.tf index 76f1d2a02..19ef2549d 100644 --- a/gke/enterprise/config_sync/oci/main.tf +++ b/gke/enterprise/config_sync/oci/main.tf @@ -15,23 +15,6 @@ */ # [START gke_enterprise_config_sync_oci] -data "google_project" "default" {} - -resource "google_container_cluster" "default" { - name = "gke-autopilot-basic" - location = "us-central1" - - fleet { - project = data.google_project.default.project_id - } - - enable_autopilot = true - - # 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" "configmanagement_feature_member" { name = "configmanagement" location = "global" diff --git a/gke/enterprise/config_sync/oci/test.yaml b/gke/enterprise/config_sync/oci/test.yaml index 0b9f37b49..b10c052d6 100644 --- a/gke/enterprise/config_sync/oci/test.yaml +++ b/gke/enterprise/config_sync/oci/test.yaml @@ -1,4 +1,4 @@ -# Copyright 2024 Google LLC +# Copyright 2024-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.