-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata.tf
53 lines (44 loc) · 2.32 KB
/
data.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
locals {
// location
location = var.regional ? var.region : var.zones[0]
region = var.region == null ? join("-", slice(split("-", var.zones[0]), 0, 2)) : var.region
zone_count = length(var.zones)
// Modified to only create regional or zonal clusters (multi-zonal option removed from template)
node_locations = var.regional ? coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result)) : null
// Kubernetes version
min_master_version_regional = var.min_kubernetes_version != "latest" ? var.min_kubernetes_version : data.google_container_engine_versions.region.latest_master_version
min_master_version_zonal = var.min_kubernetes_version != "latest" ? var.min_kubernetes_version : data.google_container_engine_versions.zone.latest_master_version
min_master_version = var.regional ? local.min_master_version_regional : local.min_master_version_zonal
# This variable will be prepended to all related resources
cluster_suffix = var.cluster_name_suffix != "" ? "-${var.cluster_name_suffix}" : ""
# Allow to override project prefix or truncate to prevent resource names longer than 40 characters
project_prefix = var.project_name_override == "" ? substr(var.project_id, 0, 28) : var.project_name_override
cluster_name = "${local.project_prefix}-cluster${local.cluster_suffix}"
}
resource "random_shuffle" "available_zones" {
input = data.google_compute_zones.available.names
result_count = 3
}
/******************************************
Get available zones in region
*****************************************/
data "google_compute_zones" "available" {
provider = google
project = var.project_id
region = local.region
}
/******************************************
Get available container engine versions
*****************************************/
data "google_container_engine_versions" "region" {
location = local.location
project = var.project_id
}
data "google_container_engine_versions" "zone" {
// Work around to prevent a lack of zone declaration from causing regional cluster creation from erroring out due to error
//
// data.google_container_engine_versions.zone: Cannot determine zone: set in this resource, or set provider-level zone.
//
location = local.zone_count == 0 ? data.google_compute_zones.available.names[0] : var.zones[0]
project = var.project_id
}