Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_lb_rule: backport of azure stack PR review comments #1754

Merged
merged 2 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azurerm/resource_arm_loadbalancer_probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccAzureRMLoadBalancerProbe_basic(t *testing.T) {
probeName := fmt.Sprintf("probe-%d", ri)

subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID")
probe_id := fmt.Sprintf(
probeId := fmt.Sprintf(
"/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/probes/%s",
subscriptionID, ri, ri, probeName)

Expand All @@ -32,7 +32,7 @@ func TestAccAzureRMLoadBalancerProbe_basic(t *testing.T) {
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
testCheckAzureRMLoadBalancerProbeExists(probeName, &lb),
resource.TestCheckResourceAttr(
"azurerm_lb_probe.test", "id", probe_id),
"azurerm_lb_probe.test", "id", probeId),
),
},
},
Expand Down
111 changes: 60 additions & 51 deletions azurerm/resource_arm_loadbalancer_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-04-01/network"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
"github.com/terraform-providers/terraform-provider-azurestack/azurestack/helpers/azure"
)

func resourceArmLoadBalancerRule() *schema.Resource {
Expand All @@ -18,6 +22,7 @@ func resourceArmLoadBalancerRule() *schema.Resource {
Read: resourceArmLoadBalancerRuleRead,
Update: resourceArmLoadBalancerRuleCreate,
Delete: resourceArmLoadBalancerRuleDelete,

Importer: &schema.ResourceImporter{
State: loadBalancerSubResourceStateImporter,
},
Expand All @@ -35,14 +40,16 @@ func resourceArmLoadBalancerRule() *schema.Resource {
"resource_group_name": resourceGroupNameSchema(),

"loadbalancer_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceId,
},

"frontend_ip_configuration_name": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"frontend_ip_configuration_id": {
Expand All @@ -60,17 +67,24 @@ func resourceArmLoadBalancerRule() *schema.Resource {
Type: schema.TypeString,
Required: true,
StateFunc: ignoreCaseStateFunc,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(network.TransportProtocolAll),
string(network.TransportProtocolTCP),
string(network.TransportProtocolUDP),
}, true),
},

"frontend_port": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Required: true,
ValidateFunc: validate.PortNumber,
},

"backend_port": {
Type: schema.TypeInt,
Required: true,
Type: schema.TypeInt,
Required: true,
ValidateFunc: validate.PortNumber,
},

"probe_id": {
Expand All @@ -86,9 +100,10 @@ func resourceArmLoadBalancerRule() *schema.Resource {
},

"idle_timeout_in_minutes": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(4, 30),
},

