|
| 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 | +locals { |
| 18 | + cluster_type = "gke-autopilot" |
| 19 | + default_workload_pool = "${var.project_id}.svc.id.goog" |
| 20 | + network_name = "autopilot-network" |
| 21 | + subnet_name = "autopilot-subnet" |
| 22 | + master_auth_subnetwork = "autopilot-master-subnet" |
| 23 | + pods_range_name = "ip-range-pods-autopilot" |
| 24 | + svc_range_name = "ip-range-svc-autopilot" |
| 25 | +} |
| 26 | + |
| 27 | +data "google_client_config" "default" {} |
| 28 | + |
| 29 | +provider "kubernetes" { |
| 30 | + host = "https://${module.gke.endpoint}" |
| 31 | + token = data.google_client_config.default.access_token |
| 32 | + cluster_ca_certificate = base64decode(module.gke.ca_certificate) |
| 33 | +} |
| 34 | + |
| 35 | +module "gke" { |
| 36 | + source = "../../modules/gke-autopilot-cluster" |
| 37 | + |
| 38 | + project = var.project_id |
| 39 | + name = "${local.cluster_type}-cluster" |
| 40 | + location = var.region |
| 41 | + network = module.gcp-network.network_self_link |
| 42 | + subnetwork = module.gcp-network.subnets_self_links[index(module.gcp-network.subnets_names, local.subnet_name)] |
| 43 | + |
| 44 | + ip_allocation_policy = { |
| 45 | + cluster_secondary_range_name = local.pods_range_name |
| 46 | + services_secondary_range_name = local.svc_range_name |
| 47 | + } |
| 48 | + |
| 49 | + private_cluster_config = { |
| 50 | + enable_private_endpoint = true |
| 51 | + enable_private_nodes = true |
| 52 | + master_ipv4_cidr_block = "172.16.0.0/28" |
| 53 | + master_global_access_config = { |
| 54 | + enabled = true |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + master_authorized_networks_config = { |
| 59 | + cidr_blocks = [{ |
| 60 | + cidr_block = "10.60.0.0/17" |
| 61 | + display_name = "VPC" |
| 62 | + }] |
| 63 | + } |
| 64 | + |
| 65 | + confidential_nodes = { |
| 66 | + enabled = true |
| 67 | + } |
| 68 | + |
| 69 | + workload_identity_config = { |
| 70 | + workload_pool = local.default_workload_pool |
| 71 | + } |
| 72 | +} |
0 commit comments