Skip to content

Commit

Permalink
Allow updating of CDN Endpoints. Fixes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jun 26, 2017
1 parent 6408714 commit f878366
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 19 deletions.
4 changes: 0 additions & 4 deletions azurerm/resource_arm_cdn_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ func resourceArmCdnEndpointRead(d *schema.ResourceData, meta interface{}) error
func resourceArmCdnEndpointUpdate(d *schema.ResourceData, meta interface{}) error {
cdnEndpointsClient := meta.(*ArmClient).cdnEndpointsClient

if !d.HasChange("tags") {
return nil
}

name := d.Get("name").(string)
resGroup := d.Get("resource_group_name").(string)
profileName := d.Get("profile_name").(string)
Expand Down
92 changes: 77 additions & 15 deletions azurerm/resource_arm_cdn_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestAccAzureRMCdnEndpoint_basic(t *testing.T) {
resourceName := "azurerm_cdn_endpoint.test"
ri := acctest.RandInt()
config := testAccAzureRMCdnEndpoint_basic(ri)

Expand All @@ -22,14 +23,15 @@ func TestAccAzureRMCdnEndpoint_basic(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
testCheckAzureRMCdnEndpointExists(resourceName),
),
},
},
})
}

func TestAccAzureRMCdnEndpoint_disappears(t *testing.T) {
resourceName := "azurerm_cdn_endpoint.test"
ri := acctest.RandInt()
config := testAccAzureRMCdnEndpoint_basic(ri)

Expand All @@ -41,16 +43,46 @@ func TestAccAzureRMCdnEndpoint_disappears(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
testCheckAzureRMCdnEndpointDisappears("azurerm_cdn_endpoint.test"),
testCheckAzureRMCdnEndpointExists(resourceName),
testCheckAzureRMCdnEndpointDisappears(resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccAzureRMCdnEndpoint_updateHostHeader(t *testing.T) {
resourceName := "azurerm_cdn_endpoint.test"
ri := acctest.RandInt()
config := testAccAzureRMCdnEndpoint_hostHeader(ri, "www.example.com")
updatedConfig := testAccAzureRMCdnEndpoint_hostHeader(ri, "www.example2.com")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCdnEndpointDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnEndpointExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "origin_host_header", "www.example.com"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnEndpointExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "origin_host_header", "www.example2.com"),
),
},
},
})
}

func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) {
resourceName := "azurerm_cdn_endpoint.test"
ri := acctest.RandInt()
preConfig := testAccAzureRMCdnEndpoint_withTags(ri)
postConfig := testAccAzureRMCdnEndpoint_withTagsUpdate(ri)
Expand All @@ -63,24 +95,19 @@ func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) {
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
resource.TestCheckResourceAttr(
"azurerm_cdn_endpoint.test", "tags.%", "2"),
resource.TestCheckResourceAttr(
"azurerm_cdn_endpoint.test", "tags.environment", "Production"),
resource.TestCheckResourceAttr(
"azurerm_cdn_endpoint.test", "tags.cost_center", "MSFT"),
testCheckAzureRMCdnEndpointExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"),
resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"),
),
},

{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
resource.TestCheckResourceAttr(
"azurerm_cdn_endpoint.test", "tags.%", "1"),
resource.TestCheckResourceAttr(
"azurerm_cdn_endpoint.test", "tags.environment", "staging"),
testCheckAzureRMCdnEndpointExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"),
),
},
},
Expand Down Expand Up @@ -198,6 +225,41 @@ resource "azurerm_cdn_endpoint" "test" {
`, rInt, rInt, rInt)
}

func testAccAzureRMCdnEndpoint_hostHeader(rInt int, domain string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "West US"
}
resource "azurerm_cdn_profile" "test" {
name = "acctestcdnprof%d"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard_Verizon"
}
resource "azurerm_cdn_endpoint" "test" {
name = "acctestcdnend%d"
profile_name = "${azurerm_cdn_profile.test.name}"
location = "West US"
resource_group_name = "${azurerm_resource_group.test.name}"
origin_host_header = "%s"
origin {
name = "acceptanceTestCdnOrigin2"
host_name = "www.example.com"
https_port = 443
http_port = 80
}
tags {
environment = "Production"
cost_center = "MSFT"
}
}
`, rInt, rInt, rInt, domain)
}

func testAccAzureRMCdnEndpoint_withTags(rInt int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit f878366

Please sign in to comment.