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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

b-dean
Copy link

@b-dean b-dean commented Mar 4, 2025

Fixes #2313

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.

// Update shape, shape config, platform config, source details, fault domain and launch options
err := s.updateOptionsViaWorkRequest()

The update to the new capacity reservation id doesn't happen until a later update request.

if capacityReservationId, ok := s.D.GetOkExists("capacity_reservation_id"); ok {
tmp := capacityReservationId.(string)
request.CapacityReservationId = &tmp
}

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

I have a complete working example in https://gist.github.com/b-dean/0cccde387e8dcc57167b08e5e45ef80c, which I referenced from #2313

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
  }
}

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.28.0, released on 2025-03-02.
│ Service: Core Instance
│ Operation Name: UpdateInstance
│ OPC request ID: xxxxxxxxxxxxxxxx
│
│
│   with oci_core_instance.example,
│   on main.tf line 46, in resource "oci_core_instance" "example":
│   46: resource "oci_core_instance" "example" {
│

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

When I build a local copy of the provider from this PR it is able to update both shape and capacity reservation at the same time.

…quest as shape

Fixes oracle#2313

Signed-off-by: Ben Dean <ben.dean@finvi.com>
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 4, 2025
@tf-oci-pub tf-oci-pub added the Pending Test Pending Test label for PRs label Mar 5, 2025
@tf-oci-pub
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement. Pending Test Pending Test label for PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot update shape and capacity reservation at the same time
2 participants