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

Import vsphere_distributed_portgroup doesn't work version > 1.25 #1461

Closed
gbordier35 opened this issue Aug 4, 2021 · 5 comments · Fixed by #1568
Closed

Import vsphere_distributed_portgroup doesn't work version > 1.25 #1461

gbordier35 opened this issue Aug 4, 2021 · 5 comments · Fixed by #1568
Labels
documentation Type: Documentation

Comments

@gbordier35
Copy link

Terraform Version

v1.0.3

vSphere Provider Version

v2.0.2

Affected Resource(s)

--- vsphere_distributed_port_group

Terraform Configuration Files

terraform {
  required_providers {
    vsphere = {
      source  = "hashicorp/vsphere"
      version = "2.0.2"
    }
  }
}

provider "vsphere" {
  user                 = var.vsphere_user
  password             = var.vsphere_password
  vsphere_server       = var.vsphere_server
  allow_unverified_ssl = false
}

variable "vsphere_server" {
  description = "vCenter"
  type        = string
}

variable "vsphere_user" {
  description = "vSphere username"
  type        = string
}

variable "vsphere_password" {
  description = "vSphere password of vsphere_user"
  type        = string
  sensitive   = true
}

data "vsphere_datacenter" "dc" {
  name = var.vsphere_datacenter
}

data "vsphere_distributed_virtual_switch" "dvs" {
  name          = var.dvs
  datacenter_id = data.vsphere_datacenter.dc.id
}

variable "vsphere_datacenter" {
  description = "vSphere datacenter"
  type        = string
}

variable "dvs" {
  description = "Distributed virtual switch"
  type        = string
}

variable "vlan_name" {
  description = "VLAN name"
  type        = string
}

resource "vsphere_distributed_port_group" "vlan" {
  name                            = var.vlan_name
  description                     = "Test VLAN"
  number_of_ports                 = 256
  type                            = "earlyBinding"
  block_override_allowed          = true
  distributed_virtual_switch_uuid = data.vsphere_distributed_virtual_switch.dvs.id
  network_resource_pool_key       = null
  port_config_reset_at_disconnect = true
  vlan_id                         = (regex("VLAN(\\d{1,3})_", var.vlan_name ))[0]
  active_uplinks                  = ["lag1"]
  standby_uplinks                 = []
}

Debug Output

# terraform import vsphere_distributed_port_group.vlan dvportgroup-<ID>
vsphere_distributed_port_group.vlan: Importing from ID "dvportgroup-<ID>"...
╷
│ Error: error locating portgroup: please specify a datacenter

Panic Output

Expected Behavior

Import dvportgroup

Example with vsphere provider v1.25.0 :

terraform {
  required_providers {
    vsphere = {
      source  = "hashicorp/vsphere"
      version = "1.25.0"
    }
  }
}

# terraform import vsphere_distributed_port_group.vlan dvportgroup-<ID>
vsphere_distributed_port_group.vlan: Importing from ID "dvportgroup-<ID>"...
vsphere_distributed_port_group.vlan: Import prepared!
  Prepared vsphere_distributed_port_group for import
vsphere_distributed_port_group.vlan: Refreshing state... [id=dvportgroup-<ID>]

Actual Behavior

It's not possible to import an existing dvportgroup with version > 1.25.0 :

# terraform import vsphere_distributed_port_group.vlan dvportgroup-<ID>
vsphere_distributed_port_group.vlan: Importing from ID "dvportgroup-<ID>"...
╷
│ Error: error locating portgroup: please specify a datacenter

Steps to Reproduce

  1. Copy configuration code with version 2.0.2
  2. terraform init
  3. terraform apply -> dvportgroup will be create
  4. Remove terraform.tfstate
  5. terraform import vsphere_distributed_port_group.vlan dvportgroup- => Error locating portgroup
  6. Change version of provider from 2.0.2 to 1.25.0
  7. Remove .terraform.d, .terraform.lock.hcl
  8. terraform init
  9. terraform import vsphere_distributed_port_group.vlan dvportgroup-
vsphere_distributed_port_group.vlan: Importing from ID "dvportgroup-<ID>"...
vsphere_distributed_port_group.vlan: Import prepared!
  Prepared vsphere_distributed_port_group for import
vsphere_distributed_port_group.vlan: Refreshing state... [id=dvportgroup-<ID>]

Important Factoids

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@gbordier35 gbordier35 added the bug Type: Bug label Aug 4, 2021
@kev-in-shu
Copy link

Hi,

I noticed that a few other resources have implemented import via a path instead of the id.

And after scratching my head some time, I managed to import my portgroups using a path like this

/$datacenter_name/network/$network_folder/$switch_name/$portgroup_name

I feel like this is much harder than just passing an ID, as it's not really clear what counts as a folder from vSphere UI.

Also the documentation for vsphere_distributed_port_group was not updated to reflect this change.

Regards,

Kevin

@tenthirtyam
Copy link
Collaborator

It appears that the changes to use MoID that were implemented by @sumitAgrawal007 in f39415b#diff-71902d0785ad0ca9cf7b4edc595ff89b91e141d86dca8010d5458aa8932ab847 for PR #1208 were overwritten by @koikonom in 44939f3#diff-71902d0785ad0ca9cf7b4edc595ff89b91e141d86dca8010d5458aa8932ab847 for PR #1381.

It looks like it might have been a mistake since the markdown for the docs were not included.

@appilon @iBrandyJackson - let me know if you'd like me to PR and test this to revert back to @sumitAgrawal007's change.

cc @tejavar

@appilon
Copy link
Contributor

appilon commented Jan 14, 2022

@tenthirtyam Thanks for tracking down the history, I seem to recall this period as a time we did refactoring/fixing of tests post SDK v2.0.0 upgrade, its possible a test was "fixed" by this reversion (and sometimes fix just means failing silently now, or passing but re-introducing other bugs such as what's being described).

If you have the bandwidth, would you have an environment to test the potential reversion against the associated acceptance tests?

@tenthirtyam
Copy link
Collaborator

I'd be happy to take the time to look at it. Let's catch over email to ensure I perform it correctly in my labs.

Inbox me at johnsonryan [at] vmware [dot] com.

Ryan

@tenthirtyam tenthirtyam self-assigned this Feb 1, 2022
@tenthirtyam tenthirtyam added documentation Type: Documentation and removed bug Type: Bug labels Feb 1, 2022
appilon pushed a commit that referenced this issue Feb 1, 2022
- Updates the examples to remove legacy Terraform  interpolation.
- Updates the examples for simplicity and context.
- Corrects "DVS" to "VDS" as the correct term.
- Corrects import example for the `vsphere_distributed_port_group` resource docs. #1461 and #1567
- Adds missing VLAN options to the `vsphere_distributed_port_group` resource docs. #1565
- Ensures markdown is lines are limited to column 80 in length.

Signed-off-by: Ryan Johnson <[email protected]>
@tenthirtyam tenthirtyam removed their assignment Feb 17, 2022
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Type: Documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants