Skip to content

Commit 6f7828f

Browse files
committed
terraform/GCE: Provision a set of extra disks
Instead of setting up two scratch disks, provision a group of extra attached disks (up to 10), just as the other kdevops providers do. Signed-off-by: Chuck Lever <[email protected]>
1 parent b4b7556 commit 6f7828f

File tree

7 files changed

+313
-24
lines changed

7 files changed

+313
-24
lines changed

playbooks/roles/gen_tfvars/templates/gce/terraform.tfvars.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ gce_image_project = "{{ terraform_gce_image_project }}"
77
gce_image_family = "{{ terraform_gce_image_family }}"
88
gce_image_size = "{{ terraform_gce_image_size }}"
99
gce_image_type = "{{ terraform_gce_image_type }}"
10-
scratch_disk_interface = "{{ terraform_gce_scatch_disk_type }}"
10+
gce_disk_count = {{ terraform_gce_disk_count }}
11+
gce_disk_size = {{ terraform_gce_disk_size }}
12+
gce_disk_type = "{{ terraform_gce_disk_type }}"
13+
{% if terraform_gce_disk_iops is defined %}
14+
gce_disk_iops = {{ terraform_gce_disk_iops }}
15+
{% endif %}
16+
{% if terraform_gce_disk_throughput is defined %}
17+
gce_disk_throughput = {{ terraform_gce_disk_throughput }}
18+
{% endif %}
1119

1220
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
1321
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"

