mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-07 22:53:08 -06:00
provider/azurerm: refactor traffic_manager_ resources to use validation helpers
Updated: traffic_manager_profile traffic_manager_endpoint
This commit is contained in:
parent
8abec085ec
commit
012fd9825f
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/arm/trafficmanager"
|
"github.com/Azure/azure-sdk-for-go/arm/trafficmanager"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"github.com/hashicorp/terraform/helper/validation"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceArmTrafficManagerEndpoint() *schema.Resource {
|
func resourceArmTrafficManagerEndpoint() *schema.Resource {
|
||||||
@ -30,7 +31,7 @@ func resourceArmTrafficManagerEndpoint() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerEndpointType,
|
ValidateFunc: validation.StringInSlice([]string{"azureEndpoints", "nestedEndpoints", "externalEndpoints"}, false),
|
||||||
},
|
},
|
||||||
|
|
||||||
"profile_name": {
|
"profile_name": {
|
||||||
@ -61,14 +62,14 @@ func resourceArmTrafficManagerEndpoint() *schema.Resource {
|
|||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerEndpointWeight,
|
ValidateFunc: validation.IntBetween(1, 1000),
|
||||||
},
|
},
|
||||||
|
|
||||||
"priority": {
|
"priority": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerEndpointPriority,
|
ValidateFunc: validation.IntBetween(1, 1000),
|
||||||
},
|
},
|
||||||
|
|
||||||
"endpoint_location": {
|
"endpoint_location": {
|
||||||
@ -220,32 +221,3 @@ func getArmTrafficManagerEndpointProperties(d *schema.ResourceData) *trafficmana
|
|||||||
|
|
||||||
return &endpointProps
|
return &endpointProps
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerEndpointType(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
valid := map[string]struct{}{
|
|
||||||
"azureEndpoints": struct{}{},
|
|
||||||
"externalEndpoints": struct{}{},
|
|
||||||
"nestedEndpoints": struct{}{},
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := valid[i.(string)]; !ok {
|
|
||||||
errors = append(errors, fmt.Errorf("endpoint type invalid, got %s", i.(string)))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerEndpointWeight(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
w := i.(int)
|
|
||||||
if w < 1 || w > 1000 {
|
|
||||||
errors = append(errors, fmt.Errorf("endpoint weight must be between 1-1000 inclusive"))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerEndpointPriority(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
p := i.(int)
|
|
||||||
if p < 1 || p > 1000 {
|
|
||||||
errors = append(errors, fmt.Errorf("endpoint priority must be between 1-1000 inclusive"))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/Azure/azure-sdk-for-go/arm/trafficmanager"
|
"github.com/Azure/azure-sdk-for-go/arm/trafficmanager"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"github.com/hashicorp/terraform/helper/validation"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceArmTrafficManagerProfile() *schema.Resource {
|
func resourceArmTrafficManagerProfile() *schema.Resource {
|
||||||
@ -33,13 +34,13 @@ func resourceArmTrafficManagerProfile() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerStatus,
|
ValidateFunc: validation.StringInSlice([]string{"Enabled", "Disabled"}, true),
|
||||||
},
|
},
|
||||||
|
|
||||||
"traffic_routing_method": {
|
"traffic_routing_method": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerRoutingMethod,
|
ValidateFunc: validation.StringInSlice([]string{"Performance", "Weighted", "Priority"}, false),
|
||||||
},
|
},
|
||||||
|
|
||||||
"dns_config": {
|
"dns_config": {
|
||||||
@ -55,7 +56,7 @@ func resourceArmTrafficManagerProfile() *schema.Resource {
|
|||||||
"ttl": {
|
"ttl": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Required: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerTTL,
|
ValidateFunc: validation.IntBetween(30, 999999),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -76,12 +77,12 @@ func resourceArmTrafficManagerProfile() *schema.Resource {
|
|||||||
"protocol": {
|
"protocol": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerMonitorProtocol,
|
ValidateFunc: validation.StringInSlice([]string{"http", "https"}, false),
|
||||||
},
|
},
|
||||||
"port": {
|
"port": {
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Required: true,
|
Required: true,
|
||||||
ValidateFunc: validateAzureRMTrafficManagerMonitorPort,
|
ValidateFunc: validation.IntBetween(1, 65535),
|
||||||
},
|
},
|
||||||
"path": {
|
"path": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@ -276,48 +277,3 @@ func resourceAzureRMTrafficManagerMonitorConfigHash(v interface{}) int {
|
|||||||
|
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerStatus(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
status := strings.ToLower(i.(string))
|
|
||||||
if status != "enabled" && status != "disabled" {
|
|
||||||
errors = append(errors, fmt.Errorf("%s must be one of: Enabled, Disabled", k))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerRoutingMethod(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
valid := map[string]struct{}{
|
|
||||||
"Performance": struct{}{},
|
|
||||||
"Weighted": struct{}{},
|
|
||||||
"Priority": struct{}{},
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := valid[i.(string)]; !ok {
|
|
||||||
errors = append(errors, fmt.Errorf("traffic_routing_method must be one of (Performance, Weighted, Priority), got %s", i.(string)))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerTTL(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
ttl := i.(int)
|
|
||||||
if ttl < 30 || ttl > 999999 {
|
|
||||||
errors = append(errors, fmt.Errorf("ttl must be between 30 and 999,999 inclusive"))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerMonitorProtocol(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
p := i.(string)
|
|
||||||
if p != "http" && p != "https" {
|
|
||||||
errors = append(errors, fmt.Errorf("monitor_config.protocol must be one of: http, https"))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateAzureRMTrafficManagerMonitorPort(i interface{}, k string) (s []string, errors []error) {
|
|
||||||
p := i.(int)
|
|
||||||
if p < 1 || p > 65535 {
|
|
||||||
errors = append(errors, fmt.Errorf("monitor_config.port must be between 1 - 65535 inclusive"))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user