vmware/terraform-provider-vcd

Error: could not get network data: 'dedicated_org_id' modifying "vcd_external_network_v2" resource

carmine73 opened this issue · 12 comments

Terraform Version

$ terraform -v
Terraform v1.6.5
on linux_amd64
+ provider registry.terraform.io/vmware/vcd v3.11.0

Affected Resource(s)

  • vcd_external_network_v2

Terraform Configuration Files

## vCD provider gateway
resource "vcd_external_network_v2" "t0_provider_gw" {
  name        = local.t0_vrf.vcd_name
  description = local.t0_vrf.vcd_descr

  nsxt_network {
    nsxt_manager_id      = data.vcd_nsxt_manager.nsxtmgr.id
    nsxt_tier0_router_id = nsxt_policy_tier0_gateway.t0_vrf.id
  }

  use_ip_spaces = false
  # optional argument to dedicate network to a particular Org (only applicable when use_ip_spaces = true)
  # dedicated_org_id = var.org.id # same error if this line is not commented out

  dynamic "ip_scope" {
    for_each = local.t0_vrf.ext_nets
    content {
      gateway       = ip_scope.value.gw_ip
      prefix_length = ip_scope.value.bitmask
      dynamic "static_ip_pool" {
        for_each = ip_scope.value.pools
        content {
          start_address = static_ip_pool.value[0]
          end_address   = static_ip_pool.value[1]
        }
      }
    }
  }
}

Expected Behavior

Provider gateway ip scope updated

Actual Behavior

I got the error

│ Error: could not get network data: 'dedicated_org_id' can only be set when 'use_ip_spaces' is enabled
│ 
│   with module.t0[0].vcd_external_network_v2.t0_provider_gw,
│   on t0-module/fcp-t0.tf line 168, in resource "vcd_external_network_v2" "t0_provider_gw":
│  168: resource "vcd_external_network_v2" "t0_provider_gw" {
│ 
╵

Steps to Reproduce

I have to modify the scope of a provider gateway already deployed with terraform.
I changed the input value and run againg the plan/apply

  1. terraform plan
  # module.t0[0].vcd_external_network_v2.t0_provider_gw will be updated in-place
  ~ resource "vcd_external_network_v2" "t0_provider_gw" {
        id               = "urn:vcloud:network:xxxxxxxx-yyyy-zzzz"
        name             = "t0gwext-orgname1"
        # (3 unchanged attributes hidden)

      - ip_scope {
          - enabled       = true -> null
          - gateway       = "X.Y.Z.1" -> null
          - prefix_length = 24 -> null

          - static_ip_pool {
              - end_address   = "X.Y.Z.3" -> null
              - start_address = "X.Y.Z.3" -> null
            }
        }
      + ip_scope {
          + enabled       = true
          + gateway       = "X.Y.Z.1"
          + prefix_length = 24

          + static_ip_pool {
              + end_address   = "X.Y.Z.4" # end address changed
              + start_address = "X.Y.Z.3"
            }
        }

        # (1 unchanged block hidden)
    }
  1. terraform apply

If I manually change the static ip pool using the vcd UI and then I use terraform plan/apply, it works fine

Hello @carmine73,
Checking a few things:

  • Did this change in 3.11.0 (I suspect it didn't but want to double check)
  • Do you have many static ip_scopes generated? (thinking of the smallest example possible that would replicate the error for me)

Hi @Didainius,

  • same error in 3.10.0
  • test done with only one ip_scope

I see the tfstate file contains dedicated_org_id with a value

{
  "module": "module.t0[0]",
  "mode": "managed",
  "type": "vcd_external_network_v2",
  "name": "t0_provider_gw",
  "provider": "provider[\"registry.terraform.io/vmware/vcd\"]",
  "instances": [
    {
      "schema_version": 0,
      "attributes": {
        "dedicated_org_id": "urn:vcloud:org:aaaaaaaaaaaaaaaaaaaaaaaaa",
        "description": "provider gw created by terraform + vmware/vcd plugin",
        "id": "urn:vcloud:network:xxxxxxxx-yyyy-zzzz",
        "ip_scope": [
          {
            "dns1": "",
            "dns2": "",
            "dns_suffix": "",
            "enabled": true,
            "gateway": "X.Y.Z.1",
            "prefix_length": 24,
            "static_ip_pool": [
              {
                "end_address": "X.Y.Z.3",
                "start_address": "X.Y.Z.3"
              }
            ]
          }
        ],
        "name": "t0gwext-tttttttttttttttt",
        "nsxt_network": [
          {
            "nsxt_manager_id": "urn:vcloud:nsxtmanager:mmmmmmmmmmmmmmmmmmmmmmm",
            "nsxt_segment_name": "",
            "nsxt_tier0_router_id": "ttttttttttttttttttttttttttt"
          }
        ],
        "use_ip_spaces": false,
        "vsphere_network": []
      },
      "sensitive_attributes": [],
      "private": "bnVsbA==",
      "dependencies": [
        "module.t0.data.nsxt_policy_edge_cluster.edge_cluster",
        "module.t0.data.nsxt_policy_tier0_gateway.t0_parent_gw",
        "module.t0.data.vcd_nsxt_manager.nsxtmgr",
        "module.t0.nsxt_policy_tier0_gateway.t0_vrf"
      ]
    }
  ]
}

@Didainius did you replicate the error?
thanks

@Didainius did you replicate the error? thanks

Hello @carmine73 ,
I have not yet, but will do my attempt as soon as I can