Skip to content

Commit

Permalink
Merge pull request #6435 from aristosvo/functionslot
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed May 6, 2020
2 parents 2c60f40 + 53218ea commit e0397cd
Show file tree
Hide file tree
Showing 12 changed files with 3,473 additions and 17 deletions.
3 changes: 2 additions & 1 deletion azurerm/internal/services/web/data_source_function_app.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
webValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand All @@ -25,7 +26,7 @@ func dataSourceArmFunctionApp() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateAppServiceName,
ValidateFunc: webValidate.AppServiceName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
Expand Down
40 changes: 40 additions & 0 deletions azurerm/internal/services/web/parse/function_app_slot.go
@@ -0,0 +1,40 @@
package parse

import (
"fmt"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type FunctionAppSlotResourceID struct {
ResourceGroup string
FunctionAppName string
Name string
}

func FunctionAppSlotID(input string) (*FunctionAppSlotResourceID, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse App Service Slot ID %q: %+v", input, err)
}

slot := FunctionAppSlotResourceID{
ResourceGroup: id.ResourceGroup,
FunctionAppName: id.Path["sites"],
Name: id.Path["slots"],
}

if slot.FunctionAppName, err = id.PopSegment("sites"); err != nil {
return nil, err
}

if slot.Name, err = id.PopSegment("slots"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &slot, nil
}
1 change: 1 addition & 0 deletions azurerm/internal/services/web/registration.go
Expand Up @@ -44,5 +44,6 @@ func (r Registration) SupportedResources() map[string]*schema.Resource {
"azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(),
"azurerm_app_service": resourceArmAppService(),
"azurerm_function_app": resourceArmFunctionApp(),
"azurerm_function_app_slot": resourceArmFunctionAppSlot(),
}
}
14 changes: 2 additions & 12 deletions azurerm/internal/services/web/resource_arm_app_service.go
Expand Up @@ -3,7 +3,6 @@ package web
import (
"fmt"
"log"
"regexp"
"time"

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -44,7 +44,7 @@ func resourceArmAppService() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateAppServiceName,
ValidateFunc: validate.AppServiceName,
},

"identity": azure.SchemaAppServiceIdentity(),
Expand Down Expand Up @@ -760,16 +760,6 @@ func flattenAppServiceAppSettings(input map[string]*string) map[string]string {
return output
}

func validateAppServiceName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)

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

return warnings, errors
}

func flattenAppServiceSiteCredential(input *web.UserProperties) []interface{} {
results := make([]interface{}, 0)
result := make(map[string]interface{})
Expand Down
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
webValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -42,7 +43,7 @@ func resourceArmAppServiceSlot() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateAppServiceName,
ValidateFunc: webValidate.AppServiceName,
},

"resource_group_name": azure.SchemaResourceGroupName(),
Expand Down
3 changes: 2 additions & 1 deletion azurerm/internal/services/web/resource_arm_function_app.go
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage"
webValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -48,7 +49,7 @@ func resourceArmFunctionApp() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateAppServiceName,
ValidateFunc: webValidate.AppServiceName,
},

"resource_group_name": azure.SchemaResourceGroupName(),
Expand Down

0 comments on commit e0397cd

Please sign in to comment.