scripts/terraform.Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ TERRAFORM_EXTRA_VARS += terraform_azure_subscription_id=$(subst ",,$(CONFIG_TERR
8585
TERRAFORM_EXTRA_VARS += terraform_azure_tenant_id=$(subst ",,$(CONFIG_TERRAFORM_AZURE_TENANT_ID))
8686
endif
8787

88-
ifeq (y,$(CONFIG_TERRAFORM_GCE))
89-
TERRAFORM_EXTRA_VARS += terraform_gce_scatch_disk_type=$(subst ",,$(CONFIG_TERRAFORM_GCE_SCRATCH_DISK_INTERFACE))
90-
endif
91-
9288
ifeq (y,$(CONFIG_TERRAFORM_OCI))
9389
TERRAFORM_EXTRA_VARS += terraform_oci_region=$(subst ",,$(CONFIG_TERRAFORM_OCI_REGION))
9490
TERRAFORM_EXTRA_VARS += terraform_oci_tenancy_ocid=$(subst ",,$(CONFIG_TERRAFORM_OCI_TENANCY_OCID))
Lines changed: 206 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,211 @@
1-
config TERRAFORM_GCE_SCRATCH_DISK_INTERFACE
2-
string "GCE scratch disk interface to use"
3-
default "NVME"
1+
choice
2+
prompt "Count of attached disks per instance"
3+
default TERRAFORM_GCE_DISK_COUNT_2
4+
5+
config TERRAFORM_GCE_DISK_COUNT_0
6+
bool "No persistent disks"
7+
8+
config TERRAFORM_GCE_DISK_COUNT_1
9+
bool "1 persistent disk"
10+
11+
config TERRAFORM_GCE_DISK_COUNT_2
12+
bool "2 persistent disks"
13+
14+
config TERRAFORM_GCE_DISK_COUNT_3
15+
bool "3 persistent disks"
16+
17+
config TERRAFORM_GCE_DISK_COUNT_4
18+
bool "4 persistent disks"
19+
20+
config TERRAFORM_GCE_DISK_COUNT_5
21+
bool "5 persistent disks"
22+
23+
config TERRAFORM_GCE_DISK_COUNT_6
24+
bool "6 persistent disks"
25+
26+
config TERRAFORM_GCE_DISK_COUNT_7
27+
bool "7 persistent disks"
28+
29+
config TERRAFORM_GCE_DISK_COUNT_8
30+
bool "8 persistent disks"
31+
32+
endchoice
33+
34+
config TERRAFORM_GCE_DISK_COUNT
35+
int
36+
output yaml
37+
default 0 if TERRAFORM_GCE_DISK_COUNT_0
38+
default 1 if TERRAFORM_GCE_DISK_COUNT_1
39+
default 2 if TERRAFORM_GCE_DISK_COUNT_2
40+
default 3 if TERRAFORM_GCE_DISK_COUNT_3
41+
default 4 if TERRAFORM_GCE_DISK_COUNT_4
42+
default 5 if TERRAFORM_GCE_DISK_COUNT_5
43+
default 6 if TERRAFORM_GCE_DISK_COUNT_6
44+
default 7 if TERRAFORM_GCE_DISK_COUNT_7
45+
default 8 if TERRAFORM_GCE_DISK_COUNT_8
46+
47+
config TERRAFORM_GCE_DISK_NEEDS_IOPS
48+
bool
49+
default n
50+
51+
config TERRAFORM_GCE_DISK_NEEDS_THROUGHPUT
52+
bool
53+
default n
54+
55+
choice
56+
prompt "Performance class of attached disks"
57+
default TERRAFORM_GCE_DISK_TYPE_PD_BALANCED
58+
help
59+
Select the type of disk that is attached to your
60+
instances. Note: A performance class selection might not
61+
be supported by all machine families.
62+
63+
config TERRAFORM_GCE_DISK_TYPE_PD_BALANCED
64+
bool "Balanced Persistent Disk"
65+
help
66+
For most VM shapes, except very large ones, these disks
67+
have the same maximum IOPS as SSD Persistent Disk and
68+
lower IOPS per GiB. This disk type offers performance
69+
levels suitable for most general-purpose applications
70+
at a price point between that of standard and performance
71+
(pd-ssd) Persistent Disk.
72+
73+
Backed by solid-state drives (SSD).
74+
75+
config TERRAFORM_GCE_DISK_TYPE_PD_SSD
76+
bool "Performance Persistent Disk"
77+
help
78+
Suitable for enterprise applications and high-performance
79+
databases that require lower latency and more IOPS than
80+
standard Persistent Disk provides.
81+
82+
Backed by solid-state drives (SSD).
83+
84+
config TERRAFORM_GCE_DISK_TYPE_PD_STANDARD
85+
bool "Standard Persistent Disk"
86+
help
87+
Suitable for large data processing workloads that primarily
88+
use sequential I/Os.
89+
90+
Backed by standard hard disk drives (HDD).
91+
92+
config TERRAFORM_GCE_DISK_TYPE_PD_EXTREME
93+
bool "Extreme Persistent Disk"
94+
select TERRAFORM_GCE_DISK_NEEDS_IOPS
495
help
5-
This option will set GCE scratch disk interface.
96+
Offers consistently high performance for both random
97+
access workloads and bulk throughput. Designed for
98+
high-end database workloads.
99+
100+
Backed by solid-state drives (SSD).
101+
102+
config TERRAFORM_GCE_DISK_TYPE_HYPERDISK_BALANCED
103+
bool "Hyperdisk Balanced"
104+
select TERRAFORM_GCE_DISK_NEEDS_IOPS
105+
select TERRAFORM_GCE_DISK_NEEDS_THROUGHPUT
106+
help
107+
Hyperdisk Balanced is a good fit for a wide range of use
108+
cases such as LOB applications, web applications, and
109+
medium-tier databases that don't require the performance
110+
of Hyperdisk Extreme.
111+
112+
config TERRAFORM_GCE_DISK_TYPE_HYPERDISK_EXTREME
113+
bool "Hyperdisk Extreme"
114+
select TERRAFORM_GCE_DISK_NEEDS_IOPS
115+
select TERRAFORM_GCE_DISK_NEEDS_THROUGHPUT
116+
help
117+
Use Hyperdisk Extreme if Extreme Persistent Disk isn't
118+
supported or doesn't provide enough performance. Hyperdisk
119+
Extreme disks feature higher maximum IOPS and throughput
120+
along with low sub-millisecond latencies, and offer high
121+
performance for the most demanding workloads, such as high
122+
performance databases.
123+
124+
config TERRAFORM_GCE_DISK_TYPE_HYPERDISK_THROUGHPUT
125+
bool "Hyperdisk Throughput"
126+
help
127+
For scale-out analytics workloads like Hadoop and Kafka,
128+
cold storage, and data drives for cost sensitive apps, use
129+
Hyperdisk Throughput.
130+
131+
endchoice
132+
133+
config TERRAFORM_GCE_DISK_TYPE
134+
string
135+
output yaml
136+
default "pd-balanced" if TERRAFORM_GCE_DISK_TYPE_PD_BALANCED
137+
default "pd-ssd" if TERRAFORM_GCE_DISK_TYPE_PD_SSD
138+
default "pd-standard" if TERRAFORM_GCE_DISK_TYPE_PD_STANDARD
139+
default "pd-extreme" if TERRAFORM_GCE_DISK_TYPE_PD_EXTREME
140+
default "hyperdisk-balanced" if TERRAFORM_GCE_DISK_TYPE_HYPERDISK_BALANCED
141+
default "hyperdisk-extreme" if TERRAFORM_GCE_DISK_TYPE_HYPERDISK_EXTREME
142+
default "hyperdisk-throughput" if TERRAFORM_GCE_DISK_TYPE_HYPERDISK_THROUGHPUT
143+
144+
choice
145+
prompt "Size of each attached disk, in GB"
146+
default TERRAFORM_GCE_DISK_SIZE_128GB
147+
148+
config TERRAFORM_GCE_DISK_SIZE_8GB
149+
bool "8 GB"
150+
151+
config TERRAFORM_GCE_DISK_SIZE_16GB
152+
bool "16 GB"
153+
154+
config TERRAFORM_GCE_DISK_SIZE_32GB
155+
bool "32 GB"
156+
157+
config TERRAFORM_GCE_DISK_SIZE_64GB
158+
bool "64 GB"
159+
160+
config TERRAFORM_GCE_DISK_SIZE_128GB
161+
bool "128 GB"
162+
163+
config TERRAFORM_GCE_DISK_SIZE_256GB
164+
bool "256 GB"
165+
166+
config TERRAFORM_GCE_DISK_SIZE_512GB
167+
bool "512 GB"
168+
169+
config TERRAFORM_GCE_DISK_SIZE_1024GB
170+
bool "1024 GB"
171+
172+
config TERRAFORM_GCE_DISK_SIZE_2048GB
173+
bool "2048 GB"
174+
175+
config TERRAFORM_GCE_DISK_SIZE_4096GB
176+
bool "4096 GB"
177+
178+
endchoice
179+
180+
config TERRAFORM_GCE_DISK_SIZE
181+
int
182+
output yaml
183+
default 8 if TERRAFORM_GCE_DISK_SIZE_8GB
184+
default 16 if TERRAFORM_GCE_DISK_SIZE_16GB
185+
default 32 if TERRAFORM_GCE_DISK_SIZE_32GB
186+
default 64 if TERRAFORM_GCE_DISK_SIZE_64GB
187+
default 128 if TERRAFORM_GCE_DISK_SIZE_128GB
188+
default 256 if TERRAFORM_GCE_DISK_SIZE_256GB
189+
default 512 if TERRAFORM_GCE_DISK_SIZE_512GB
190+
default 1024 if TERRAFORM_GCE_DISK_SIZE_1024GB
191+
default 2048 if TERRAFORM_GCE_DISK_SIZE_2048GB
192+
default 4096 if TERRAFORM_GCE_DISK_SIZE_4096GB
193+
194+
config TERRAFORM_GCE_DISK_IOPS
195+
int "Provisioned IOPS for each attached disk"
196+
output yaml
197+
range 125 120000
198+
default 240
199+
depends on TERRAFORM_GCE_DISK_NEEDS_IOPS
6200

7-
Documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#scratch_disk
201+
config TERRAFORM_GCE_DISK_THROUGHPUT
202+
int "Provisioned throughput for each attached disk"
203+
output yaml
204+
range 125 600
205+
default 240
206+
depends on TERRAFORM_GCE_DISK_NEEDS_THROUGHPUT
8207

9208
config TERRAFORM_GCE_DATA_VOLUME_DEVICE_FILE_NAME
10209
string
11-
default "/dev/nvme0n1"
210+
output yaml
211+
default "/dev/disk/by-id/google-persistent-disk-1"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
resource "google_compute_disk" "kdevops_disk" {
2+
count = var.cd_disk_count
3+
name = format("disk-%s-%02d", var.cd_instance_name, count.index)
4+
provisioned_iops = var.cd_disk_iops
5+
provisioned_throughput = var.cd_disk_throughput
6+
type = var.cd_disk_type
7+
size = var.cd_disk_size
8+
zone = var.cd_zone
9+
}
10+
11+
resource "google_compute_attached_disk" "kdevops_attached_disk" {
12+
count = var.cd_disk_count
13+
disk = google_compute_disk.kdevops_disk[count.index].id
14+
instance = var.cd_instance_id
15+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "cd_disk_count" {
2+
description = "Count of attached disks per instance"
3+
type = number
4+
}
5+
6+
variable "cd_disk_iops" {
7+
description = "Provisioned IOPS for each attached disk"
8+
type = number
9+
}
10+
11+
variable "cd_disk_size" {
12+
description = "Size of each attached disk, in GB"
13+
type = number
14+
}
15+
16+
variable "cd_disk_throughput" {
17+
description = "Provisioned throughput for each attached disk"
18+
type = number
19+
}
20+
21+
variable "cd_disk_type" {
22+
description = "Performance class of attached disks"
23+
type = string
24+
}
25+
26+
variable "cd_instance_id" {
27+
description = "Instance ID of instance to which to attach disks"
28+
type = string
29+
}
30+
31+
variable "cd_instance_name" {
32+
description = "Instance name of instance to which to attach disks"
33+
type = string
34+
}
35+
36+
variable "cd_zone" {
37+
description = "Availability zone in which disks are to reside"
38+
type = string
39+
}

terraform/gce/main.tf

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ resource "google_compute_instance" "kdevops_instance" {
1919
}
2020
}
2121

22-
scratch_disk {
23-
interface = var.scratch_disk_interface
24-
}
25-
26-
scratch_disk {
27-
interface = var.scratch_disk_interface
28-
}
29-
3022
network_interface {
3123
network = "default"
3224

@@ -35,9 +27,26 @@ resource "google_compute_instance" "kdevops_instance" {
3527
}
3628
}
3729

30+
lifecycle {
31+
ignore_changes = [attached_disk]
32+
}
33+
3834
metadata = {
3935
ssh-keys = format("%s:%s", var.ssh_config_user, file(var.ssh_config_pubkey_file))
4036
}
4137

4238
metadata_startup_script = "echo hi > /test.txt"
4339
}
40+
41+
module "kdevops_compute_disks" {
42+
count = local.kdevops_num_boxes
43+
cd_disk_count = var.gce_disk_count
44+
cd_disk_iops = var.gce_disk_iops
45+
cd_disk_size = var.gce_disk_size
46+
cd_disk_throughput = var.gce_disk_throughput
47+
cd_disk_type = var.gce_disk_type
48+
cd_instance_id = google_compute_instance.kdevops_instance[count.index].id
49+
cd_instance_name = element(var.kdevops_nodes, count.index)
50+
cd_zone = var.gce_zone
51+
source = "./kdevops_compute_disks"
52+
}

terraform/gce/vars.tf

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ variable "gce_credentials" {
33
type = string
44
}
55

6+
variable "gce_disk_count" {
7+
description = "Count of attached disks per instance"
8+
type = number
9+
}
10+
11+
variable "gce_disk_iops" {
12+
description = "Provisioned IOPS for each attached disk"
13+
type = number
14+
default = null
15+
}
16+
17+
variable "gce_disk_size" {
18+
description = "Size of each attached disk, in GB"
19+
type = number
20+
}
21+
22+
variable "gce_disk_throughput" {
23+
description = "Provisioned throughput for each attached disk"
24+
type = number
25+
default = null
26+
}
27+
28+
variable "gce_disk_type" {
29+
description = "Performance class of attached disks"
30+
type = string
31+
}
32+
633
variable "gce_image_family" {
734
description = "Release of Linux distribution"
835
type = string
@@ -42,8 +69,3 @@ variable "gce_zone" {
4269
description = "Availability zone"
4370
type = string
4471
}
45-
46-
variable "scratch_disk_interface" {
47-
description = "The type of interface for the scratch disk, SCSI, or NVME"
48-
type = string
49-
}

0 commit comments

Comments
 (0)