Skip to content

Commit ce97bdd

Browse files
committed
terraform/OCI: Create a set of multiple generic block devices
When provisioning on OCI, terraform creates one block device for the /data file system, and one for sparse files. This is unlike other provisioning methods (guestfs and AWS being the primary examples) which instead create a set of generic block devices and then set up the sparse files or /data file system on one of those. Luis and Chandan have agreed to changing OCI to work like the other terraform providers and guestfs. Reviewed-by: Luis Chamberlain <[email protected]> Reviewed-by: Chandan Babu R <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 378d8fe commit ce97bdd

File tree

5 files changed

+208
-5
lines changed

5 files changed

+208
-5
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ oci_os_image_ocid = "{{ terraform_oci_os_image_ocid }}"
1212
oci_assign_public_ip = "{{ terraform_oci_assign_public_ip | lower }}"
1313
oci_instance_display_name = "{{ terraform_oci_instance_display_name }}"
1414
oci_subnet_ocid = "{{ terraform_oci_subnet_ocid }}"
15+
oci_volumes_enable_extra = "{{ terraform_oci_volumes_enable_extra | lower }}"
16+
{% if terraform_oci_volumes_enable_extra %}
17+
oci_volumes_per_instance = {{ terraform_oci_volumes_per_instance }}
18+
oci_volumes_size = {{ terraform_oci_volumes_size }}
19+
{% else %}
1520
oci_data_volume_display_name = "{{ terraform_oci_data_volume_display_name }}"
1621
oci_data_volume_device_file_name = "{{ terraform_oci_data_volume_device_file_name }}"
1722
oci_sparse_volume_display_name = "{{ terraform_oci_sparse_volume_display_name }}"
1823
oci_sparse_volume_device_file_name = "{{ terraform_oci_sparse_volume_device_file_name }}"
24+
{% endif %}
1925

2026
ssh_config_pubkey_file = "{{ kdevops_terraform_ssh_config_pubkey_file }}"
2127
ssh_config_user = "{{ kdevops_terraform_ssh_config_user }}"

