-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/azurerm: Add AzureRM Loadbalancer resource
Adds support for the elusive Azure LoadBalancer * [x] `azurerm_lb` * [x] `azurerm_lb_backend_address_pool` * [x] `azurerm_lb_rule` * [x] `azurerm_lb_nat_rule` * [x] `azurerm_lb_probe` * [x] `azurerm_lb_nat_pool` Test Results: ``` ```
- Loading branch information
Showing
15 changed files
with
2,721 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Azure/azure-sdk-for-go/arm/network" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func resourceGroupAndLBNameFromId(loadBalancerId string) (string, string, error) { | ||
id, err := parseAzureResourceID(loadBalancerId) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
name := id.Path["loadBalancers"] | ||
resGroup := id.ResourceGroup | ||
|
||
return resGroup, name, nil | ||
} | ||
|
||
func retrieveLoadbalancerById(loadBalancerId string, meta interface{}) (*network.LoadBalancer, bool, error) { | ||
loadBalancerClient := meta.(*ArmClient).loadBalancerClient | ||
|
||
resGroup, name, err := resourceGroupAndLBNameFromId(loadBalancerId) | ||
if err != nil { | ||
return nil, false, errwrap.Wrapf("TODO: error message {{err}}", err) | ||
} | ||
|
||
resp, err := loadBalancerClient.Get(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 &resp, true, nil | ||
} | ||
|
||
func findLoadBalancerBackEndAddressPoolByName(lb *network.LoadBalancer, name string) (*network.BackendAddressPool, int, bool) { | ||
if lb == nil || lb.Properties == nil || lb.Properties.BackendAddressPools == nil { | ||
return nil, -1, false | ||
} | ||
|
||
for i, apc := range *lb.Properties.BackendAddressPools { | ||
if apc.Name != nil && *apc.Name == name { | ||
return &apc, i, true | ||
} | ||
} | ||
|
||
return nil, -1, false | ||
} | ||
|
||
func findLoadBalancerFrontEndIpConfigurationByName(lb *network.LoadBalancer, name string) (*network.FrontendIPConfiguration, int, bool) { | ||
if lb == nil || lb.Properties == nil || lb.Properties.FrontendIPConfigurations == nil { | ||
return nil, -1, false | ||
} | ||
|
||
for i, feip := range *lb.Properties.FrontendIPConfigurations { | ||
if feip.Name != nil && *feip.Name == name { | ||
return &feip, i, true | ||
} | ||
} | ||
|
||
return nil, -1, false | ||
} | ||
|
||
func findLoadBalancerRuleByName(lb *network.LoadBalancer, name string) (*network.LoadBalancingRule, int, bool) { | ||
if lb == nil || lb.Properties == nil || lb.Properties.LoadBalancingRules == nil { | ||
return nil, -1, false | ||
} | ||
|
||
for i, lbr := range *lb.Properties.LoadBalancingRules { | ||
if lbr.Name != nil && *lbr.Name == name { | ||
return &lbr, i, true | ||
} | ||
} | ||
|
||
return nil, -1, false | ||
} | ||
|
||
func findLoadBalancerNatRuleByName(lb *network.LoadBalancer, name string) (*network.InboundNatRule, int, bool) { | ||
if lb == nil || lb.Properties == nil || lb.Properties.InboundNatRules == nil { | ||
return nil, -1, false | ||
} | ||
|
||
for i, nr := range *lb.Properties.InboundNatRules { | ||
if nr.Name != nil && *nr.Name == name { | ||
return &nr, i, true | ||
} | ||
} | ||
|
||
return nil, -1, false | ||
} | ||
|
||
func findLoadBalancerNatPoolByName(lb *network.LoadBalancer, name string) (*network.InboundNatPool, int, bool) { | ||
if lb == nil || lb.Properties == nil || lb.Properties.InboundNatPools == nil { | ||
return nil, -1, false | ||
} | ||
|
||
for i, np := range *lb.Properties.InboundNatPools { | ||
if np.Name != nil && *np.Name == name { | ||
return &np, i, true | ||
} | ||
} | ||
|
||
return nil, -1, false | ||
} | ||
|
||
func findLoadBalancerProbeByName(lb *network.LoadBalancer, name string) (*network.Probe, int, bool) { | ||
if lb == nil || lb.Properties == nil || lb.Properties.Probes == nil { | ||
return nil, -1, false | ||
} | ||
|
||
for i, p := range *lb.Properties.Probes { | ||
if p.Name != nil && *p.Name == name { | ||
return &p, i, true | ||
} | ||
} | ||
|
||
return nil, -1, false | ||
} | ||
|
||
func loadbalancerStateRefreshFunc(client *ArmClient, resourceGroupName string, loadbalancer string) resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
res, err := client.loadBalancerClient.Get(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 res, *res.Properties.ProvisioningState, nil | ||
} | ||
} | ||
|
||
func validateLoadbalancerPrivateIpAddressAllocation(v interface{}, k string) (ws []string, errors []error) { | ||
value := strings.ToLower(v.(string)) | ||
allocations := map[string]bool{ | ||
"static": true, | ||
"dynamic": true, | ||
} | ||
|
||
if !allocations[value] { | ||
errors = append(errors, fmt.Errorf("Loadbalancer Allocations can only be Static or Dynamic")) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.