11/**
2- * Copyright 2018 Google LLC
2+ * Copyright 2022 Google LLC
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ resource "google_container_cluster" "primary" {
3535 node_locations = local.node_locations
3636 cluster_ipv4_cidr = var.cluster_ipv4_cidr
3737 network = "projects/${local.network_project_id}/global/networks/${var.network}"
38-
38+ {% if autopilot_cluster != true %}
3939 dynamic "network_policy" {
4040 for_each = local.cluster_network_policy
4141
@@ -44,6 +44,7 @@ resource "google_container_cluster" "primary" {
4444 provider = network_policy.value.provider
4545 }
4646 }
47+ {% endif %}
4748
4849 dynamic "release_channel" {
4950 for_each = local.release_channel
@@ -64,13 +65,13 @@ resource "google_container_cluster" "primary" {
6465 subnetwork = "projects/${local.network_project_id}/regions/${local.region}/subnetworks/${var.subnetwork}"
6566
6667{% if beta_cluster %}
67- default_snat_status{
68+ default_snat_status {
6869 disabled = var.disable_default_snat
6970 }
7071{% endif %}
7172 min_master_version = var.release_channel != null ? null : local.master_version
7273
73- {% if beta_cluster %}
74+ {% if beta_cluster and autopilot_cluster != true %}
7475 dynamic "cluster_telemetry" {
7576 for_each = local.cluster_telemetry_type_is_set ? [1] : []
7677 content {
@@ -98,7 +99,7 @@ resource "google_container_cluster" "primary" {
9899 logging_service = var.logging_service
99100 monitoring_service = var.monitoring_service
100101{% endif %}
101-
102+ {% if autopilot_cluster != true %}
102103 cluster_autoscaling {
103104 enabled = var.cluster_autoscaling.enabled
104105 dynamic "auto_provisioning_defaults" {
@@ -107,14 +108,14 @@ resource "google_container_cluster" "primary" {
107108 content {
108109 service_account = local.service_account
109110 oauth_scopes = local.node_pools_oauth_scopes["all"]
110- {% if beta_cluster %}
111+ {% if beta_cluster %}
111112 min_cpu_platform = lookup(var.node_pools[0], "min_cpu_platform", "")
112- {% endif %}
113+ {% endif %}
113114 }
114115 }
115- {% if beta_cluster %}
116+ {% if beta_cluster %}
116117 autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
117- {% endif %}
118+ {% endif %}
118119 dynamic "resource_limits" {
119120 for_each = local.autoscaling_resource_limits
120121 content {
@@ -124,16 +125,15 @@ resource "google_container_cluster" "primary" {
124125 }
125126 }
126127 }
127-
128+ {% endif %}
128129 vertical_pod_autoscaling {
129130 enabled = var.enable_vertical_pod_autoscaling
130131 }
131-
132+ {% if autopilot_cluster != true %}
132133 default_max_pods_per_node = var.default_max_pods_per_node
133-
134134 enable_shielded_nodes = var.enable_shielded_nodes
135135 enable_binary_authorization = var.enable_binary_authorization
136- {% if beta_cluster %}
136+ {% if beta_cluster %}
137137 enable_intranode_visibility = var.enable_intranode_visibility
138138 enable_kubernetes_alpha = var.enable_kubernetes_alpha
139139 enable_tpu = var.enable_tpu
@@ -153,6 +153,10 @@ resource "google_container_cluster" "primary" {
153153 }
154154
155155 enable_l4_ilb_subsetting = var.enable_l4_ilb_subsetting
156+ {% endif %}
157+ {% endif %}
158+ {% if autopilot_cluster %}
159+ enable_autopilot = true
156160{% endif %}
157161 dynamic "master_authorized_networks_config" {
158162 for_each = local.master_authorized_networks_config
@@ -181,14 +185,15 @@ resource "google_container_cluster" "primary" {
181185 horizontal_pod_autoscaling {
182186 disabled = !var.horizontal_pod_autoscaling
183187 }
184-
188+ {% if autopilot_cluster != true %}
185189 network_policy_config {
186190 disabled = !var.network_policy
187191 }
188- {% if beta_cluster %}
192+ {% endif %}
193+ {% if beta_cluster and autopilot_cluster != true %}
189194
190195 istio_config {
191- disabled = ! var.istio
196+ disabled = !var.istio
192197 auth = var.istio_auth
193198 }
194199
@@ -258,24 +263,25 @@ resource "google_container_cluster" "primary" {
258263 end_time = maintenance_exclusion.value.end_time
259264 }
260265 }
261-
262266 {% else %}
263267 daily_maintenance_window {
264268 start_time = var.maintenance_start_time
265269 }
266270 {% endif %}
267271 }
268272
273+ {% if autopilot_cluster != true %}
269274 lifecycle {
270275 ignore_changes = [node_pool, initial_node_count, resource_labels["asmv"], resource_labels["mesh_id"]]
271276 }
277+ {% endif %}
272278
273279 timeouts {
274280 create = "45m"
275281 update = "45m"
276282 delete = "45m"
277283 }
278-
284+ {% if autopilot_cluster != true %}
279285 node_pool {
280286 name = "default-pool"
281287 initial_node_count = var.initial_node_count
@@ -321,6 +327,7 @@ resource "google_container_cluster" "primary" {
321327 }
322328 }
323329 }
330+ {% endif %}
324331
325332 dynamic "resource_usage_export_config" {
326333 for_each = var.resource_usage_export_dataset_id != "" ? [{
@@ -362,6 +369,7 @@ resource "google_container_cluster" "primary" {
362369 }
363370{% endif %}
364371
372+ {% if autopilot_cluster != true %}
365373 remove_default_node_pool = var.remove_default_node_pool
366374
367375 dynamic "database_encryption" {
@@ -380,27 +388,30 @@ resource "google_container_cluster" "primary" {
380388 workload_pool = workload_identity_config.value.workload_pool
381389 }
382390 }
391+ {% endif %}
383392
393+ {% if autopilot_cluster != true %}
384394 dynamic "authenticator_groups_config" {
385395 for_each = local.cluster_authenticator_security_group
386396 content {
387397 security_group = authenticator_groups_config.value.security_group
388398 }
389399 }
390-
391- {% if beta_cluster %}
400+ {% endif %}
401+ {% if beta_cluster %}
392402 notification_config {
393403 pubsub {
394404 enabled = var.notification_config_topic != "" ? true : false
395- topic = var.notification_config_topic
405+ topic = var.notification_config_topic
396406 }
397407 }
398- {% endif %}
408+ {% endif %}
399409}
400-
410+ {% if autopilot_cluster != true %}
401411/******************************************
402412 Create Container Cluster node pools
403413 *****************************************/
414+ {% endif %}
404415{% if update_variant %}
405416locals {
406417 force_node_pool_recreation_resources = [
@@ -491,6 +502,7 @@ resource "random_id" "name" {
491502}
492503
493504{% endif %}
505+ {% if autopilot_cluster != true %}
494506resource "google_container_node_pool" "pools" {
495507 {% if beta_cluster %}
496508 provider = google-beta
@@ -698,3 +710,4 @@ resource "google_container_node_pool" "pools" {
698710 delete = "45m"
699711 }
700712}
713+ {% endif %}
0 commit comments