Skip to content

Commit

Permalink
Merge pull request #6055 from adesso-as-a-service/yves-vogl/fix-6053
Browse files Browse the repository at this point in the history
azurerm_route - add validation to routing table name and route name (#6053)
  • Loading branch information
jackofallops authored Apr 23, 2020
2 parents 1089169 + f88b9c6 commit e85d13e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions azurerm/internal/services/network/resource_arm_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -49,7 +49,7 @@ func resourceArmRoute() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
ValidateFunc: ValidateRouteTableName,
},

"address_prefix": {
Expand Down
4 changes: 2 additions & 2 deletions azurerm/internal/services/network/resource_arm_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func resourceArmRouteTable() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
ValidateFunc: ValidateRouteTableName,
},

"location": azure.SchemaLocation(),
Expand All @@ -63,7 +63,7 @@ func resourceArmRouteTable() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
ValidateFunc: ValidateRouteName,
},

"address_prefix": {
Expand Down
17 changes: 17 additions & 0 deletions azurerm/internal/services/network/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit e85d13e

Please sign in to comment.