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