terraform-provider-oci icon indicating copy to clipboard operation
terraform-provider-oci copied to clipboard

Move compute instance's capacity reservation id change to the same request as shape

Open b-dean opened this issue 1 year ago • 2 comments

Problem

If I have a compute instance and I want to change both its shape and its capacity reservation (to a different capacity reservation that I know has the new shape available), I can do that in the OCI web UI with a single update to the instance.

However, because of how those attributes are split apart in the terraform provider, it ends up being two different update requests. The first update request, to change the shape will fail, because the current capacity reservation does not have sufficient capacity for the new shape. The update to the new capacity reservation id doesn't happen until a later update request.

I believe, that capacity reservation id belongs in the first update (which contains shape, shape config, platform config, source details, fault domain, and launch options), because reserving capacity is intrinsically tied to the shape and shape config of the instance. You are reserving a specific shape.

Example

In this example there's a capacity reservation with E4 instances and one with E5, and the instance will switch between them. Real world examples would likely be more complex, but the principle is still the same: it should be possible to change both shape and capacity reservation at the same time.

variable "shape_index" {
  type    = number
  default = 0
}

variable "shapes" {
  type = list(string)

  default = [
    "VM.Standard.E4.Flex",
    "VM.Standard.E5.Flex",
  ]
}

resource "oci_core_compute_capacity_reservation" "example" {
  count = length(var.shapes)

  availability_domain = var.availability_domain
  compartment_id      = var.compartment_id
  display_name        = "example-${count.index}"

  instance_reservation_configs {
    instance_shape = var.shapes[count.index]
    reserved_count = 1
    fault_domain   = var.fault_domain

    instance_shape_config {
      memory_in_gbs = 4
      ocpus         = 1
    }
  }
}

resource "oci_core_instance" "example" {
  availability_domain = var.availability_domain
  compartment_id      = var.compartment_id
  fault_domain   = var.fault_domain
  capacity_reservation_id = oci_core_compute_capacity_reservation.example[var.shape_index].id
  display_name            = "example"
  shape                   = var.shapes[var.shape_index]

  shape_config {
    memory_in_gbs = 4
    ocpus         = 1
  }

  # ... other instance config
}

# ... other variables

The first terraform apply puts it in the E4 capacity reservation:

terraform apply -var shape_index=0

The second should change the shape and move it to the new capacity reservation:

terraform apply -var shape_index=1

but it fails:

╷
│ Error: 400-InvalidParameter, Invalid Shape Config: No valid reservation configs in the reservation to move the resize to.
│ Suggestion: Please update the parameter(s) in the Terraform config as per error message Invalid Shape Config: No valid reservation configs in the reservation to move the resize to.
│ Documentation: https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_instance
│ API Reference: https://docs.oracle.com/iaas/api/#/en/iaas/20160918/Instance/UpdateInstance
│ Request Target: PUT https://iaas.us-ashburn-1.oraclecloud.com/20160918/instances/ocid1.instance.oc1.iad.xxxxxxxxxxxxxxxx
│ Provider version: 6.11.0, released on 2024-09-24. This provider is 1 Update(s) behind to current.
│ Service: Core Instance
│ Operation Name: UpdateInstance

Because it's trying to change only the shape, and there aren't any of that shape in the old capacity reservation.

Notes

Also I can't rebase this to the top of master or it won't work because of #2205 causing any change to oci_core_instance resources to fail. But my branch works if I build it based on v6.11.0 instead.

b-dean avatar Oct 07 '24 17:10 b-dean

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA). The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

Thank you for your valuable contribution. We greatly appreciate your efforts in submitting this pull request. However, I regret to inform you that we are unable to merge it directly on GitHub at this time.

Our internal policy requires that all pull requests undergo thorough local testing and review before they can be merged into the main codebase. This process ensures the quality and stability of Terraform-Provider-OCI.

We understand that this may cause some inconvenience, but please rest assured that your contribution is highly valued. Our team will carefully review and test your changes locally to ensure they meet our standards.

We appreciate your understanding and patience in this matter. If you have any questions or need further assistance, please don't hesitate to reach out. Thank you once again for your contribution.

tf-oci-pub avatar Oct 07 '24 20:10 tf-oci-pub

Oracle any chance of picking this up or reviewing? You have released 3 versions now with this bug.

twmcelroy avatar Oct 24 '24 14:10 twmcelroy

Thank you for signing the OCA.

For reference, I've opened SR 4-0000144019 to help move this PR.

b-dean avatar Dec 04 '24 17:12 b-dean

Rejecting this PR as we don't allow direct check-ins.

ganbaras avatar Jan 22 '25 02:01 ganbaras

@ganbaras, what does direct check-ins mean?

What is the correct way to submit a pull request?

b-dean avatar Jan 23 '25 20:01 b-dean