scripts/terraform.Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,17 @@ else
105105
TERRAFORM_EXTRA_VARS += terraform_oci_assign_public_ip=false
106106
endif
107107
TERRAFORM_EXTRA_VARS += terraform_oci_subnet_ocid=$(subst ",,$(CONFIG_TERRAFORM_OCI_SUBNET_OCID))
108+
109+
ifeq (y, $(CONFIG_TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA))
110+
TERRAFORM_EXTRA_VARS += terraform_oci_volumes_enable_extra=true
111+
else
112+
TERRAFORM_EXTRA_VARS += terraform_oci_volumes_enable_extra=false
108113
TERRAFORM_EXTRA_VARS += terraform_oci_data_volume_display_name=$(subst ",,$(CONFIG_TERRAFORM_OCI_DATA_VOLUME_DISPLAY_NAME))
109-
TERRAFORM_EXTRA_VARS += terraform_oci_data_volume_device_file_name=$(subst ",,$(CONFIG_TERRAFORM_OCI_DATA_VOLUME_DEVICE_FILE_NAME))
110114
TERRAFORM_EXTRA_VARS += terraform_oci_sparse_volume_display_name=$(subst ",,$(CONFIG_TERRAFORM_OCI_SPARSE_VOLUME_DISPLAY_NAME))
115+
endif
116+
TERRAFORM_EXTRA_VARS += terraform_oci_data_volume_device_file_name=$(subst ",,$(CONFIG_TERRAFORM_OCI_DATA_VOLUME_DEVICE_FILE_NAME))
111117
TERRAFORM_EXTRA_VARS += terraform_oci_sparse_volume_device_file_name=$(subst ",,$(CONFIG_TERRAFORM_OCI_SPARSE_VOLUME_DEVICE_FILE_NAME))
118+
112119
endif
113120

114121
ifeq (y,$(CONFIG_TERRAFORM_OPENSTACK))

terraform/oci/Kconfig

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,153 @@ config TERRAFORM_OCI_SUBNET_OCID
9090
Read this:
9191
https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformproviderconfiguration.htm
9292

93+
config TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
94+
bool "Enable additional block devices"
95+
default n
96+
help
97+
Enable this to provision up to 10 extra block devices
98+
on each target node.
99+
100+
if TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
101+
102+
choice
103+
prompt "Count of extra block volumes"
104+
default TERRAFORM_OCI_VOLUMES_PER_INSTANCE_4
105+
help
106+
The count of extra block devices attached to each target
107+
node.
108+
109+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_2
110+
bool "2"
111+
help
112+
Provision 2 extra volumes per target node.
113+
114+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_3
115+
bool "3"
116+
help
117+
Provision 3 extra volumes per target node.
118+
119+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_4
120+
bool "4"
121+
help
122+
Provision 4 extra volumes per target node.
123+
124+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_5
125+
bool "5"
126+
help
127+
Provision 5 extra volumes per target node.
128+
129+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_6
130+
bool "6"
131+
help
132+
Provision 6 extra volumes per target node.
133+
134+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_7
135+
bool "7"
136+
help
137+
Provision 7 extra volumes per target node.
138+
139+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_8
140+
bool "8"
141+
help
142+
Provision 8 extra volumes per target node.
143+
144+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_9
145+
bool "9"
146+
help
147+
Provision 9 extra volumes per target node.
148+
149+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE_10
150+
bool "10"
151+
help
152+
Provision 10 extra volumes per target node.
153+
154+
endchoice
155+
156+
config TERRAFORM_OCI_VOLUMES_PER_INSTANCE
157+
int
158+
output yaml
159+
default 2 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_2
160+
default 3 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_3
161+
default 4 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_4
162+
default 5 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_5
163+
default 6 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_6
164+
default 7 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_7
165+
default 8 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_8
166+
default 9 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_9
167+
default 10 if TERRAFORM_OCI_VOLUMES_PER_INSTANCE_10
168+
169+
choice
170+
prompt "Volume size for each additional volume"
171+
default TERRAFORM_OCI_VOLUMES_SIZE_50G
172+
help
173+
OCI implements volume sizes between 50G and 32T. In some
174+
cases, 50G volumes are in the free tier.
175+
176+
config TERRAFORM_OCI_VOLUMES_SIZE_50G
177+
bool "50G"
178+
help
179+
Extra block volumes are 50 GiB in size.
180+
181+
config TERRAFORM_OCI_VOLUMES_SIZE_64G
182+
bool "64G"
183+
help
184+
Extra block volumes are 64 GiB in size.
185+
186+
config TERRAFORM_OCI_VOLUMES_SIZE_128G
187+
bool "128G"
188+
help
189+
Extra block volumes are 128 GiB in size.
190+
191+
config TERRAFORM_OCI_VOLUMES_SIZE_256G
192+
bool "256G"
193+
help
194+
Extra block volumes are 256 GiB in size.
195+
196+
config TERRAFORM_OCI_VOLUMES_SIZE_512G
197+
bool "512G"
198+
help
199+
Extra block volumes are 512 GiB in size.
200+
201+
config TERRAFORM_OCI_VOLUMES_SIZE_1024G
202+
bool "1024G"
203+
help
204+
Extra block volumes are 1024 GiB in size.
205+
206+
config TERRAFORM_OCI_VOLUMES_SIZE_2048G
207+
bool "2048G"
208+
help
209+
Extra block volumes are 2048 GiB in size.
210+
211+
config TERRAFORM_OCI_VOLUMES_SIZE_4096G
212+
bool "4096G"
213+
help
214+
Extra block volumes are 4096 GiB in size.
215+
216+
config TERRAFORM_OCI_VOLUMES_SIZE_8192G
217+
bool "8192G"
218+
help
219+
Extra block volumes are 8192 GiB in size.
220+
221+
endchoice
222+
223+
config TERRAFORM_OCI_VOLUMES_SIZE
224+
int
225+
output yaml
226+
default 50 if TERRAFORM_OCI_VOLUMES_SIZE_50G
227+
default 64 if TERRAFORM_OCI_VOLUMES_SIZE_64G
228+
default 128 if TERRAFORM_OCI_VOLUMES_SIZE_128G
229+
default 256 if TERRAFORM_OCI_VOLUMES_SIZE_256G
230+
default 512 if TERRAFORM_OCI_VOLUMES_SIZE_512G
231+
default 1024 if TERRAFORM_OCI_VOLUMES_SIZE_1024G
232+
default 2048 if TERRAFORM_OCI_VOLUMES_SIZE_2048G
233+
default 4096 if TERRAFORM_OCI_VOLUMES_SIZE_4096G
234+
default 8192 if TERRAFORM_OCI_VOLUMES_SIZE_8192G
235+
236+
endif # TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
237+
238+
if !TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
239+
93240
config TERRAFORM_OCI_DATA_VOLUME_DISPLAY_NAME
94241
string "Display name to use for the data volume"
95242
default "data"
@@ -98,6 +245,8 @@ config TERRAFORM_OCI_DATA_VOLUME_DISPLAY_NAME
98245
Read this:
99246
https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformproviderconfiguration.htm
100247

248+
endif # !TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
249+
101250
config TERRAFORM_OCI_DATA_VOLUME_DEVICE_FILE_NAME
102251
string "Data volume's device file name"
103252
default "/dev/oracleoci/oraclevdb"
@@ -106,6 +255,8 @@ config TERRAFORM_OCI_DATA_VOLUME_DEVICE_FILE_NAME
106255
Read this:
107256
https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformproviderconfiguration.htm
108257

258+
if !TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
259+
109260
config TERRAFORM_OCI_SPARSE_VOLUME_DISPLAY_NAME
110261
string "Display name to use for the sparse volume"
111262
default "sparse"
@@ -114,6 +265,8 @@ config TERRAFORM_OCI_SPARSE_VOLUME_DISPLAY_NAME
114265
Read this:
115266
https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformproviderconfiguration.htm
116267

268+
endif # !TERRAFORM_OCI_VOLUMES_ENABLE_EXTRA
269+
117270
config TERRAFORM_OCI_SPARSE_VOLUME_DEVICE_FILE_NAME
118271
string "Sparse volume's device file name"
119272
default "/dev/oracleoci/oraclevdc"

terraform/oci/main.tf

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "oci_core_instance" "kdevops_instance" {
2828
}
2929

3030
resource "oci_core_volume" "kdevops_data_disk" {
31-
count = local.kdevops_num_boxes
31+
count = var.oci_volumes_enable_extra == "true" ? 0 : local.kdevops_num_boxes
3232

3333
compartment_id = var.oci_compartment_ocid
3434

@@ -38,7 +38,7 @@ resource "oci_core_volume" "kdevops_data_disk" {
3838
}
3939

4040
resource "oci_core_volume" "kdevops_sparse_disk" {
41-
count = local.kdevops_num_boxes
41+
count = var.oci_volumes_enable_extra == "true" ? 0 : local.kdevops_num_boxes
4242

4343
compartment_id = var.oci_compartment_ocid
4444

@@ -48,7 +48,7 @@ resource "oci_core_volume" "kdevops_sparse_disk" {
4848
}
4949

5050
resource "oci_core_volume_attachment" "kdevops_data_volume_attachment" {
51-
count = local.kdevops_num_boxes
51+
count = var.oci_volumes_enable_extra == "true" ? 0 : local.kdevops_num_boxes
5252

5353
attachment_type = "paravirtualized"
5454
instance_id = element(oci_core_instance.kdevops_instance.*.id, count.index)
@@ -58,11 +58,31 @@ resource "oci_core_volume_attachment" "kdevops_data_volume_attachment" {
5858
}
5959

6060
resource "oci_core_volume_attachment" "kdevops_sparse_disk_attachment" {
61-
count = local.kdevops_num_boxes
61+
count = var.oci_volumes_enable_extra == "true" ? 0 : local.kdevops_num_boxes
6262

6363
attachment_type = "paravirtualized"
6464
instance_id = element(oci_core_instance.kdevops_instance.*.id, count.index)
6565
volume_id = element(oci_core_volume.kdevops_sparse_disk.*.id, count.index)
6666

6767
device = var.oci_sparse_volume_device_file_name
6868
}
69+
70+
resource "oci_core_volume" "kdevops_volume_extra" {
71+
count = var.oci_volumes_enable_extra == "false" ? 0 : local.kdevops_num_boxes * var.oci_volumes_per_instance
72+
availability_domain = var.oci_availablity_domain
73+
display_name = format("kdevops_volume%02d", count.index + 1)
74+
compartment_id = var.oci_compartment_ocid
75+
size_in_gbs = var.oci_volumes_size
76+
}
77+
78+
locals {
79+
volume_name_suffixes = [ "b", "c", "d", "e", "f", "g", "h", "i", "j", "k" ]
80+
}
81+
82+
resource "oci_core_volume_attachment" "kdevops_volume_extra_att" {
83+
count = var.oci_volumes_enable_extra == "false" ? 0 : local.kdevops_num_boxes * var.oci_volumes_per_instance
84+
attachment_type = "paravirtualized"
85+
instance_id = element(oci_core_instance.kdevops_instance.*.id, count.index)
86+
volume_id = element(oci_core_volume.kdevops_volume_extra.*.id, count.index)
87+
device = format("/dev/oracleoci/oraclevd%s", element(local.volume_name_suffixes, count.index))
88+
}

terraform/oci/vars.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ variable "oci_subnet_ocid" {
7070
default = ""
7171
}
7272

73+
variable "oci_volumes_enable_extra" {
74+
description = "Create additional block volumes per instance"
75+
default = false
76+
}
77+
78+
variable "oci_volumes_per_instance" {
79+
description = "The count of additional block volumes per instance"
80+
type = number
81+
default = 0
82+
}
83+
84+
variable "oci_volumes_size" {
85+
description = "The size of additional block volumes, in gibibytes"
86+
type = number
87+
default = 0
88+
}
89+
7390
variable "oci_data_volume_display_name" {
7491
description = "Display name to use for the data volume"
7592
default = "data"

0 commit comments

Comments
 (0)