fix: make network offering update work (set the id) and read back correctly - #339
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new acceptance test should include the standard remote existence and destroy verification used elsewhere in the suite, and the domain-id update path’s error/comment text is misleading.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes cloudstack_network_offering updates by ensuring update requests target the correct offering ID and by reading state back through the correct resource read function, preventing failed updates and state corruption.
Changes:
- Set the network offering ID (
p.SetId(d.Id())) on eachUpdateNetworkOfferingparams struct so updates don’t fail withid is null. - Return
resourceCloudStackNetworkOfferingReadfrom the Update path (instead of the instance read) to avoid corrupting state after updates. - Add an acceptance test covering a two-step update of
display_textforcloudstack_network_offering.
File summaries
| File | Description |
|---|---|
| cloudstack/resource_cloudstack_network_offering.go | Fixes update behavior by setting the offering ID on update requests and reading back state via the correct read function. |
| cloudstack/resource_cloudstack_network_offering_test.go | Adds an acceptance test that exercises the update path (create, then update display_text). |
Review details
Suppressed comments (2)
cloudstack/resource_cloudstack_network_offering_test.go:34
- The update acceptance test currently only asserts Terraform state values; it doesn't verify the network offering exists remotely by ID or that it's fully destroyed. Adding an Exists check (per step) and a CheckDestroy improves coverage and helps catch silent cleanup/state drift issues.
func TestAccCloudStackNetworkOffering_update(t *testing.T) {
name := "tf-acc-no-" + resource.UniqueId()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
cloudstack/resource_cloudstack_network_offering_test.go:59
- Add helper functions used by the acceptance test to validate the resource exists in CloudStack (by ID) and is destroyed at the end of the test run.
func testAccNetworkOfferingUpdateConfig(name, displayText string) string {
return fmt.Sprintf(`
resource "cloudstack_network_offering" "foo" {
name = "%s"
display_text = "%s"
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Set the new domain id | ||
| p.SetDomainid(d.Get("domain_id").(string)) | ||
|
|
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| ) |
|
@nagaboinaramgopal please address the copilot's comments |
…rectly resourceCloudStackNetworkOfferingUpdate was broken in two ways: 1. Each UpdateNetworkOffering call built its params with NewUpdateNetworkOfferingParams() but never set the offering id, so every update (name, display_text, max_connections, domain_id) failed with "CloudStack API error 530 ... Cannot invoke java.lang.Long.longValue() because id is null". Set the id on each params struct. 2. After updating, it returned resourceCloudStackInstanceRead, the instance read function, which looks up a VM by the network offering id and corrupts state. Return resourceCloudStackNetworkOfferingRead instead. Adds an acceptance test that creates a network offering and updates its display_text; it fails before this change and passes after. Verified against a CloudStack advanced zone. Signed-off-by: Ramgopal Nagaboina <ramgopal.nagaboina.dev@gmail.com>
a2571fa to
6474f69
Compare
There was a problem hiding this comment.
LGTM Tested manually
resource "cloudstack_network_offering" "test" {
name = "tf-test-offering"
display_text = "initial text"
guest_ip_type = "Isolated"
traffic_type = "Guest"
}
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
+ create
Terraform will perform the following actions:
# cloudstack_network_offering.test will be created
+ resource "cloudstack_network_offering" "test" {
+ display_text = "initial text"
+ guest_ip_type = "Isolated"
+ id = (known after apply)
+ name = "tf-test-offering"
+ traffic_type = "Guest"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_network_offering.test: Creating...
cloudstack_network_offering.test: Creation complete after 1s [id=d32bd0a6-96ae-42fe-8efc-342a7ff46995]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
change the display text parameter
terraform apply
cloudstack_network_offering.test: Refreshing state... [id=d32bd0a6-96ae-42fe-8efc-342a7ff46995]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
~ update in-place
Terraform will perform the following actions:
# cloudstack_network_offering.test will be updated in-place
~ resource "cloudstack_network_offering" "test" {
~ display_text = "initial text" -> "initial text2"
id = "d32bd0a6-96ae-42fe-8efc-342a7ff46995"
name = "tf-test-offering"
# (2 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
cloudstack_network_offering.test: Modifying... [id=d32bd0a6-96ae-42fe-8efc-342a7ff46995]
cloudstack_network_offering.test: Modifications complete after 0s [id=d32bd0a6-96ae-42fe-8efc-342a7ff46995]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
Description
resourceCloudStackNetworkOfferingUpdatewas broken in two ways, and updating acloudstack_network_offeringfailed outright:Each
UpdateNetworkOfferingcall built its params withNewUpdateNetworkOfferingParams()but never set the offering id, so every update (name, display_text, max_connections, domain_id) failed with:Fixed by setting the id on each params struct.
After updating, the function returned
resourceCloudStackInstanceRead, the read function for thecloudstack_instanceresource, which looks up a VM by the network offering id and corrupts the resource state. Fixed to returnresourceCloudStackNetworkOfferingRead, matching the Create and Read paths.Testing
Added an acceptance test
TestAccCloudStackNetworkOffering_updatethat creates a network offering and then updates itsdisplay_text. It fails before this change (theid is nullAPI error) and passes after.Verified end to end against a live CloudStack advanced zone:
go build ./...,go vet ./..., and the unit suite (go test ./cloudstack/) also pass.