Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Additional Block Volume is targeted for change when var.block_storage_sizes_in_gbs is updated #57

Open
kral2 opened this issue Mar 16, 2021 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@kral2
Copy link
Contributor

kral2 commented Mar 16, 2021

var.block_storage_sizes_in_gbs is a list of numbers where one BV is created for each element, with BV size is equal to the passed number.

Having a list is problematic when we need an update:

  • removing an element change the index number of each element in the collection
  • wrong BV gets modification (BV delete is possible ...).

The example below will create 3 volumes named xxx_volume0,xxx_volume1,xxx_volume2.

resource "oci_core_volume" "this" {
  count               = var.instance_count * length(var.block_storage_sizes_in_gbs)
  availability_domain = oci_core_instance.this[count.index % var.instance_count].availability_domain
  compartment_id      = var.compartment_ocid
  display_name        = "${oci_core_instance.this[count.index % var.instance_count].display_name}_volume${floor(count.index / var.instance_count)}"
  size_in_gbs = element(
    var.block_storage_sizes_in_gbs,
    floor(count.index / var.instance_count),
  )
  freeform_tags = local.merged_freeform_tags
  defined_tags  = var.defined_tags
}

variable "block_storage_sizes_in_gbs" {
  description = "Sizes of volumes to create and attach to each instance."
  type        = list(number)
  default     = [50,55,56]
}

If var.block_storage_sizes_in_gbs is edited, removing 55 from the list for example:

  • instead of having xxx_volume1 removed, Terraform will remove xxx_volume2 and update size of xxx_volume1 (when possible),
  • whereas the initial intention was to remove xxx_volume1 but not touch xxx_volume0 and xxx_volume2.

To have a consistent behavior, the logic behind var.block_storage_sizes_in_gbs needs to be rewritten using a for_each implementation.

@kral2 kral2 added the bug Something isn't working label Mar 16, 2021
@kral2 kral2 changed the title Wrong Additional Block Volume gets updated when var.block_storage_sizes_in_gbs is updated Wrong Additional Block Volume is targeted for change when var.block_storage_sizes_in_gbs is updated Mar 16, 2021
@kral2 kral2 added this to the Future milestone Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant