Skip to content

Commit

Permalink
Expose MACs of private networks in instance resource
Browse files Browse the repository at this point in the history
Terraform will support nested maps starting with 0.12 (late summer),
so I'm adding a separate map of MACs.

https://www.hashicorp.com/blog/terraform-0-12-rich-value-types

Fixes #54
  • Loading branch information
mlazowik committed Dec 5, 2018
1 parent 62b7450 commit 6761be4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vultr/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func resourceInstance() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},

"network_macs": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"network_ids": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -278,9 +284,11 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error getting private networks for instance (%s): %v", d.Id(), err)
}
nets := make(map[string]string)
netMACs := make(map[string]string)
var networkIDs []string
for _, n := range networks {
nets[n.ID] = n.IPAddress
netMACs[n.ID] = n.MACAddress
networkIDs = append(networkIDs, n.ID)
}

Expand Down Expand Up @@ -319,6 +327,7 @@ func resourceInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("ipv4_private_cidr", fmt.Sprintf("%s/%d", instance.InternalIP, size))
d.Set("name", instance.Name)
d.Set("networks", nets)
d.Set("network_macs", netMACs)
d.Set("network_ids", networkIDs)
d.Set("os_id", osID)
d.Set("plan_id", instance.PlanID)
Expand Down

0 comments on commit 6761be4

Please sign in to comment.