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

Fix vnic import #1162

Merged
merged 3 commits into from
Aug 14, 2020
Merged

Fix vnic import #1162

merged 3 commits into from
Aug 14, 2020

Conversation

waquidvp
Copy link
Contributor

@waquidvp waquidvp commented Aug 9, 2020

Description

After importing a vsphere_vnic, I noticed couple of things in the subsequent terraform plan indicating some sort of 'incomplete' import:

  • the host field was showing as being added, even though the value for host is technically in the id used for importing (note that this causes a replacement of the resource which was kind of a show stopper for trying to import the nic)
  • the same behavior was observed for both the netstack and ipv4 fields and I suspect it would be the same for ipv6, although in my case, the vnic I was importing didn't have any IPv6 settings configured.

Below is an example of the observed behavior :

The vsphere_vnic config:

resource "vsphere_vnic" "management" {
  host      = "host-4109"
  portgroup = "Management Network"
  netstack  = "defaultTcpipStack"

  ipv4 {
    dhcp    = false
    ip      = "172.20.9.15"
    netmask = "255.255.255.0"
    gw      = "172.20.9.1"
  }
}

The management vnic I am trying to import here is vmk0 so the import command I used was:

terraform import vsphere_vnic.management host-4109_vmk0

The subsequent terraform plan was showing the following:

  # vsphere_vnic.management must be replaced
-/+ resource "vsphere_vnic" "management" {
      + host      = "host-4109" # forces replacement
      ~ id        = "host-4109_vmk0" -> (known after apply)
      ~ mac       = "24:6e:96:2c:8b:34" -> (known after apply)
      ~ mtu       = 1500 -> (known after apply)
      + netstack  = "defaultTcpipStack" # forces replacement
        portgroup = "Management Network"

      + ipv4 {
          + dhcp    = false
          + gw      = "172.20.9.1"
          + ip      = "172.20.9.15"
          + netmask = "255.255.255.0"
        }
    }

The ipv4 settings that are shown as "added" shouldn't be there, the vnic already has those settings.

This MR is an attempt at fixing this behavior. I have done this in two ways:

  1. Modify the 'read' function to set the netstack, ipv4 and ipv6 values from the vnic.Spec returned by the vSphere Client.
  2. Change the Importer from the standard ImportStatePassthrough to a custom func which handles setting the host field.

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch? (If so, please include the test log in a gist)

@ghost ghost added size/s Relative Sizing: Small labels Aug 9, 2020
Copy link
Contributor

@bill-rich bill-rich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for fixing this!

@bill-rich bill-rich merged commit e702103 into hashicorp:master Aug 14, 2020
@ghost
Copy link

ghost commented Sep 14, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Sep 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size/s Relative Sizing: Small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants