Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kaje783 opened this issue Dec 12, 2023 · 2 comments
Assignees
Labels
awaiting-response Awaiting Response bug Bug

Comments

@kaje783
Copy link

kaje783 commented Dec 12, 2023

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:
  + create
 <= read (data resources)

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" {
      + id           = (known after apply)
      + network_name = (known after apply)
      + path         = (known after apply)
      + state        = (known after apply)
    }

  # nsxt_policy_project.tenant_networks will be created
  + resource "nsxt_policy_project" "tenant_networks" {
      + description  = "Terraform provisioned and managed Project"
      + display_name = "test"
      + id           = (known after apply)
      + nsx_id       = (known after apply)
      + path         = (known after apply)
      + revision     = (known after apply)
      + short_id     = (known after apply)
    }

  # nsxt_policy_segment.tenant_networks["500"] will be created
  + resource "nsxt_policy_segment" "tenant_networks" {
      + description         = "provisioned and managed with Terraform"
      + display_name        = "Test-mgmt"
      + id                  = (known after apply)
      + nsx_id              = (known after apply)
      + overlay_id          = (known after apply)
      + path                = (known after apply)
      + replication_mode    = "MTEP"
      + revision            = (known after apply)
      + transport_zone_path = "/infra/sites/default/enforcement-points/default/transport-zones/<removed>"

      + discovery_profile {
          + binding_map_path           = (known after apply)
          + mac_discovery_profile_path = "/infra/mac-discovery-profiles/<removed>"
          + revision                   = (known after apply)
        }

      + security_profile {
          + binding_map_path      = (known after apply)
          + revision              = (known after apply)
          + security_profile_path = "/infra/segment-security-profiles/<removed>"
        }
    }

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

Changes to Outputs:
  + network = {
      + Test-mgmt = {
          + context = []
        }
    }

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

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.

  1. output ist empty

...

Expected behavior

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

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

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	
	}
]
@kaje783 kaje783 added the bug Bug label Dec 12, 2023
@salv-orlando
Copy link
Member

@annakhm can you please look at this bug?

@annakhm
Copy link
Collaborator

annakhm commented Feb 20, 2024

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.

@annakhm annakhm added the awaiting-response Awaiting Response label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response Awaiting Response bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants