Skip to content

Commit

Permalink
Merge pull request #1351 from shanepoint/b-appserviceplan-validation
Browse files Browse the repository at this point in the history
Updated resource_arm_app_service_plan Validation to Allow Underscore
  • Loading branch information
katbyte committed Jun 6, 2018
2 parents 0e0d185 + a4956d5 commit 47dcea0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ func flattenAzureRmAppServiceMachineIdentity(identity *web.ManagedServiceIdentit
func validateAppServiceName(v interface{}, k string) (ws []string, es []error) {
value := v.(string)

if matched := regexp.MustCompile(`^[0-9a-zA-Z-]+$`).Match([]byte(value)); !matched {
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k))
if matched := regexp.MustCompile(`^[0-9a-zA-Z-]{1,60}$`).Match([]byte(value)); !matched {
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes and up to 60 characters in length", k))
}

return
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ func flattenAppServiceProperties(props *web.AppServicePlanProperties) []interfac
func validateAppServicePlanName(v interface{}, k string) (ws []string, es []error) {
value := v.(string)

if matched := regexp.MustCompile(`^[0-9a-zA-Z-]+$`).Match([]byte(value)); !matched {
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k))
if matched := regexp.MustCompile(`^[0-9a-zA-Z-_]{1,60}$`).Match([]byte(value)); !matched {
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters, dashes and underscores up to 60 characters in length", k))
}

return
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_app_service_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestAzureRMAppServicePlanName_validation(t *testing.T) {
},
{
Value: "hello_world",
ErrCount: 1,
ErrCount: 0,
},
{
Value: "helloworld21!",
Expand Down
11 changes: 9 additions & 2 deletions examples/app-service/app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ resource "azurerm_resource_group" "default" {
location = "${var.location}"
}


resource "random_integer" "ri" {
min = 10000
max = 99999
}


resource "azurerm_app_service_plan" "default" {
name = "${var.app_service_name}-plan"
name = "tfex-appservice-${random_integer.ri.result}-plan"
location = "${azurerm_resource_group.default.location}"
resource_group_name = "${azurerm_resource_group.default.name}"

Expand All @@ -20,7 +27,7 @@ resource "azurerm_app_service_plan" "default" {
}

resource "azurerm_app_service" "default" {
name = "${var.app_service_name}"
name = "tfex-appservice-${random_integer.ri.result}"
location = "${azurerm_resource_group.default.location}"
resource_group_name = "${azurerm_resource_group.default.name}"
app_service_plan_id = "${azurerm_app_service_plan.default.id}"
Expand Down
21 changes: 12 additions & 9 deletions examples/app-service/variables.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
variable "resource_group_name" {
type = "string"
type = "string"
description = "Name of the azure resource group."
default = "tfex-appserviceplan"
}

variable "location" {
type = "string"
type = "string"
description = "Location of the azure resource group."
default = "westus"
}

variable "app_service_name" {
type = "string"
}

variable "app_service_plan_sku_tier" {
type = "string"
default = "Basic" # Basic | Standard | ...
type = "string"
description = "SKU tier of the App Service Plan"
default = "Basic" # Basic | Standard | ...
}

variable "app_service_plan_sku_size" {
type = "string"
default = "B1" # B1 | S1 | ...
type = "string"
description = "SKU size of the App Service Plan"
default = "B1" # B1 | S1 | ...
}

0 comments on commit 47dcea0

Please sign in to comment.