Skip to content

Commit

Permalink
feat(gke): add config_sync cluster samples
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Nov 21, 2024
1 parent 0828b82 commit a1df75a
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
61 changes: 61 additions & 0 deletions gke/autopilot/config_sync/git/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* 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.
*/

# [START gke_autopilot_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" "configmanagement_feature" {
name = "configmanagement"
location = "global"
}

resource "google_gke_hub_feature_membership" "configmanagement_feature_member" {
location = "global"

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

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_autopilot_config_sync_git]
21 changes: 21 additions & 0 deletions gke/autopilot/config_sync/git/test.yaml
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions gke/autopilot/config_sync/oci/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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.
*/

# [START gke_autopilot_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" {
name = "configmanagement"
location = "global"
}

resource "google_gke_hub_feature_membership" "configmanagement_feature_member" {
location = "global"

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

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_autopilot_config_sync_oci]
21 changes: 21 additions & 0 deletions gke/autopilot/config_sync/oci/test.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a1df75a

Please sign in to comment.