diff --git a/azurerm/internal/services/network/resource_arm_route.go b/azurerm/internal/services/network/resource_arm_route.go index 7cc9d5352056..08d7aaf88da3 100644 --- a/azurerm/internal/services/network/resource_arm_route.go +++ b/azurerm/internal/services/network/resource_arm_route.go @@ -40,7 +40,7 @@ func resourceArmRoute() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: ValidateRouteName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -49,7 +49,7 @@ func resourceArmRoute() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: ValidateRouteTableName, }, "address_prefix": { diff --git a/azurerm/internal/services/network/resource_arm_route_table.go b/azurerm/internal/services/network/resource_arm_route_table.go index 1929af641129..356e7729e5dd 100644 --- a/azurerm/internal/services/network/resource_arm_route_table.go +++ b/azurerm/internal/services/network/resource_arm_route_table.go @@ -46,7 +46,7 @@ func resourceArmRouteTable() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: ValidateRouteTableName, }, "location": azure.SchemaLocation(), @@ -63,7 +63,7 @@ func resourceArmRouteTable() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: ValidateRouteName, }, "address_prefix": { diff --git a/azurerm/internal/services/network/validate.go b/azurerm/internal/services/network/validate.go index e5e62e1c9ca8..2f80fa4aca79 100644 --- a/azurerm/internal/services/network/validate.go +++ b/azurerm/internal/services/network/validate.go @@ -147,3 +147,20 @@ func ValidatePrivateLinkSubResourceName(i interface{}, k string) (_ []string, er return nil, errors } + +func ValidateRouteTableName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if !regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,78}[a-zA-Z0-9_]?$`).MatchString(value) { + errors = append(errors, fmt.Errorf("%q should be between 1 and 80 characters, start with an alphanumeric, end with an alphanumeric or underscore and can contain alphanumerics, underscores, periods, and hyphens", k)) + } + + return warnings, errors +} + +func ValidateRouteName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if !regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,78}[a-zA-Z0-9_]?$`).MatchString(value) { + errors = append(errors, fmt.Errorf("%q should be between 1 and 80 characters, start with an alphanumeric, end with an alphanumeric or underscore and can contain alphanumerics, underscores, periods, and hyphens", k)) + } + return warnings, errors +}