Skip to content

Commit

Permalink
Merge pull request #1748 from terraform-providers/lb-nat-pool-azurest…
Browse files Browse the repository at this point in the history
…ack_updates

azurerm_lb_nat_pool: backporting azurestack changes
  • Loading branch information
katbyte authored Aug 9, 2018
2 parents 249a790 + a7b2b4a commit 3c6a1ad
Show file tree
Hide file tree
Showing 20 changed files with 182 additions and 168 deletions.
2 changes: 1 addition & 1 deletion azurerm/helpers/validate/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func PortNumber(i interface{}, k string) (_ []string, errors []error) {
return
}

if v < 0 || 65535 < v {
if v < 1 || 65535 < v {
errors = append(errors, fmt.Errorf("%q is not a valid port number: %q", k, i))
}

Expand Down
2 changes: 1 addition & 1 deletion azurerm/helpers/validate/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestPortNumber(t *testing.T) {
},
{
Port: 0,
Errors: 0,
Errors: 1,
},
{
Port: 1,
Expand Down
6 changes: 3 additions & 3 deletions azurerm/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func retrieveLoadBalancerById(loadBalancerId string, meta interface{}) (*network

resGroup, name, err := resourceGroupAndLBNameFromId(loadBalancerId)
if err != nil {
return nil, false, fmt.Errorf("Error Getting LoadBalancer Name and Group:: %+v", err)
return nil, false, fmt.Errorf("Error Getting Load Balancer Name and Group:: %+v", err)
}

resp, err := client.Get(ctx, resGroup, name, "")
if err != nil {
if resp.StatusCode == http.StatusNotFound {
return nil, false, nil
}
return nil, false, fmt.Errorf("Error making Read request on Azure LoadBalancer %s: %s", name, err)
return nil, false, fmt.Errorf("Error making Read request on Azure Load Balancer %s: %s", name, err)
}

return &resp, true, nil
Expand Down Expand Up @@ -131,7 +131,7 @@ func loadbalancerStateRefreshFunc(ctx context.Context, client network.LoadBalanc
return func() (interface{}, string, error) {
res, err := client.Get(ctx, resourceGroupName, loadbalancer, "")
if err != nil {
return nil, "", fmt.Errorf("Error issuing read request in loadbalancerStateRefreshFunc to Azure ARM for LoadBalancer '%s' (RG: '%s'): %s", loadbalancer, resourceGroupName, err)
return nil, "", fmt.Errorf("Error issuing read request in loadbalancerStateRefreshFunc to Azure ARM for Load Balancer '%s' (RG: '%s'): %s", loadbalancer, resourceGroupName, err)
}

return res, *res.LoadBalancerPropertiesFormat.ProvisioningState, nil
Expand Down
16 changes: 8 additions & 8 deletions azurerm/resource_arm_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resourceArmLoadBalancerCreate(d *schema.ResourceData, meta interface{}) err
client := meta.(*ArmClient).loadBalancerClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for Azure ARM LoadBalancer creation.")
log.Printf("[INFO] preparing arguments for Azure ARM Load Balancer creation.")

name := d.Get("name").(string)
location := azureRMNormalizeLocation(d.Get("location").(string))
Expand All @@ -167,34 +167,34 @@ func resourceArmLoadBalancerCreate(d *schema.ResourceData, meta interface{}) err

future, err := client.CreateOrUpdate(ctx, resGroup, name, loadBalancer)
if err != nil {
return fmt.Errorf("Error Creating/Updating LoadBalancer %q (Resource Group %q): %+v", name, resGroup, err)
return fmt.Errorf("Error Creating/Updating Load Balancer %q (Resource Group %q): %+v", name, resGroup, err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error Creating/Updating LoadBalancer %q (Resource Group %q): %+v", name, resGroup, err)
return fmt.Errorf("Error Creating/Updating Load Balancer %q (Resource Group %q): %+v", name, resGroup, err)
}

read, err := client.Get(ctx, resGroup, name, "")
if err != nil {
return fmt.Errorf("Error Retrieving LoadBalancer %q (Resource Group %q): %+v", name, resGroup, err)
return fmt.Errorf("Error Retrieving Load Balancer %q (Resource Group %q): %+v", name, resGroup, err)
}
if read.ID == nil {
return fmt.Errorf("Cannot read LoadBalancer %q (resource group %q) ID", name, resGroup)
return fmt.Errorf("Cannot read Load Balancer %q (resource group %q) ID", name, resGroup)
}

d.SetId(*read.ID)

// TODO: is this still needed?
log.Printf("[DEBUG] Waiting for LoadBalancer (%q) to become available", name)
log.Printf("[DEBUG] Waiting for Load Balancer (%q) to become available", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"Accepted", "Updating"},
Target: []string{"Succeeded"},
Refresh: loadbalancerStateRefreshFunc(ctx, client, resGroup, name),
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for LoadBalancer (%q - Resource Group %q) to become available: %s", name, resGroup, err)
return fmt.Errorf("Error waiting for Load Balancer (%q - Resource Group %q) to become available: %s", name, resGroup, err)
}

return resourceArmLoadBalancerRead(d, meta)
Expand All @@ -212,7 +212,7 @@ func resourceArmLoadBalancerRead(d *schema.ResourceData, meta interface{}) error
}
if !exists {
d.SetId("")
log.Printf("[INFO] LoadBalancer %q not found. Removing from state", d.Id())
log.Printf("[INFO] Load Balancer %q not found. Removing from state", d.Id())
return nil
}

Expand Down
28 changes: 14 additions & 14 deletions azurerm/resource_arm_loadbalancer_backend_address_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, met

loadBalancer, exists, err := retrieveLoadBalancerById(loadBalancerID, meta)
if err != nil {
return fmt.Errorf("Error Getting LoadBalancer By ID: %+v", err)
return fmt.Errorf("Error Getting Load Balancer By ID: %+v", err)
}
if !exists {
d.SetId("")
log.Printf("[INFO] LoadBalancer %q not found. Removing from state", d.Get("name").(string))
log.Printf("[INFO] Load Balancer %q not found. Removing from state", d.Get("name").(string))
return nil
}

Expand All @@ -94,25 +94,25 @@ func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, met
loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools = &backendAddressPools
resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string))
if err != nil {
return fmt.Errorf("Error parsing LoadBalancer Name and Group: %+v", err)
return fmt.Errorf("Error parsing Load Balancer Name and Group: %+v", err)
}

future, err := client.CreateOrUpdate(ctx, resGroup, loadBalancerName, *loadBalancer)
if err != nil {
return fmt.Errorf("Error Creating/Updating LoadBalancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
return fmt.Errorf("Error Creating/Updating Load Balancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error Creating/Updating LoadBalancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
return fmt.Errorf("Error Creating/Updating Load Balancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
}

read, err := client.Get(ctx, resGroup, loadBalancerName, "")
if err != nil {
return fmt.Errorf("Error retrieving Load Balancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
}
if read.ID == nil {
return fmt.Errorf("Cannot read LoadBalancer %q (Resource Group %q) ID", loadBalancerName, resGroup)
return fmt.Errorf("Cannot read Load Balancer %q (Resource Group %q) ID", loadBalancerName, resGroup)
}

var poolId string
Expand All @@ -123,21 +123,21 @@ func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, met
}

if poolId == "" {
return fmt.Errorf("Cannot find created LoadBalancer Backend Address Pool ID %q", poolId)
return fmt.Errorf("Cannot find created Load Balancer Backend Address Pool ID %q", poolId)
}

d.SetId(poolId)

// TODO: is this still needed?
log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", loadBalancerName)
log.Printf("[DEBUG] Waiting for Load Balancer (%s) to become available", loadBalancerName)
stateConf := &resource.StateChangeConf{
Pending: []string{"Accepted", "Updating"},
Target: []string{"Succeeded"},
Refresh: loadbalancerStateRefreshFunc(ctx, client, resGroup, loadBalancerName),
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for LoadBalancer (%q Resource Group %q) to become available: %+v", loadBalancerName, resGroup, err)
return fmt.Errorf("Error waiting for Load Balancer (%q Resource Group %q) to become available: %+v", loadBalancerName, resGroup, err)
}

return resourceArmLoadBalancerBackendAddressPoolRead(d, meta)
Expand All @@ -156,14 +156,14 @@ func resourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, meta
}
if !exists {
d.SetId("")
log.Printf("[INFO] LoadBalancer %q not found. Removing from state", name)
log.Printf("[INFO] Load Balancer %q not found. Removing from state", name)
return nil
}

config, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name)
if !exists {
d.SetId("")
log.Printf("[INFO] LoadBalancer Backend Address Pool %q not found. Removing from state", name)
log.Printf("[INFO] Load Balancer Backend Address Pool %q not found. Removing from state", name)
return nil
}

Expand Down Expand Up @@ -221,7 +221,7 @@ func resourceArmLoadBalancerBackendAddressPoolDelete(d *schema.ResourceData, met

resGroup, loadBalancerName, err := resourceGroupAndLBNameFromId(d.Get("loadbalancer_id").(string))
if err != nil {
return fmt.Errorf("Error Getting LoadBalancer Name and Group:: %+v", err)
return fmt.Errorf("Error Getting Load Balancer Name and Group:: %+v", err)
}

future, err := client.CreateOrUpdate(ctx, resGroup, loadBalancerName, *loadBalancer)
Expand All @@ -236,10 +236,10 @@ func resourceArmLoadBalancerBackendAddressPoolDelete(d *schema.ResourceData, met

read, err := client.Get(ctx, resGroup, loadBalancerName, "")
if err != nil {
return fmt.Errorf("Error retrieving the LoadBalancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
return fmt.Errorf("Error retrieving the Load Balancer %q (Resource Group %q): %+v", loadBalancerName, resGroup, err)
}
if read.ID == nil {
return fmt.Errorf("Cannot read LoadBalancer %q (resource group %q) ID", loadBalancerName, resGroup)
return fmt.Errorf("Cannot read Load Balancer %q (resource group %q) ID", loadBalancerName, resGroup)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ func testCheckAzureRMLoadBalancerBackEndAddressPoolDisappears(addressPoolName st

future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, *lb.Name, *lb)
if err != nil {
return fmt.Errorf("Error Creating/Updating LoadBalancer %+v", err)
return fmt.Errorf("Error Creating/Updating Load Balancer %+v", err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error Creating/Updating LoadBalancer %+v", err)
return fmt.Errorf("Error Creating/Updating Load Balancer %+v", err)
}

_, err = client.Get(ctx, id.ResourceGroup, *lb.Name, "")
Expand Down
Loading

0 comments on commit 3c6a1ad

Please sign in to comment.