Code cleanup to address PR comments
This commit is contained in:
parent
b6abb91b83
commit
a15c99e5bb
|
@ -4,13 +4,11 @@ import (
|
|||
"fmt"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hmrc/vmware-govcd"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func resourceVcdDNAT() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceVcdDNATCreate,
|
||||
Update: resourceVcdDNATUpdate,
|
||||
Delete: resourceVcdDNATDelete,
|
||||
Read: resourceVcdDNATRead,
|
||||
|
||||
|
@ -24,16 +22,19 @@ func resourceVcdDNAT() *schema.Resource {
|
|||
"external_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"port": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"internal_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -78,10 +79,6 @@ func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func resourceVcdDNATUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error {
|
||||
vcd_client := meta.(*govcd.VCDClient)
|
||||
e, err := vcd_client.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
|
||||
|
@ -90,13 +87,12 @@ func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error {
|
|||
return fmt.Errorf("Unable to find edge gateway: %#v", err)
|
||||
}
|
||||
|
||||
idSplit := strings.Split(d.Id(), "_")
|
||||
var found bool
|
||||
|
||||
for _, r := range e.EdgeGateway.Configuration.EdgeGatewayServiceConfiguration.NatService.NatRule {
|
||||
if r.RuleType == "DNAT" &&
|
||||
r.GatewayNatRule.OriginalIP == idSplit[0] &&
|
||||
r.GatewayNatRule.OriginalPort == idSplit[1] {
|
||||
r.GatewayNatRule.OriginalIP == d.Get("external_ip").(string) &&
|
||||
r.GatewayNatRule.OriginalPort == getPortString(d.Get("port").(int)) {
|
||||
found = true
|
||||
d.Set("internal_ip", r.GatewayNatRule.TranslatedIP)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
func resourceVcdNetwork() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceVcdNetworkCreate,
|
||||
Update: resourceVcdNetworkUpdate,
|
||||
Read: resourceVcdNetworkRead,
|
||||
Delete: resourceVcdNetworkDelete,
|
||||
|
||||
|
@ -29,51 +28,60 @@ func resourceVcdNetwork() *schema.Resource {
|
|||
"fence_mode": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: "natRouted",
|
||||
},
|
||||
|
||||
"edge_gateway": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"netmask": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: "255.255.255.0",
|
||||
},
|
||||
|
||||
"gateway": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"dns1": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: "8.8.8.8",
|
||||
},
|
||||
|
||||
"dns2": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: "8.8.4.4",
|
||||
},
|
||||
|
||||
"dns_suffix": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"href": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"dhcp_pool": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"start_address": &schema.Schema{
|
||||
|
@ -92,6 +100,7 @@ func resourceVcdNetwork() *schema.Resource {
|
|||
"static_ip_pool": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"start_address": &schema.Schema{
|
||||
|
@ -119,10 +128,7 @@ func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
|
||||
edgeGateway, err := vcd_client.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
|
||||
|
||||
ipRanges, err := expandIpRange(d.Get("static_ip_pool").(*schema.Set).List())
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v\n", err)
|
||||
}
|
||||
ipRanges := expandIpRange(d.Get("static_ip_pool").(*schema.Set).List())
|
||||
|
||||
newnetwork := &types.OrgVDCNetwork{
|
||||
Xmlns: "http://www.vmware.com/vcloud/v1.5",
|
||||
|
@ -187,14 +193,6 @@ func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
return resourceVcdNetworkRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceVcdNetworkUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
vcd_client := meta.(*govcd.VCDClient)
|
||||
|
||||
log.Printf("[DEBUG] VCD Client configuration: %#v", vcd_client)
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error {
|
||||
vcd_client := meta.(*govcd.VCDClient)
|
||||
log.Printf("[DEBUG] VCD Client configuration: %#v", vcd_client)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
func resourceVcdSNAT() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceVcdSNATCreate,
|
||||
Update: resourceVcdSNATUpdate,
|
||||
Delete: resourceVcdSNATDelete,
|
||||
Read: resourceVcdSNATRead,
|
||||
|
||||
|
@ -23,11 +22,13 @@ func resourceVcdSNAT() *schema.Resource {
|
|||
"external_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"internal_ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -67,10 +68,6 @@ func resourceVcdSNATCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func resourceVcdSNATUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceVcdSNATRead(d *schema.ResourceData, meta interface{}) error {
|
||||
vcd_client := meta.(*govcd.VCDClient)
|
||||
e, err := vcd_client.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
|
||||
|
|
|
@ -150,18 +150,6 @@ func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// err = resource.Retry(4*time.Minute, func() error {
|
||||
// err = vcd_client.OrgVdc.InstantiateVAppTemplate(createvapp)
|
||||
//
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("Error: %#v", err)
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
vapp, err := vcd_client.OrgVdc.FindVAppByName(d.Get("name").(string))
|
||||
|
||||
err = retryCall(4, func() error {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func expandIpRange(configured []interface{}) (types.IPRanges, error) {
|
||||
func expandIpRange(configured []interface{}) types.IPRanges {
|
||||
ipRange := make([]*types.IPRange, 0, len(configured))
|
||||
|
||||
for _, ipRaw := range configured {
|
||||
|
@ -25,7 +25,7 @@ func expandIpRange(configured []interface{}) (types.IPRanges, error) {
|
|||
IPRange: ipRange,
|
||||
}
|
||||
|
||||
return ipRanges, nil
|
||||
return ipRanges
|
||||
}
|
||||
|
||||
func expandFirewallRules(configured []interface{}, gateway *types.EdgeGateway) ([]*types.FirewallRule, error) {
|
||||
|
|
Loading…
Reference in New Issue