From a15c99e5bb8168450a3fcfba9e6eb4df92944cdd Mon Sep 17 00:00:00 2001 From: Brett Mack Date: Tue, 10 Nov 2015 18:39:58 +0000 Subject: [PATCH] Code cleanup to address PR comments --- builtin/providers/vcd/resource_vcd_dnat.go | 14 ++++------- builtin/providers/vcd/resource_vcd_network.go | 24 +++++++++---------- builtin/providers/vcd/resource_vcd_snat.go | 7 ++---- builtin/providers/vcd/resource_vcd_vapp.go | 12 ---------- builtin/providers/vcd/structure.go | 4 ++-- 5 files changed, 20 insertions(+), 41 deletions(-) diff --git a/builtin/providers/vcd/resource_vcd_dnat.go b/builtin/providers/vcd/resource_vcd_dnat.go index b0ffc196c..edfdd69f7 100644 --- a/builtin/providers/vcd/resource_vcd_dnat.go +++ b/builtin/providers/vcd/resource_vcd_dnat.go @@ -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) } diff --git a/builtin/providers/vcd/resource_vcd_network.go b/builtin/providers/vcd/resource_vcd_network.go index b247be5da..37b9d68bb 100644 --- a/builtin/providers/vcd/resource_vcd_network.go +++ b/builtin/providers/vcd/resource_vcd_network.go @@ -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) diff --git a/builtin/providers/vcd/resource_vcd_snat.go b/builtin/providers/vcd/resource_vcd_snat.go index afae15550..75c78696b 100644 --- a/builtin/providers/vcd/resource_vcd_snat.go +++ b/builtin/providers/vcd/resource_vcd_snat.go @@ -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)) diff --git a/builtin/providers/vcd/resource_vcd_vapp.go b/builtin/providers/vcd/resource_vcd_vapp.go index c50037868..69c4cc4c2 100644 --- a/builtin/providers/vcd/resource_vcd_vapp.go +++ b/builtin/providers/vcd/resource_vcd_vapp.go @@ -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 { diff --git a/builtin/providers/vcd/structure.go b/builtin/providers/vcd/structure.go index 289351469..7c40f70fc 100644 --- a/builtin/providers/vcd/structure.go +++ b/builtin/providers/vcd/structure.go @@ -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) {