Merge pull request #3445 from svanharmelen/f-cloudstack-style
provider/cloudstack: small refactor for better readability and style
This commit is contained in:
commit
1ed316c2d3
|
@ -52,16 +52,16 @@ func resourceCloudStackVPC() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"source_nat_ip": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
|
||||||
"zone": &schema.Schema{
|
"zone": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"source_nat_ip": &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Computed: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,19 +157,27 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
setValueOrID(d, "project", v.Project, v.Projectid)
|
setValueOrID(d, "project", v.Project, v.Projectid)
|
||||||
setValueOrID(d, "zone", v.Zonename, v.Zoneid)
|
setValueOrID(d, "zone", v.Zonename, v.Zoneid)
|
||||||
|
|
||||||
// Grab the source NAT IP that CloudStack assigned.
|
// Create a new parameter struct
|
||||||
p := cs.Address.NewListPublicIpAddressesParams()
|
p := cs.Address.NewListPublicIpAddressesParams()
|
||||||
p.SetVpcid(d.Id())
|
p.SetVpcid(d.Id())
|
||||||
p.SetIssourcenat(true)
|
p.SetIssourcenat(true)
|
||||||
|
|
||||||
if _, ok := d.GetOk("project"); ok {
|
if _, ok := d.GetOk("project"); ok {
|
||||||
p.SetProjectid(v.Projectid)
|
p.SetProjectid(v.Projectid)
|
||||||
}
|
}
|
||||||
|
|
||||||
l, e := cs.Address.ListPublicIpAddresses(p)
|
// Get the source NAT IP assigned to the VPC
|
||||||
if (e == nil) && (l.Count == 1) {
|
l, err := cs.Address.ListPublicIpAddresses(p)
|
||||||
d.Set("source_nat_ip", l.PublicIpAddresses[0].Ipaddress)
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if l.Count != 1 {
|
||||||
|
return fmt.Errorf("Unexpected number (%d) of source NAT IPs returned", l.Count)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set("source_nat_ip", l.PublicIpAddresses[0].Ipaddress)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,3 +49,4 @@ The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The ID of the VPC.
|
* `id` - The ID of the VPC.
|
||||||
* `display_text` - The display text of the VPC.
|
* `display_text` - The display text of the VPC.
|
||||||
|
* `source_nat_ip` - The source NAT IP assigned to the VPC.
|
||||||
|
|
Loading…
Reference in New Issue