forked from GoogleCloudPlatform/cluster-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
89 lines (80 loc) · 3.71 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
# Handle VM image format from 2 sources, prioritize source_image* variables
# over instance_image
source_image_input_used = var.source_image != "" || var.source_image_family != "" || var.source_image_project != ""
source_image = local.source_image_input_used ? var.source_image : lookup(var.instance_image, "name", "")
source_image_family = local.source_image_input_used ? var.source_image_family : lookup(var.instance_image, "family", "")
source_image_project = local.source_image_input_used ? var.source_image_project : lookup(var.instance_image, "project", "")
enable_public_ip_access_config = var.disable_public_ips ? [] : [{ nat_ip = null, network_tier = null }]
access_config = length(var.access_config) == 0 ? local.enable_public_ip_access_config : var.access_config
additional_disks = [
for ad in var.additional_disks : {
disk_name = ad.disk_name
device_name = ad.device_name
disk_type = ad.disk_type
disk_size_gb = ad.disk_size_gb
disk_labels = merge(ad.disk_labels, var.labels)
auto_delete = ad.auto_delete
boot = ad.boot
}
]
node_group = {
# Group Definition
group_name = var.name
node_count_dynamic_max = var.node_count_dynamic_max
node_count_static = var.node_count_static
node_conf = var.node_conf
# Template By Definition
additional_disks = local.additional_disks
bandwidth_tier = var.bandwidth_tier
can_ip_forward = var.can_ip_forward
disable_smt = !var.enable_smt
disk_auto_delete = var.disk_auto_delete
disk_labels = merge(var.labels, var.disk_labels)
disk_size_gb = var.disk_size_gb
disk_type = var.disk_type
enable_confidential_vm = var.enable_confidential_vm
enable_oslogin = var.enable_oslogin
enable_shielded_vm = var.enable_shielded_vm
gpu = var.gpu != null ? var.gpu : one(local.guest_accelerator)
labels = var.labels
machine_type = var.machine_type
metadata = var.metadata
min_cpu_platform = var.min_cpu_platform
on_host_maintenance = var.on_host_maintenance
preemptible = var.preemptible
shielded_instance_config = var.shielded_instance_config
source_image_family = local.source_image_family
source_image_project = local.source_image_project
source_image = local.source_image
tags = var.tags
access_config = local.access_config
service_account = var.service_account != null ? var.service_account : {
email = data.google_compute_default_service_account.default.email
scopes = ["https://www.googleapis.com/auth/cloud-platform"]
}
# Spot VM settings
enable_spot_vm = var.enable_spot_vm
spot_instance_config = var.spot_instance_config
# Template By Source
instance_template = var.instance_template
}
}
data "google_compute_default_service_account" "default" {
project = var.project_id
}