Skip to content

Commit

Permalink
r/host_port_group: Add support for importing (#1194)
Browse files Browse the repository at this point in the history
* add importer

* add missing field (virtual_switch_name) in read

* Update docs

Co-authored-by: Waquid Valiya Peedikakkal <[email protected]>
  • Loading branch information
waquidvp and Waquid Valiya Peedikakkal authored Sep 17, 2020
1 parent 7b0d4df commit a88bf6b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
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`.

0 comments on commit a88bf6b

Please sign in to comment.