Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Service Custom Hostname Binding: support for multiple bindings #1970

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}