Merge pull request #3399 from vmfarms/source_nat_ip

Add source NAT IP computed parameter to CloudStack VPC
This commit is contained in:
Sander van Harmelen 2015-10-07 22:36:25 +02:00
commit b0d9b5666c
1 changed files with 18 additions and 0 deletions

View File

@ -57,6 +57,11 @@ func resourceCloudStackVPC() *schema.Resource {
Required: true,
ForceNew: true,
},
"source_nat_ip": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
}
}
@ -152,6 +157,19 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
setValueOrID(d, "project", v.Project, v.Projectid)
setValueOrID(d, "zone", v.Zonename, v.Zoneid)
// Grab the source NAT IP that CloudStack assigned.
p := cs.Address.NewListPublicIpAddressesParams()
p.SetVpcid(d.Id())
p.SetIssourcenat(true)
if _, ok := d.GetOk("project"); ok {
p.SetProjectid(v.Projectid)
}
l, e := cs.Address.ListPublicIpAddresses(p)
if (e == nil) && (l.Count == 1) {
d.Set("source_nat_ip", l.PublicIpAddresses[0].Ipaddress)
}
return nil
}