From 910469ddee2dfc1743dfeaed5af3b95d8db72af8 Mon Sep 17 00:00:00 2001 From: Hany Fahim Date: Fri, 2 Oct 2015 20:54:07 -0400 Subject: [PATCH] Add Source NAT IP parameter When creating a VPC, CloudStack automatically assigns a source NAT IP from it's pool. It's handy to have this IP available in Terraform, which can be used in ACLs for example. This commit adds such support. --- .../cloudstack/resource_cloudstack_vpc.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpc.go b/builtin/providers/cloudstack/resource_cloudstack_vpc.go index 8fe132d94f..1b2ecbf86c 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpc.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpc.go @@ -51,6 +51,11 @@ func resourceCloudStackVPC() *schema.Resource { Required: true, ForceNew: true, }, + + "source_nat_ip": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -133,6 +138,16 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error { setValueOrUUID(d, "project", v.Project, v.Projectid) setValueOrUUID(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) + 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 }