|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# |
| 16 | +# Configuration dependencies |
| 17 | +# - shared_config/platform_variables.tf |
| 18 | +# |
| 19 | + |
| 20 | +locals { |
| 21 | + cluster_credentials_command_private = "gcloud container clusters get-credentials ${local.cluster_name} --internal-ip --location ${var.cluster_region} --project ${var.cluster_project_id}" |
| 22 | + cluster_credentials_command_public = "gcloud container clusters get-credentials ${local.cluster_name} --location ${var.cluster_region} --project ${var.cluster_project_id}" |
| 23 | + cluster_credentials_command_gke = var.cluster_enable_private_endpoint ? local.cluster_credentials_command_private : local.cluster_credentials_command_public |
| 24 | + cluster_credentials_command_gkee = "gcloud container fleet memberships get-credentials ${local.cluster_name} --project ${var.cluster_project_id}" |
| 25 | + cluster_credentials_command = var.cluster_use_connect_gateway ? local.cluster_credentials_command_gkee : local.cluster_credentials_command_gke |
| 26 | + cluster_name = local.unique_identifier_prefix |
| 27 | + |
| 28 | + kubeconfig_directory = abspath("${path.module}/../kubeconfig") |
| 29 | + kubeconfig_file = abspath("${local.kubeconfig_directory}/${var.cluster_project_id}-${local.unique_identifier_prefix}") |
| 30 | +} |
| 31 | + |
| 32 | +variable "cluster_binary_authorization_evaluation_mode" { |
| 33 | + default = "DISABLED" |
| 34 | + description = "Mode of operation for Binary Authorization policy evaluation. Valid values are DISABLED and PROJECT_SINGLETON_POLICY_ENFORCE." |
| 35 | + type = string |
| 36 | + |
| 37 | + validation { |
| 38 | + condition = contains( |
| 39 | + [ |
| 40 | + "DISABLED", |
| 41 | + "PROJECT_SINGLETON_POLICY_ENFORCE", |
| 42 | + ], |
| 43 | + var.cluster_binary_authorization_evaluation_mode |
| 44 | + ) |
| 45 | + error_message = "'cluster_binary_authorization_evaluation_mode' value is invalid" |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +variable "cluster_confidential_nodes_enabled" { |
| 50 | + default = false |
| 51 | + description = "Enable Confidential GKE Nodes for this node pool, to enforce encryption of data in-use" |
| 52 | + type = bool |
| 53 | +} |
| 54 | + |
| 55 | +variable "cluster_database_encryption_state" { |
| 56 | + default = "DECRYPTED" |
| 57 | + description = "The desired state of etcd encryption. ENCRYPTED or DECRYPTED" |
| 58 | + type = string |
| 59 | + |
| 60 | + validation { |
| 61 | + condition = contains( |
| 62 | + [ |
| 63 | + "DECRYPTED", |
| 64 | + "ENCRYPTED", |
| 65 | + ], |
| 66 | + var.cluster_database_encryption_state |
| 67 | + ) |
| 68 | + error_message = "'cluster_database_encryption_state' value is invalid" |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +variable "cluster_database_encryption_key_name" { |
| 73 | + default = null |
| 74 | + description = "Name of CloudKMS key to use for the encryption of secrets in etcd. Ex. projects/my-project/locations/global/keyRings/my-ring/cryptoKeys/my-key" |
| 75 | + type = string |
| 76 | +} |
| 77 | + |
| 78 | +variable "cluster_enable_private_endpoint" { |
| 79 | + default = true |
| 80 | + description = "When true, the cluster's private endpoint is used as the cluster endpoint and access through the public endpoint is disabled. When false, either endpoint can be used. This field only applies to private clusters, when enable_private_nodes is true." |
| 81 | + type = bool |
| 82 | +} |
| 83 | + |
| 84 | +variable "cluster_gateway_api_config_channel" { |
| 85 | + default = "CHANNEL_STANDARD" |
| 86 | + description = "Which Gateway Api channel should be used. CHANNEL_DISABLED, CHANNEL_EXPERIMENTAL or CHANNEL_STANDARD" |
| 87 | + type = string |
| 88 | + |
| 89 | + validation { |
| 90 | + condition = contains( |
| 91 | + [ |
| 92 | + "CHANNEL_DISABLED", |
| 93 | + "CHANNEL_EXPERIMENTAL", |
| 94 | + "CHANNEL_STANDARD", |
| 95 | + ], |
| 96 | + var.cluster_gateway_api_config_channel |
| 97 | + ) |
| 98 | + error_message = "'cluster_gateway_api_config_channel' value is invalid" |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +variable "cluster_gpu_driver_version" { |
| 103 | + default = "LATEST" |
| 104 | + description = "Mode for how the GPU driver is installed." |
| 105 | + type = string |
| 106 | + |
| 107 | + validation { |
| 108 | + condition = contains( |
| 109 | + [ |
| 110 | + "DEFAULT", |
| 111 | + "GPU_DRIVER_VERSION_UNSPECIFIED", |
| 112 | + "INSTALLATION_DISABLED", |
| 113 | + "LATEST" |
| 114 | + ], |
| 115 | + var.cluster_gpu_driver_version |
| 116 | + ) |
| 117 | + error_message = "'gpu_driver_version' value is invalid" |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +variable "cluster_master_global_access_enabled" { |
| 122 | + default = false |
| 123 | + description = "Whether the cluster master is accessible globally or not." |
| 124 | + type = bool |
| 125 | +} |
| 126 | + |
| 127 | +variable "cluster_project_id" { |
| 128 | + description = "The GCP project where the cluster resources will be created" |
| 129 | + type = string |
| 130 | + |
| 131 | + validation { |
| 132 | + condition = var.cluster_project_id != "" |
| 133 | + error_message = "'cluster_project_id' was not set, please set the value in the mlp.auto.tfvars file" |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +variable "cluster_region" { |
| 138 | + default = "us-central1" |
| 139 | + description = "Region where cluster resources will be created." |
| 140 | + type = string |
| 141 | + |
| 142 | + validation { |
| 143 | + condition = contains( |
| 144 | + [ |
| 145 | + "us-central1", |
| 146 | + "us-east4", |
| 147 | + ], |
| 148 | + var.cluster_region) |
| 149 | + error_message = "'cluster_region' must be one of ['us-central1', 'us-east4']" |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +variable "cluster_use_connect_gateway" { |
| 154 | + default = true |
| 155 | + description = "UsevConnect gateway to connect to the cluster, require GKE Enterprise." |
| 156 | + type = bool |
| 157 | +} |
0 commit comments