-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new resource and datasource for App Serice Environment (v2 suppo…
…rt only) Replaces #4956 Co-authored-by: @justinbarias
- Loading branch information
1 parent
a581836
commit 72d4ff0
Showing
30 changed files
with
75,896 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type SubnetID struct { | ||
ResourceGroup string | ||
VirtualNetworkName string | ||
Name string | ||
} | ||
|
||
func ParseSubnetID(input string) (*SubnetID, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("[ERROR] Unable to parse Subnet ID %q: %+v", input, err) | ||
} | ||
|
||
subnet := SubnetID{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if subnet.VirtualNetworkName, err = id.PopSegment("virtualNetworks"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if subnet.Name, err = id.PopSegment("subnets"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &subnet, nil | ||
} | ||
|
||
// ValidateSubnetID validates that the specified ID is a valid App Service ID | ||
func ValidateSubnetID(i interface{}, k string) (warnings []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := ParseSubnetID(v); err != nil { | ||
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) | ||
return | ||
} | ||
|
||
return warnings, errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type VirtualNetworkID struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func ParseVirtualNetworkID(input string) (*VirtualNetworkID, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("[ERROR] Unable to parse Subnet ID %q: %+v", input, err) | ||
} | ||
|
||
vnet := VirtualNetworkID{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if vnet.Name, err = id.PopSegment("virtualNetworks"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &vnet, nil | ||
} | ||
|
||
// ValidateVirtualNetworkID validates that the specified ID is a valid App Service ID | ||
func ValidateVirtualNetworkID(i interface{}, k string) (warnings []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := ParseVirtualNetworkID(v); err != nil { | ||
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) | ||
return | ||
} | ||
|
||
return warnings, errors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package web | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type AppServiceEnvironmentResourceID struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func ParseAppServiceEnvironmentID(input string) (*AppServiceEnvironmentResourceID, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("[ERROR] Unable to parse App Service Environment ID %q: %+v", input, err) | ||
} | ||
|
||
appServiceEnvironment := AppServiceEnvironmentResourceID{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if appServiceEnvironment.Name, err = id.PopSegment("hostingEnvironments"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &appServiceEnvironment, nil | ||
} | ||
|
||
// ValidateAppServiceID validates that the specified ID is a valid App Service ID | ||
func ValidateAppServiceEnvironmentID(i interface{}, k string) (warnings []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
if _, err := ParseAppServiceEnvironmentID(v); err != nil { | ||
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) | ||
return | ||
} | ||
|
||
return warnings, errors | ||
} | ||
|
||
func validateAppServiceEnvironmentName(v interface{}, k string) (warnings []string, errors []error) { | ||
value := v.(string) | ||
|
||
if matched := regexp.MustCompile(`^[0-9a-zA-Z][-0-9a-zA-Z]{0,61}[0-9a-zA-Z]$`).Match([]byte(value)); !matched { | ||
errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes up to 60 characters in length, and must start and end in an alphanumeric", k)) | ||
} | ||
|
||
return warnings, errors | ||
} | ||
|
||
func validateAppServiceEnvironmentPricingTier(v interface{}, k string) (warnings []string, errors []error) { | ||
tier := v.(string) | ||
|
||
valid := []string{"I1", "I2", "I3"} | ||
|
||
for _, val := range valid { | ||
if val == tier { | ||
return | ||
} | ||
} | ||
errors = append(errors, fmt.Errorf("pricing_tier must be one of %q", valid)) | ||
return warnings, errors | ||
} |
103 changes: 103 additions & 0 deletions
103
azurerm/internal/services/web/app_service_environment_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package web | ||
|
||
import "testing" | ||
|
||
func TestParseAppServiceEnvironmentID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *AppServiceEnvironmentResourceID | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing environment name value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/providers/Microsoft.Web/hostingEnvironments/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Valid", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup1/providers/Microsoft.Web/hostingEnvironments/TestASEv2", | ||
Expected: &AppServiceEnvironmentResourceID{ | ||
ResourceGroup: "testGroup1", | ||
Name: "TestASEv2", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ParseAppServiceEnvironmentID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} | ||
|
||
func TestValidateAppServiceEnvironmentID(t *testing.T) { | ||
cases := []struct { | ||
ID string | ||
Valid bool | ||
}{ | ||
{ | ||
ID: "", | ||
Valid: false, | ||
}, | ||
{ | ||
ID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Valid: false, | ||
}, | ||
{ | ||
ID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/", | ||
Valid: false, | ||
}, | ||
{ | ||
ID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/providers/Microsoft.Web/hostingEnvironments/", | ||
Valid: false, | ||
}, | ||
{ | ||
ID: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup1/providers/Microsoft.Web/hostingEnvironments/TestASEv2", | ||
Valid: true, | ||
}, | ||
} | ||
for _, tc := range cases { | ||
t.Logf("[DEBUG] Testing Value %s", tc.ID) | ||
_, errors := ValidateAppServiceEnvironmentID(tc.ID, "test") | ||
valid := len(errors) == 0 | ||
|
||
if tc.Valid != valid { | ||
t.Fatalf("Expected %t but got %t", tc.Valid, valid) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.