"load_distribution": {
Expand Down Expand Up @@ -211,38 +226,40 @@ func resourceArmLoadBalancerRuleRead(d *schema.ResourceData, meta interface{}) e
d.Set("name", config.Name)
d.Set("resource_group_name", id.ResourceGroup)

d.Set("protocol", config.LoadBalancingRulePropertiesFormat.Protocol)
d.Set("frontend_port", config.LoadBalancingRulePropertiesFormat.FrontendPort)
d.Set("backend_port", config.LoadBalancingRulePropertiesFormat.BackendPort)
if properties := config.LoadBalancingRulePropertiesFormat; properties != nil {
d.Set("protocol", properties.Protocol)
d.Set("frontend_port", properties.FrontendPort)
d.Set("backend_port", properties.BackendPort)

if config.LoadBalancingRulePropertiesFormat.EnableFloatingIP != nil {
d.Set("enable_floating_ip", config.LoadBalancingRulePropertiesFormat.EnableFloatingIP)
}

if config.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes != nil {
d.Set("idle_timeout_in_minutes", config.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes)
}
if properties.EnableFloatingIP != nil {
d.Set("enable_floating_ip", properties.EnableFloatingIP)
}

if config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration != nil {
fipID, err := parseAzureResourceID(*config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration.ID)
if err != nil {
return err
if properties.IdleTimeoutInMinutes != nil {
d.Set("idle_timeout_in_minutes", properties.IdleTimeoutInMinutes)
}

d.Set("frontend_ip_configuration_name", fipID.Path["frontendIPConfigurations"])
d.Set("frontend_ip_configuration_id", config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration.ID)
}
if properties.FrontendIPConfiguration != nil {
fipID, err := parseAzureResourceID(*properties.FrontendIPConfiguration.ID)
if err != nil {
return err
}

if config.LoadBalancingRulePropertiesFormat.BackendAddressPool != nil {
d.Set("backend_address_pool_id", config.LoadBalancingRulePropertiesFormat.BackendAddressPool.ID)
}
d.Set("frontend_ip_configuration_name", fipID.Path["frontendIPConfigurations"])
d.Set("frontend_ip_configuration_id", properties.FrontendIPConfiguration.ID)
}

if config.LoadBalancingRulePropertiesFormat.Probe != nil {
d.Set("probe_id", config.LoadBalancingRulePropertiesFormat.Probe.ID)
}
if properties.BackendAddressPool != nil {
d.Set("backend_address_pool_id", properties.BackendAddressPool.ID)
}

if properties.Probe != nil {
d.Set("probe_id", properties.Probe.ID)
}

if config.LoadBalancingRulePropertiesFormat.LoadDistribution != "" {
d.Set("load_distribution", config.LoadBalancingRulePropertiesFormat.LoadDistribution)
if properties.LoadDistribution != "" {
d.Set("load_distribution", properties.LoadDistribution)
}
}

return nil
Expand Down Expand Up @@ -323,35 +340,27 @@ func expandAzureRmLoadBalancerRule(d *schema.ResourceData, lb *network.LoadBalan
return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v)
}

feip := network.SubResource{
properties.FrontendIPConfiguration = &network.SubResource{
ID: rule.ID,
}

properties.FrontendIPConfiguration = &feip
}

if v := d.Get("backend_address_pool_id").(string); v != "" {
beAP := network.SubResource{
properties.BackendAddressPool = &network.SubResource{
ID: &v,
}

properties.BackendAddressPool = &beAP
}

if v := d.Get("probe_id").(string); v != "" {
pid := network.SubResource{
properties.Probe = &network.SubResource{
ID: &v,
}

properties.Probe = &pid
}

lbRule := network.LoadBalancingRule{
return &network.LoadBalancingRule{
Name: utils.String(d.Get("name").(string)),
LoadBalancingRulePropertiesFormat: &properties,
}

return &lbRule, nil
}, nil
}

func validateArmLoadBalancerRuleName(v interface{}, k string) (ws []string, errors []error) {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/loadbalancer_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-

# azurerm_lb_rule

Create a Load Balancer Rule.
Manages a Load Balancer Rule.

~> **NOTE** When using this resource, the Load Balancer needs to have a FrontEnd IP Configuration Attached

Expand Down Expand Up @@ -57,7 +57,7 @@ The following arguments are supported:
* `resource_group_name` - (Required) The name of the resource group in which to create the resource.
* `loadbalancer_id` - (Required) The ID of the Load Balancer in which to create the Rule.
* `frontend_ip_configuration_name` - (Required) The name of the frontend IP configuration to which the rule is associated.
* `protocol` - (Required) The transport protocol for the external endpoint. Possible values are `Udp` or `Tcp`.
* `protocol` - (Required) The transport protocol for the external endpoint. Possible values are `Tcp`, `Udp` or `All`.
* `frontend_port` - (Required) The port for the external endpoint. Port numbers for each Rule must be unique within the Load Balancer. Possible values range between 1 and 65534, inclusive.
* `backend_port` - (Required) The port used for internal connections on the endpoint. Possible values range between 1 and 65535, inclusive.
* `backend_address_pool_id` - (Optional) A reference to a Backend Address Pool over which this Load Balancing Rule operates.
Expand Down