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_probe: backport azurestack review comments #1742

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 20 additions & 10 deletions azurerm/resource_arm_loadbalancer_backend_address_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/hashicorp/errwrap"
"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/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -23,33 +25,41 @@ func resourceArmLoadBalancerBackendAddressPool() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"location": deprecatedLocationSchema(),

"resource_group_name": resourceGroupNameSchema(),

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

"backend_ip_configurations": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Set: schema.HashString,
},

"load_balancing_rules": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Set: schema.HashString,
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion azurerm/resource_arm_loadbalancer_nat_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"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"
)
Expand Down Expand Up @@ -49,7 +50,7 @@ func resourceArmLoadBalancerNatRule() *schema.Resource {
Type: schema.TypeString,
Required: true,
StateFunc: ignoreCaseStateFunc,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(network.TransportProtocolAll),
string(network.TransportProtocolTCP),
Expand Down
91 changes: 54 additions & 37 deletions azurerm/resource_arm_loadbalancer_probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,59 @@ import (
"github.com/hashicorp/errwrap"
"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/azure"
"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"
)

func resourceArmLoadBalancerProbe() *schema.Resource {
return &schema.Resource{
Create: resourceArmLoadBalancerProbeCreate,
Create: resourceArmLoadBalancerProbeCreateUpdate,
Read: resourceArmLoadBalancerProbeRead,
Update: resourceArmLoadBalancerProbeCreate,
Update: resourceArmLoadBalancerProbeCreateUpdate,
Delete: resourceArmLoadBalancerProbeDelete,
Importer: &schema.ResourceImporter{
State: loadBalancerSubResourceStateImporter,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"location": deprecatedLocationSchema(),

"resource_group_name": resourceGroupNameSchema(),

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

"protocol": {
Type: schema.TypeString,
Computed: true,
Optional: true,
StateFunc: ignoreCaseStateFunc,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(network.ProbeProtocolHTTP),
string(network.ProbeProtocolHTTPS),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: We may want to consider adding an acceptance test to cover this new value

string(network.ProbeProtocolTCP),
}, true),
},

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

"request_path": {
Expand All @@ -58,9 +70,10 @@ func resourceArmLoadBalancerProbe() *schema.Resource {
},

"interval_in_seconds": {
Type: schema.TypeInt,
Optional: true,
Default: 15,
Type: schema.TypeInt,
Optional: true,
Default: 15,
ValidateFunc: validation.IntAtLeast(5),
},

"number_of_probes": {
Expand All @@ -72,14 +85,17 @@ func resourceArmLoadBalancerProbe() *schema.Resource {
"load_balancer_rules": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
},
Set: schema.HashString,
},
},
}
}

func resourceArmLoadBalancerProbeCreate(d *schema.ResourceData, meta interface{}) error {
func resourceArmLoadBalancerProbeCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).loadBalancerClient
ctx := meta.(*ArmClient).StopContext

Expand All @@ -97,11 +113,7 @@ func resourceArmLoadBalancerProbeCreate(d *schema.ResourceData, meta interface{}
return nil
}

newProbe, err := expandAzureRmLoadBalancerProbe(d, loadBalancer)
if err != nil {
return fmt.Errorf("Error Expanding Probe: %+v", err)
}

newProbe := expandAzureRmLoadBalancerProbe(d)
probes := append(*loadBalancer.LoadBalancerPropertiesFormat.Probes, *newProbe)

existingProbe, existingProbeIndex, exists := findLoadBalancerProbeByName(loadBalancer, d.Get("name").(string))
Expand Down Expand Up @@ -189,19 +201,26 @@ func resourceArmLoadBalancerProbeRead(d *schema.ResourceData, meta interface{})

d.Set("name", config.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("protocol", config.ProbePropertiesFormat.Protocol)
d.Set("interval_in_seconds", config.ProbePropertiesFormat.IntervalInSeconds)
d.Set("number_of_probes", config.ProbePropertiesFormat.NumberOfProbes)
d.Set("port", config.ProbePropertiesFormat.Port)
d.Set("request_path", config.ProbePropertiesFormat.RequestPath)

var load_balancer_rules []string
if config.ProbePropertiesFormat.LoadBalancingRules != nil {
for _, ruleConfig := range *config.ProbePropertiesFormat.LoadBalancingRules {
load_balancer_rules = append(load_balancer_rules, *ruleConfig.ID)

if properties := config.ProbePropertiesFormat; properties != nil {
d.Set("protocol", properties.Protocol)
d.Set("interval_in_seconds", properties.IntervalInSeconds)
d.Set("number_of_probes", properties.NumberOfProbes)
d.Set("port", properties.Port)
d.Set("request_path", properties.RequestPath)

var load_balancer_rules []string
if rules := properties.LoadBalancingRules; rules != nil {
for _, ruleConfig := range *rules {
if id := ruleConfig.ID; id != nil {
load_balancer_rules = append(load_balancer_rules, *id)
}
}
}
if err := d.Set("load_balancer_rules", load_balancer_rules); err != nil {
return fmt.Errorf("Error setting `load_balancer_rules` (Load Balancer Probe %q): %+v", name, err)
}
}
d.Set("load_balancer_rules", load_balancer_rules)

return nil
}
Expand Down Expand Up @@ -258,7 +277,7 @@ func resourceArmLoadBalancerProbeDelete(d *schema.ResourceData, meta interface{}
return nil
}

func expandAzureRmLoadBalancerProbe(d *schema.ResourceData, lb *network.LoadBalancer) (*network.Probe, error) {
func expandAzureRmLoadBalancerProbe(d *schema.ResourceData) *network.Probe {

properties := network.ProbePropertiesFormat{
NumberOfProbes: utils.Int32(int32(d.Get("number_of_probes").(int))),
Expand All @@ -274,10 +293,8 @@ func expandAzureRmLoadBalancerProbe(d *schema.ResourceData, lb *network.LoadBala
properties.RequestPath = utils.String(v.(string))
}

probe := network.Probe{
return &network.Probe{
Name: utils.String(d.Get("name").(string)),
ProbePropertiesFormat: &properties,
}

return &probe, nil
}
4 changes: 2 additions & 2 deletions website/docs/r/loadbalancer_probe.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-

# azurerm_lb_probe

Create a LoadBalancer Probe Resource.
Manages a LoadBalancer Probe Resource.

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

Expand Down Expand Up @@ -53,7 +53,7 @@ The following arguments are supported:
* `name` - (Required) Specifies the name of the Probe.
* `resource_group_name` - (Required) The name of the resource group in which to create the resource.
* `loadbalancer_id` - (Required) The ID of the LoadBalancer in which to create the NAT Rule.
* `protocol` - (Optional) Specifies the protocol of the end point. Possible values are `Http` or `Tcp`. If Tcp is specified, a received ACK is required for the probe to be successful. If Http is specified, a 200 OK response from the specified URI is required for the probe to be successful.
* `protocol` - (Optional) Specifies the protocol of the end point. Possible values are `Http`, `Https` or `Tcp`. If Tcp is specified, a received ACK is required for the probe to be successful. If Http is specified, a 200 OK response from the specified URI is required for the probe to be successful.
* `port` - (Required) Port on which the Probe queries the backend endpoint. Possible values range from 1 to 65535, inclusive.
* `request_path` - (Optional) The URI used for requesting health status from the backend endpoint. Required if protocol is set to Http. Otherwise, it is not allowed.
* `interval_in_seconds` - (Optional) The interval, in seconds between probes to the backend endpoint for health status. The default value is 15, the minimum value is 5.
Expand Down