Skip to content

Commit 4df4797

Browse files
committed
fix: resolve duplicate option values in OCI template instance shape parameter
- Fix duplicate option values for VM.Standard.A1.Flex and VM.Standard.E3.Flex shapes - Add dynamic shape configuration handling for flexible shapes - Implement proper OCPU and memory parsing from parameter values - Ensure unique option values while maintaining descriptive names - Template now passes terraform validation without errors
1 parent 1f001f0 commit 4df4797

File tree

1 file changed

+22
-10
lines changed
  • registry/aybanda/templates/oci-linux

1 file changed

+22
-10
lines changed

registry/aybanda/templates/oci-linux/main.tf

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ data "coder_parameter" "instance_shape" {
127127
mutable = false
128128
option {
129129
name = "VM.Standard.A1.Flex (1 OCPU, 6 GB RAM)"
130-
value = "VM.Standard.A1.Flex"
130+
value = "VM.Standard.A1.Flex-1-6"
131131
}
132132
option {
133133
name = "VM.Standard.A1.Flex (2 OCPU, 12 GB RAM)"
134-
value = "VM.Standard.A1.Flex"
134+
value = "VM.Standard.A1.Flex-2-12"
135135
}
136136
option {
137137
name = "VM.Standard.A1.Flex (4 OCPU, 24 GB RAM)"
138-
value = "VM.Standard.A1.Flex"
138+
value = "VM.Standard.A1.Flex-4-24"
139139
}
140140
option {
141141
name = "VM.Standard.E2.1.Micro (1 OCPU, 1 GB RAM)"
@@ -159,15 +159,15 @@ data "coder_parameter" "instance_shape" {
159159
}
160160
option {
161161
name = "VM.Standard.E3.Flex (1 OCPU, 8 GB RAM)"
162-
value = "VM.Standard.E3.Flex"
162+
value = "VM.Standard.E3.Flex-1-8"
163163
}
164164
option {
165165
name = "VM.Standard.E3.Flex (2 OCPU, 16 GB RAM)"
166-
value = "VM.Standard.E3.Flex"
166+
value = "VM.Standard.E3.Flex-2-16"
167167
}
168168
option {
169169
name = "VM.Standard.E3.Flex (4 OCPU, 32 GB RAM)"
170-
value = "VM.Standard.E3.Flex"
170+
value = "VM.Standard.E3.Flex-4-32"
171171
}
172172
}
173173

@@ -228,6 +228,15 @@ data "oci_core_images" "ubuntu" {
228228
locals {
229229
hostname = lower(data.coder_workspace.me.name)
230230
linux_user = "coder"
231+
232+
# Parse shape configuration for flexible shapes
233+
shape_parts = split("-", data.coder_parameter.instance_shape.value)
234+
base_shape = length(local.shape_parts) > 2 ? join("-", slice(local.shape_parts, 0, 3)) : data.coder_parameter.instance_shape.value
235+
ocpus = length(local.shape_parts) > 3 ? tonumber(local.shape_parts[3]) : 1
236+
memory_gb = length(local.shape_parts) > 4 ? tonumber(local.shape_parts[4]) : 6
237+
238+
# Determine if shape is flexible (needs shape_config)
239+
is_flexible = can(regex(".*Flex.*", local.base_shape))
231240
}
232241

233242
# Coder Agent
@@ -430,11 +439,14 @@ resource "oci_core_instance" "dev" {
430439
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
431440
compartment_id = var.compartment_ocid
432441
display_name = "coder-${lower(data.coder_workspace_owner.me.name)}-${lower(data.coder_workspace.me.name)}"
433-
shape = data.coder_parameter.instance_shape.value
442+
shape = local.base_shape
434443

435-
shape_config {
436-
ocpus = 1
437-
memory_in_gbs = 6
444+
dynamic "shape_config" {
445+
for_each = local.is_flexible ? [1] : []
446+
content {
447+
ocpus = local.ocpus
448+
memory_in_gbs = local.memory_gb
449+
}
438450
}
439451

440452
create_vnic_details {

0 commit comments

Comments
 (0)