From 825a41aa08fc5524db34bc10a473ff894a1395cc Mon Sep 17 00:00:00 2001 From: Peter McAtominey Date: Tue, 10 Jan 2017 08:49:30 +0000 Subject: [PATCH] provider/azurerm: fix update protocol for lb_probe (#11125) request_path had Computed enabled which prevented updating it to an empty value TF_ACC=1 go test ./builtin/providers/azurerm -v -run TestAccAzureRMLoadBalancerProbe -timeout 120m === RUN TestAccAzureRMLoadBalancerProbe_basic --- PASS: TestAccAzureRMLoadBalancerProbe_basic (119.63s) === RUN TestAccAzureRMLoadBalancerProbe_removal --- PASS: TestAccAzureRMLoadBalancerProbe_removal (122.50s) === RUN TestAccAzureRMLoadBalancerProbe_update --- PASS: TestAccAzureRMLoadBalancerProbe_update (129.98s) === RUN TestAccAzureRMLoadBalancerProbe_duplicate --- PASS: TestAccAzureRMLoadBalancerProbe_duplicate (115.22s) === RUN TestAccAzureRMLoadBalancerProbe_updateProtocol --- PASS: TestAccAzureRMLoadBalancerProbe_updateProtocol (127.25s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 614.657s --- .../resource_arm_loadbalancer_probe.go | 1 - .../resource_arm_loadbalancer_probe_test.go | 103 ++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go b/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go index 9057e0cb8..9edfb5df2 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_probe.go @@ -54,7 +54,6 @@ func resourceArmLoadBalancerProbe() *schema.Resource { "request_path": { Type: schema.TypeString, Optional: true, - Computed: true, }, "interval_in_seconds": { diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_probe_test.go b/builtin/providers/azurerm/resource_arm_loadbalancer_probe_test.go index 9a05aec05..1cfb5b23d 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_probe_test.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_probe_test.go @@ -124,6 +124,36 @@ func TestAccAzureRMLoadBalancerProbe_duplicate(t *testing.T) { }) } +func TestAccAzureRMLoadBalancerProbe_updateProtocol(t *testing.T) { + var lb network.LoadBalancer + ri := acctest.RandInt() + probeName := fmt.Sprintf("probe-%d", ri) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMLoadBalancerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLoadBalancerProbe_updateProtocolBefore(ri, probeName), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), + testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), + resource.TestCheckResourceAttr("azurerm_lb_probe.test", "protocol", "Http"), + ), + }, + { + Config: testAccAzureRMLoadBalancerProbe_updateProtocolAfter(ri, probeName), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), + testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), + resource.TestCheckResourceAttr("azurerm_lb_probe.test", "protocol", "Tcp"), + ), + }, + }, + }) +} + func testCheckAzureRMLoadBalancerProbeExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { _, _, exists := findLoadBalancerProbeByName(lb, natRuleName) @@ -293,3 +323,76 @@ resource "azurerm_lb_probe" "test2" { } `, rInt, rInt, rInt, rInt, probeName, probe2Name) } + +func testAccAzureRMLoadBalancerProbe_updateProtocolBefore(rInt int, probeName string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "West US" +} + +resource "azurerm_public_ip" "test" { + name = "test-ip-%d" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurerm_lb" "test" { + name = "arm-test-loadbalancer-%d" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + + frontend_ip_configuration { + name = "one-%d" + public_ip_address_id = "${azurerm_public_ip.test.id}" + } +} + +resource "azurerm_lb_probe" "test" { + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + loadbalancer_id = "${azurerm_lb.test.id}" + name = "%s" + protocol = "Http" + request_path = "/" + port = 80 +} +`, rInt, rInt, rInt, rInt, probeName) +} + +func testAccAzureRMLoadBalancerProbe_updateProtocolAfter(rInt int, probeName string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%d" + location = "West US" +} + +resource "azurerm_public_ip" "test" { + name = "test-ip-%d" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + public_ip_address_allocation = "static" +} + +resource "azurerm_lb" "test" { + name = "arm-test-loadbalancer-%d" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + + frontend_ip_configuration { + name = "one-%d" + public_ip_address_id = "${azurerm_public_ip.test.id}" + } +} + +resource "azurerm_lb_probe" "test" { + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + loadbalancer_id = "${azurerm_lb.test.id}" + name = "%s" + protocol = "Tcp" + port = 80 +} +`, rInt, rInt, rInt, rInt, probeName) +}