Skip to content

Commit

Permalink
[Updated] - completed bigip_ltm_resource_virtual_address (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Burnett committed Jun 1, 2016
1 parent a28efc0 commit 0a718d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
48 changes: 25 additions & 23 deletions bigip/resource_bigip_ltm_virtual_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ func resourceBigipLtmVirtualAddress() *schema.Resource {
}

func resourceBigipLtmVirtualAddressCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*bigip.BigIP)

name := d.Get("name").(string)
log.Printf("[INFO] not creating virtual address %s - should have been created automatically\n", name)
log.Println("[INFO] Creating virtual address " + name)

client.CreateVirtualAddress(name, hydrateVirtualAddress(d))

d.SetId(name)
return resourceBigipLtmVirtualAddressRead(d, meta)
Expand All @@ -98,19 +102,17 @@ func resourceBigipLtmVirtualAddressRead(d *schema.ResourceData, meta interface{}
return err
}
for _, va = range vas.VirtualAddresses {
if va.Name == name {
if va.FullPath == name {
break
}
}
if va.Name != name {
if va.FullPath != name {
return fmt.Errorf("virtual address %s not found", name)
}

d.Set("name", name)
d.Set("arp", va.ARP)
if va.AutoDelete != "true" {
d.Set("auto_delete", false)
}
d.Set("auto_delete", va.AutoDelete)
d.Set("conn_limit", va.ConnectionLimit)
d.Set("enabled", va.Enabled)
d.Set("icmp_echo", va.ICMPEcho)
Expand Down Expand Up @@ -150,21 +152,7 @@ func resourceBigipLtmVirtualAddressUpdate(d *schema.ResourceData, meta interface

name := d.Id()

va := &bigip.VirtualAddress{
Name: name,
ARP: d.Get("arp").(bool),
ConnectionLimit: d.Get("conn_limit").(int),
Enabled: d.Get("enabled").(bool),
ICMPEcho: d.Get("icmp_echo").(bool),
RouteAdvertisement: d.Get("advertize_route").(bool),
TrafficGroup: d.Get("traffic_group").(string),
}

if !d.Get("auto_delete").(bool) {
va.AutoDelete = "false"
} else {
va.AutoDelete = "true"
}
va := hydrateVirtualAddress(d)

err := client.ModifyVirtualAddress(name, va)
if err != nil {
Expand All @@ -174,8 +162,22 @@ func resourceBigipLtmVirtualAddressUpdate(d *schema.ResourceData, meta interface
return nil
}

func hydrateVirtualAddress(d *schema.ResourceData) *bigip.VirtualAddress {
return &bigip.VirtualAddress{
Name: d.Id(),
ARP: d.Get("arp").(bool),
ConnectionLimit: d.Get("conn_limit").(int),
Enabled: d.Get("enabled").(bool),
ICMPEcho: d.Get("icmp_echo").(bool),
RouteAdvertisement: d.Get("advertize_route").(bool),
TrafficGroup: d.Get("traffic_group").(string),
AutoDelete: d.Get("auto_delete").(bool),
}
}

func resourceBigipLtmVirtualAddressDelete(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
log.Printf("[INFO] unable to delete virtual address %s - not implemented\n", name)
return nil
log.Printf("[INFO] Deleting virtual address " + name)
client := meta.(*bigip.BigIP)
return client.DeleteVirtualAddress(name)
}
1 change: 1 addition & 0 deletions bigip/resource_bigip_ltm_virtual_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var TEST_VA_NAME = fmt.Sprintf("/%s/test-va", TEST_PARTITION)
var TEST_VA_RESOURCE = `
resource "bigip_ltm_virtual_address" "test-va" {
name = "` + TEST_VA_NAME + `"
}
`

Expand Down

0 comments on commit 0a718d9

Please sign in to comment.