Move compute instance's capacity reservation id change to the same request as shape #2314
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
terraform-provider-oci/internal/service/core/core_instance_resource.go
Lines 1470 to 1471 in 97b6ff8
The update to the new capacity reservation id doesn't happen until a later update request.
terraform-provider-oci/internal/service/core/core_instance_resource.go
Lines 1504 to 1507 in 97b6ff8
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.
The first terraform apply puts it in the E4 capacity reservation:
The second should change the shape and move it to the new capacity reservation:
but it fails:
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.