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

r/host_port_group: Add support for importing #1194

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vsphere/host_port_group_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func expandHostPortGroupSpec(d *schema.ResourceData) *types.HostPortGroupSpec {
// the passed in ResourceData.
func flattenHostPortGroupSpec(d *schema.ResourceData, obj *types.HostPortGroupSpec) error {
d.Set("vlan_id", obj.VlanId)
d.Set("virtual_switch_name", obj.VswitchName)
if err := flattenHostNetworkPolicy(d, &obj.Policy); err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions vsphere/resource_vsphere_host_port_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func resourceVSphereHostPortGroup() *schema.Resource {
Read: resourceVSphereHostPortGroupRead,
Update: resourceVSphereHostPortGroupUpdate,
Delete: resourceVSphereHostPortGroupDelete,
Importer: &schema.ResourceImporter{
State: resourceVSphereHostPortGroupImport,
},
Schema: s,
}
}
Expand Down Expand Up @@ -147,3 +150,19 @@ func resourceVSphereHostPortGroupDelete(d *schema.ResourceData, meta interface{}

return nil
}

func resourceVSphereHostPortGroupImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
hsID, name, err := portGroupIDsFromResourceID(d)

err = d.Set("host_system_id", hsID)
if err != nil {
return []*schema.ResourceData{}, err
}

err = d.Set("name", name)
if err != nil {
return []*schema.ResourceData{}, err
}

return []*schema.ResourceData{d}, nil
}
13 changes: 13 additions & 0 deletions website/docs/r/host_port_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,16 @@ The following attributes are exported:
explaining the effective policy for this port group.
* `key` - The key for this port group as returned from the vSphere API.
* `ports` - A list of ports that currently exist and are used on this port group.

## Importing

An existing host port group can be [imported][docs-import] into this resource
using the host port group's ID. An example is below:

[docs-import]: /docs/import/index.html

```
terraform import vsphere_host_port_group.management tf-HostPortGroup:host-123:Management
```

The above would import the `Management` host port group from host with ID `host-123`.
2 changes: 1 addition & 1 deletion website/docs/r/vnic.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ via supplying the vNic's ID. An example is below:
terraform import vsphere_vnic.v1 host-123_vmk2
```

The above would import the the vnic `vmk2` from host with ID `host-123`.
The above would import the vnic `vmk2` from host with ID `host-123`.