Skip to content

Fix internet_protocol/routing_mode case mismatch causing perpetual replace on cloudstack_vpc_offering - #330

Merged
sureshanaparti merged 1 commit into
mainfrom
fix/vpc-offering-case-insensitive-forcenew-fields
Sep 2, 2026
Merged

sureshanaparti merged 1 commit into
mainfrom
fix/vpc-offering-case-insensitive-forcenew-fields

Conversation

@sudo87

@sudo87 sudo87 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

CloudStack's API normalizes these ForceNew fields' casing on write (e.g. ipv4 -> IPv4, static -> Static), which produced a permanent diff and proposed a destroy/recreate on every subsequent plan. Add a case-insensitive DiffSuppressFunc to both fields.

network_mode is unaffected: the API rejects incorrect casing outright instead of silently normalizing it, so no fix is needed there.

…place on cloudstack_vpc_offering

CloudStack's API normalizes these ForceNew fields' casing on write (e.g.
ipv4 -> IPv4, static -> Static), which produced a permanent diff and
proposed a destroy/recreate on every subsequent plan. Add a
case-insensitive DiffSuppressFunc to both fields.

network_mode is unaffected: the API rejects incorrect casing outright
instead of silently normalizing it, so no fix is needed there.
@sudo87
sudo87 requested review from sureshanaparti and a lite review from Copilot August 28, 2026 09:35

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.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds case-insensitive diff suppression for CloudStack-normalized ForceNew fields to prevent perpetual plan diffs and unnecessary VPC offering replacements.

Changes:

  • Add DiffSuppressFunc using case-insensitive comparison for internet_protocol.
  • Add DiffSuppressFunc using case-insensitive comparison for routing_mode.
  • Import strings to support strings.EqualFold.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

import (
"fmt"
"log"
"strings"
Comment on lines +86 to +88
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
Comment on lines +103 to +105
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},

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

clgtm. didn't test.

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

@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_vpc_offering" "example" {
    name         = "example-vpc-offering"
    display_text = "Example VPC Offering"
    enable       = true
    supported_services = ["Dhcp", "Dns", "SourceNat", "PortForwarding", "Lb", "UserData", "StaticNat", "NetworkACL"]
    service_provider_list = {
        Dhcp           = "VpcVirtualRouter"
        Dns            = "VpcVirtualRouter"
        SourceNat      = "VpcVirtualRouter"
        PortForwarding = "VpcVirtualRouter"
        Lb             = "VpcVirtualRouter"
        UserData       = "VpcVirtualRouter"
        StaticNat      = "VpcVirtualRouter"
        NetworkACL     = "VpcVirtualRouter"
    }
}

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_vpc_offering.example will be created
  + resource "cloudstack_vpc_offering" "example" {
      + display_text          = "Example VPC Offering"
      + enable                = true
      + id                    = (known after apply)
      + internet_protocol     = (known after apply)
      + is_default            = (known after apply)
      + name                  = "example-vpc-offering"
      + network_mode          = (known after apply)
      + routing_mode          = (known after apply)
      + service_provider_list = {
          + "Dhcp"           = "VpcVirtualRouter"
          + "Dns"            = "VpcVirtualRouter"
          + "Lb"             = "VpcVirtualRouter"
          + "NetworkACL"     = "VpcVirtualRouter"
          + "PortForwarding" = "VpcVirtualRouter"
          + "SourceNat"      = "VpcVirtualRouter"
          + "StaticNat"      = "VpcVirtualRouter"
          + "UserData"       = "VpcVirtualRouter"
        }
      + supported_services    = [
          + "Dhcp",
          + "Dns",
          + "Lb",
          + "NetworkACL",
          + "PortForwarding",
          + "SourceNat",
          + "StaticNat",
          + "UserData",
        ]

      + service_capability_list (known after apply)
    }

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_vpc_offering.example: Creating...
cloudstack_vpc_offering.example: Creation complete after 0s [id=a133e483-e5df-4464-9eca-01a04df1d0ff]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

terraform destroy
cloudstack_vpc_offering.example: Refreshing state... [id=a133e483-e5df-4464-9eca-01a04df1d0ff]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
  - destroy

Terraform will perform the following actions:

  # cloudstack_vpc_offering.example will be destroyed
  - resource "cloudstack_vpc_offering" "example" {
      - display_text          = "Example VPC Offering" -> null
      - enable                = true -> null
      - for_nsx               = false -> null
      - id                    = "a133e483-e5df-4464-9eca-01a04df1d0ff" -> null
      - internet_protocol     = "IPv4" -> null
      - is_default            = false -> null
      - name                  = "example-vpc-offering" -> null
      - service_provider_list = {
          - "Dhcp"           = "VpcVirtualRouter"
          - "Dns"            = "VpcVirtualRouter"
          - "Lb"             = "VpcVirtualRouter"
          - "NetworkACL"     = "VpcVirtualRouter"
          - "PortForwarding" = "VpcVirtualRouter"
          - "SourceNat"      = "VpcVirtualRouter"
          - "StaticNat"      = "VpcVirtualRouter"
          - "UserData"       = "VpcVirtualRouter"
        } -> null
      - specify_as_number     = false -> null
      - supported_services    = [
          - "Dhcp",
          - "Dns",
          - "Lb",
          - "NetworkACL",
          - "PortForwarding",
          - "SourceNat",
          - "StaticNat",
          - "UserData",
        ] -> null
    }

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

cloudstack_vpc_offering.example: Destroying... [id=a133e483-e5df-4464-9eca-01a04df1d0ff]
cloudstack_vpc_offering.example: Destruction complete after 1s

Destroy complete! Resources: 1 destroyed.


@sureshanaparti sureshanaparti added this to the v0.7.0 milestone Sep 2, 2026
@sureshanaparti
sureshanaparti merged commit 8252603 into main Sep 2, 2026
32 checks passed
@sureshanaparti
sureshanaparti deleted the fix/vpc-offering-case-insensitive-forcenew-fields branch September 2, 2026 04:54
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