|
| 1 | +/** |
| 2 | + * Copyright 2024 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 | + |
| 18 | +// This is an example of how you might use the attached module with a local kind cluster |
| 19 | + |
| 20 | +locals { |
| 21 | + cluster_name = "${var.name_prefix}-cluster" |
| 22 | +} |
| 23 | + |
| 24 | +resource "kind_cluster" "cluster" { |
| 25 | + name = local.cluster_name |
| 26 | + node_image = var.kind_node_image |
| 27 | + |
| 28 | + kubeconfig_path = "${path.root}/.tmp/kube/${local.cluster_name}" |
| 29 | + |
| 30 | + wait_for_ready = true |
| 31 | + |
| 32 | + kind_config { |
| 33 | + kind = "Cluster" |
| 34 | + api_version = "kind.x-k8s.io/v1alpha4" |
| 35 | + feature_gates = { |
| 36 | + KubeletInUserNamespace : "true" |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +provider "helm" { |
| 42 | + alias = "bootstrap_installer" |
| 43 | + kubernetes { |
| 44 | + host = kind_cluster.cluster.endpoint |
| 45 | + client_certificate = kind_cluster.cluster.client_certificate |
| 46 | + client_key = kind_cluster.cluster.client_key |
| 47 | + cluster_ca_certificate = kind_cluster.cluster.cluster_ca_certificate |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +module "attached_install_manifest" { |
| 52 | + source = "../modules/attached-install-manifest" |
| 53 | + attached_cluster_name = local.cluster_name |
| 54 | + attached_cluster_fleet_project = data.google_project.project.project_id |
| 55 | + gcp_location = var.gcp_location |
| 56 | + platform_version = var.platform_version |
| 57 | + providers = { |
| 58 | + helm = helm.bootstrap_installer |
| 59 | + } |
| 60 | + depends_on = [ |
| 61 | + kind_cluster.cluster |
| 62 | + ] |
| 63 | +} |
| 64 | + |
| 65 | +data "google_project" "project" { |
| 66 | + project_id = var.gcp_project_id |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +module "oidc" { |
| 72 | + source = "./oidc" |
| 73 | + |
| 74 | + endpoint = kind_cluster.cluster.endpoint |
| 75 | + cluster_ca_certificate = kind_cluster.cluster.cluster_ca_certificate |
| 76 | + client_certificate = kind_cluster.cluster.client_certificate |
| 77 | + client_key = kind_cluster.cluster.client_key |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +resource "google_container_attached_cluster" "primary" { |
| 82 | + name = local.cluster_name |
| 83 | + project = data.google_project.project.project_id |
| 84 | + location = var.gcp_location |
| 85 | + description = "Kind attached cluster example" |
| 86 | + distribution = "generic" |
| 87 | + platform_version = var.platform_version |
| 88 | + oidc_config { |
| 89 | + issuer_url = module.oidc.issuer |
| 90 | + jwks = module.oidc.jwks |
| 91 | + } |
| 92 | + fleet { |
| 93 | + project = "projects/${data.google_project.project.number}" |
| 94 | + } |
| 95 | + |
| 96 | + # Optional: |
| 97 | + # logging_config { |
| 98 | + # component_config { |
| 99 | + # enable_components = ["SYSTEM_COMPONENTS", "WORKLOADS"] |
| 100 | + # } |
| 101 | + # } |
| 102 | + |
| 103 | + # Optional: |
| 104 | + # monitoring_config { |
| 105 | + # managed_prometheus_config { |
| 106 | + # enabled = true |
| 107 | + # } |
| 108 | + # } |
| 109 | + |
| 110 | + # Optional: |
| 111 | + # authorization { |
| 112 | + # admin_users = ["[email protected]", ] |
| 113 | + |
| 114 | + # } |
| 115 | + |
| 116 | + depends_on = [ |
| 117 | + module.attached_install_manifest |
| 118 | + ] |
| 119 | +} |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
0 commit comments