Skip to content

Commit

Permalink
App Service Custom Hostname Binding: support for multiple bindings (#…
Browse files Browse the repository at this point in the history
…1970)

before this change:

```
$ ARM_TEST_APP_SERVICE=tomdevacctest12345 ARM_TEST_DOMAIN=REDACTED ARM_ALT_TEST_DOMAIN=REDACTED acctests azurerm TestAccAzureRMAppServiceCustomHostnameBinding

=== RUN   TestAccAzureRMAppServiceCustomHostnameBinding
=== RUN   TestAccAzureRMAppServiceCustomHostnameBinding/basic
=== RUN   TestAccAzureRMAppServiceCustomHostnameBinding/basic/basic
=== RUN   TestAccAzureRMAppServiceCustomHostnameBinding/basic/import
--- PASS: TestAccAzureRMAppServiceCustomHostnameBinding (299.70s)
    --- PASS: TestAccAzureRMAppServiceCustomHostnameBinding/basic (299.70s)
        --- PASS: TestAccAzureRMAppServiceCustomHostnameBinding/basic/basic (135.97s)
        --- PASS: TestAccAzureRMAppServiceCustomHostnameBinding/basic/import (163.72s)
=== RUN   TestAccAzureRMAppServiceCustomHostnameBinding_multiple
--- FAIL: TestAccAzureRMAppServiceCustomHostnameBinding_multiple (112.01s)
	testing.go:573: Error destroying resource! WARNING: Dangling resources
		may exist. The full state and error is shown below.

		Error: Error applying: 1 error(s) occurred:

		* azurerm_app_service_custom_hostname_binding.test2 (destroy): 1 error(s) occurred:

		* azurerm_app_service_custom_hostname_binding.test2: web.AppsClient#DeleteHostNameBinding: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
```

after this change:

```
$ ARM_TEST_APP_SERVICE=tomdevacctest12345 ARM_TEST_DOMAIN=REDACTED ARM_ALT_TEST_DOMAIN=REDACTED acctests azurerm TestAccAzureRMAppServiceCustomHostnameBinding_multiple
=== RUN   TestAccAzureRMAppServiceCustomHostnameBinding_multiple
--- PASS: TestAccAzureRMAppServiceCustomHostnameBinding_multiple (157.72s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	158.148s
```
  • Loading branch information
tombuildsstuff authored Sep 25, 2018
1 parent 1bb0720 commit df50acd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
5 changes: 3 additions & 2 deletions azurerm/import_arm_app_service_hostname_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ func TestAccAzureRMAppServiceCustomHostnameBinding(t *testing.T) {
// the app service name being shared (so the tests don't conflict with each other)
testCases := map[string]map[string]func(t *testing.T){
"basic": {
"basic": testAccAzureRMAppServiceCustomHostnameBinding_basic,
"import": testAccAzureRMAppServiceCustomHostnameBinding_import,
"basic": testAccAzureRMAppServiceCustomHostnameBinding_basic,
"multiple": testAccAzureRMAppServiceCustomHostnameBinding_multiple,
"import": testAccAzureRMAppServiceCustomHostnameBinding_import,
},
}

Expand Down
8 changes: 8 additions & 0 deletions azurerm/resource_arm_app_service_custom_hostname_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

var appServiceCustomHostnameBindingResourceName = "azurerm_app_service_custom_hostname_binding"

func resourceArmAppServiceCustomHostnameBinding() *schema.Resource {
return &schema.Resource{
Create: resourceArmAppServiceCustomHostnameBindingCreate,
Expand Down Expand Up @@ -46,6 +48,9 @@ func resourceArmAppServiceCustomHostnameBindingCreate(d *schema.ResourceData, me
appServiceName := d.Get("app_service_name").(string)
hostname := d.Get("hostname").(string)

azureRMLockByName(appServiceName, appServiceCustomHostnameBindingResourceName)
defer azureRMUnlockByName(appServiceName, appServiceCustomHostnameBindingResourceName)

properties := web.HostNameBinding{
HostNameBindingProperties: &web.HostNameBindingProperties{
SiteName: utils.String(appServiceName),
Expand Down Expand Up @@ -110,6 +115,9 @@ func resourceArmAppServiceCustomHostnameBindingDelete(d *schema.ResourceData, me
appServiceName := id.Path["sites"]
hostname := id.Path["hostNameBindings"]

azureRMLockByName(appServiceName, appServiceCustomHostnameBindingResourceName)
defer azureRMUnlockByName(appServiceName, appServiceCustomHostnameBindingResourceName)

log.Printf("[DEBUG] Deleting App Service Hostname Binding %q (App Service %q / Resource Group %q)", hostname, appServiceName, resGroup)

ctx := meta.(*ArmClient).StopContext
Expand Down
52 changes: 52 additions & 0 deletions azurerm/resource_arm_app_service_custom_hostname_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ func testAccAzureRMAppServiceCustomHostnameBinding_basic(t *testing.T) {
})
}

func testAccAzureRMAppServiceCustomHostnameBinding_multiple(t *testing.T) {
appServiceEnvVariable := "ARM_TEST_APP_SERVICE"
appServiceEnv := os.Getenv(appServiceEnvVariable)
if appServiceEnv == "" {
t.Skipf("Skipping as %q is not specified", appServiceEnvVariable)
}

domainEnvVariable := "ARM_TEST_DOMAIN"
domainEnv := os.Getenv(domainEnvVariable)
if domainEnv == "" {
t.Skipf("Skipping as %q is not specified", domainEnvVariable)
}

altDomainEnvVariable := "ARM_ALT_TEST_DOMAIN"
altDomainEnv := os.Getenv(altDomainEnvVariable)
if domainEnv == "" {
t.Skipf("Skipping as %q is not specified", domainEnvVariable)
}

resourceName := "azurerm_app_service_custom_hostname_binding.test"
ri := acctest.RandInt()
location := testLocation()
config := testAccAzureRMAppServiceCustomHostnameBinding_multipleConfig(ri, location, appServiceEnv, domainEnv, altDomainEnv)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMAppServiceCustomHostnameBindingDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName),
),
},
},
})
}

func testCheckAzureRMAppServiceCustomHostnameBindingDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).appServicesClient

Expand Down Expand Up @@ -132,3 +171,16 @@ resource "azurerm_app_service_custom_hostname_binding" "test" {
}
`, rInt, location, rInt, appServiceName, domain)
}

func testAccAzureRMAppServiceCustomHostnameBinding_multipleConfig(rInt int, location, appServiceName, domain, altDomain string) string {
template := testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(rInt, location, appServiceName, domain)
return fmt.Sprintf(`
%s
resource "azurerm_app_service_custom_hostname_binding" "test2" {
hostname = "%s"
app_service_name = "${azurerm_app_service.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
`, template, altDomain)
}

0 comments on commit df50acd

Please sign in to comment.