vmware / terraform-provider-nsxt

Terraform VMware NSX-T provider
https://www.terraform.io/docs/providers/nsxt/
Other
123 stars 80 forks source link

Infos of data.nsxt_policy_segment_realization can't export/show via output at least in terraform plan #1062

Open kaje783 opened 7 months ago

kaje783 commented 7 months ago

Describe the bug

The information from the data element nsxt_policy_segment_realization is not displayed via the output element

Reproduction steps

  1. terraform init
  2. terraform plan
    
    data.nsxt_policy_mac_discovery_profile.nsx_mac_discovery_profile: Reading...
    data.nsxt_policy_transport_zone.vlan_tz: Reading...
    data.nsxt_policy_transport_zone.overlay_tz: Reading...
    data.nsxt_policy_segment_security_profile.nsx_security_profile: Reading...
    data.nsxt_policy_mac_discovery_profile.nsx_mac_discovery_profile: Read complete after 0s [id=<removed>]
    data.nsxt_policy_segment_security_profile.nsx_security_profile: Read complete after 0s [id=<removed>]
    data.nsxt_policy_transport_zone.overlay_tz: Read complete after 0s [id=<removed>]
    data.nsxt_policy_transport_zone.vlan_tz: Read complete after 0s [id=<removed>]

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

Terraform will perform the following actions:

data.nsxt_policy_segment_realization.tenant_networks["Test-mgmt"] will be read during apply

(config refers to values not yet known)

<= data "nsxt_policy_segment_realization" "tenant_networks" {

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

Changes to Outputs:

─────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

3. output ist empty

...

### Expected behavior

The complete variable information from the data element is displayed.
So something like this:

Changes to Outputs:

Additional context

Config:


main.tf

data "nsxt_policy_transport_zone" "overlay_tz" {
  display_name = var.nsx.transport_zone.overlay
}

data "nsxt_policy_transport_zone" "vlan_tz" {
  display_name = var.nsx.transport_zone.vlan
}

data "nsxt_policy_mac_discovery_profile" "nsx_mac_discovery_profile" {
  display_name = var.nsx.mac_discovery_profile
} 

data "nsxt_policy_segment_security_profile" "nsx_security_profile" {
  display_name = var.nsx.security_profile
}

resource "nsxt_policy_segment" "tenant_networks" { 
  for_each = { for network in var.networks : network.id => network}

  display_name        = "${each.value.name}"
  description         = "provisioned with Terraform"
  transport_zone_path = "${data.nsxt_policy_transport_zone.overlay_tz.path}"

  discovery_profile {
    mac_discovery_profile_path = "${data.nsxt_policy_mac_discovery_profile.nsx_mac_discovery_profile.path}"
  }

  security_profile {
    security_profile_path   = "${data.nsxt_policy_segment_security_profile.nsx_security_profile.path}"
  }  
}

data "nsxt_policy_segment_realization" "tenant_networks" {
  for_each = { for network in var.networks : network.name => network}
  path = resource.nsxt_policy_segment.tenant_networks["${each.value.id}"].path
  depends_on = [resource.nsxt_policy_segment.tenant_networks]
}

output "network" {
  value       = data.nsxt_policy_segment_realization.tenant_networks
}

var.tf

variable "nsx" {
    type = object({
        ip_address = string
        username = string
        password = string
        transport_zone = object({
            overlay = string
            vlan = string
            edge = optional(string)
        })
        mac_discovery_profile = string
        security_profile = string       
    })
    sensitive = true
}

variable "networks" {
    type = list(object({
        name = string
        id = number     
    }))
}

provider.tf

terraform {
    required_providers {
        nsxt = {
            source = "vmware/nsxt"
            version = "3.4.0"
            configuration_aliases = [
                nsxt,
            ]
        }
    }
}

Testdata:

terraform.tfvars

nsx = {
    ip_address = "<nsx_address>"
    username = "<nsx_username>"
    password =  "<nsx_password>" 
    transport_zone = {
        overlay = "<nsx_overlay>"
        vlan = "<nsx_vlan>"
    }
    mac_discovery_profile = "<nsx_mac_discovery_profile>"
    security_profile = "<nsx_security_profile>"
}

tenant_networks = [    
    {
        name = "Test-mgmt"
        id   = 500  
    }
]
salv-orlando commented 5 months ago

@annakhm can you please look at this bug?

annakhm commented 5 months ago

Hi @kaje783, thanks for reporting this. Here is the output that I see when trying to replicate your scenario:

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

Changes to Outputs:
  + network = {
      + Test-mgmt = {
          + context      = []
          + id           = (known after apply)
          + network_name = (known after apply)
          + path         = (known after apply)
          + state        = (known after apply)
        }
    }

May I ask what is your version of terraform? I don't think this can be related to the provider, rather to terraform core, but I'm curious what the difference in our cases might be.