Skip to content

fix: make network offering update work (set the id) and read back correctly - #339

Merged
sureshanaparti merged 1 commit into
apache:mainfrom
nagaboinaramgopal:fix/network-offering-update-read
Sep 4, 2026
Merged

fix: make network offering update work (set the id) and read back correctly#339
sureshanaparti merged 1 commit into
apache:mainfrom
nagaboinaramgopal:fix/network-offering-update-read

Conversation

@nagaboinaramgopal

Copy link
Copy Markdown
Contributor

Description

resourceCloudStackNetworkOfferingUpdate was broken in two ways, and updating a cloudstack_network_offering failed outright:

  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 (CSExceptionErrorCode: 9999): Cannot invoke
     "java.lang.Long.longValue()" because "id" is null
    

    Fixed by setting the id on each params struct.

  2. After updating, the function returned resourceCloudStackInstanceRead, the read function for the cloudstack_instance resource, which looks up a VM by the network offering id and corrupts the resource state. Fixed to return resourceCloudStackNetworkOfferingRead, matching the Create and Read paths.

Testing

Added an acceptance test TestAccCloudStackNetworkOffering_update that creates a network offering and then updates its display_text. It fails before this change (the id is null API error) and passes after.

Verified end to end against a live CloudStack advanced zone:

    TF_ACC=1 go test ./cloudstack/ -run TestAccCloudStackNetworkOffering_update
    --- PASS: TestAccCloudStackNetworkOffering_update

go build ./..., go vet ./..., and the unit suite (go test ./cloudstack/) also pass.

@sudo87 sudo87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 each UpdateNetworkOffering params struct so updates don’t fail with id is null.
  • Return resourceCloudStackNetworkOfferingRead from 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_text for cloudstack_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.

Comment on lines 331 to 333
// Set the new domain id
p.SetDomainid(d.Get("domain_id").(string))

Comment on lines +20 to +25
import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
@sudo87

sudo87 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

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

@kiranchavala kiranchavala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sureshanaparti sureshanaparti added this to the v0.7.0 milestone Sep 4, 2026
@sureshanaparti
sureshanaparti merged commit aea59bf into apache:main Sep 4, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants