From 2db96b36ac3e7d3f583d88d717a3c33568b558be Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 21 Nov 2019 14:16:46 -0800 Subject: [PATCH 1/3] Replicate crash --- azurerm/resource_arm_container_group_test.go | 69 +++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index d271f2ab3a82..1d99847a67a4 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -281,7 +281,7 @@ func TestAccAzureRMContainerGroup_linuxBasicUpdate(t *testing.T) { ri := tf.AccRandTimeInt() config := testAccAzureRMContainerGroup_linuxBasic(ri, testLocation()) - updatedConfig := testAccAzureRMContainerGroup_linuxBasicUpdated(ri, testLocation()) + updatedConfig := testaccazurermcontainergroupLinuxbasicupdated(ri, testLocation()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -515,6 +515,31 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { }) } +func TestAccAzureRMContainerGroup_emptyCommand(t *testing.T) { + resourceName := "azurerm_container_group.test" + ri := tf.AccRandTimeInt() + config := testAccAzureRMContainerGroup_emptyCommand(ri, testLocation()) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMContainerGroupDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMContainerGroupExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccAzureRMContainerGroup_SystemAssignedIdentity(ri int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -823,7 +848,7 @@ resource "azurerm_container_group" "test" { `, ri, location, ri, ri) } -func testAccAzureRMContainerGroup_linuxBasicUpdated(ri int, location string) string { +func testaccazurermcontainergroupLinuxbasicupdated(ri int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1209,6 +1234,46 @@ resource "azurerm_container_group" "test" { `, ri, location, ri, ri, ri, ri, ri) } +func testAccAzureRMContainerGroup_emptyCommand(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_container_group" "test" { + name = "acctestcontainergroup-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + ip_address_type = "public" + os_type = "windows" + + container { + name = "windowsservercore" + image = "microsoft/iis:windowsservercore" + cpu = "2.0" + memory = "3.5" + + ports { + port = 80 + protocol = "TCP" + } + + ports { + port = 443 + protocol = "TCP" + } + + commands = ["", "ls"] + } + + tags = { + environment = "Testing" + } +} +`, ri, location, ri) +} + func testCheckAzureRMContainerGroupExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure we have enough information in state to look up in API From 95c9cb298d78bf18ab6e275351dafbec1b539628 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 21 Nov 2019 14:38:21 -0800 Subject: [PATCH 2/3] Prevent passing empty strings to commands --- azurerm/resource_arm_container_group.go | 5 +- azurerm/resource_arm_container_group_test.go | 65 -------------------- 2 files changed, 4 insertions(+), 66 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 01fa5e60c450..80a538da3f4c 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -323,7 +323,10 @@ func resourceArmContainerGroup() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validate.NoEmptyStrings, + }, }, "volume": { diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 1d99847a67a4..0b2f9eaa05c5 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -515,31 +515,6 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { }) } -func TestAccAzureRMContainerGroup_emptyCommand(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMContainerGroup_emptyCommand(ri, testLocation()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMContainerGroupDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - func testAccAzureRMContainerGroup_SystemAssignedIdentity(ri int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -1234,46 +1209,6 @@ resource "azurerm_container_group" "test" { `, ri, location, ri, ri, ri, ri, ri) } -func testAccAzureRMContainerGroup_emptyCommand(ri int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_container_group" "test" { - name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - ip_address_type = "public" - os_type = "windows" - - container { - name = "windowsservercore" - image = "microsoft/iis:windowsservercore" - cpu = "2.0" - memory = "3.5" - - ports { - port = 80 - protocol = "TCP" - } - - ports { - port = 443 - protocol = "TCP" - } - - commands = ["", "ls"] - } - - tags = { - environment = "Testing" - } -} -`, ri, location, ri) -} - func testCheckAzureRMContainerGroupExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure we have enough information in state to look up in API From 8d5d12e75915be80f2cbd18e783eb7ec2668be84 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 21 Nov 2019 14:40:16 -0800 Subject: [PATCH 3/3] revert test name change --- azurerm/resource_arm_container_group_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 0b2f9eaa05c5..d271f2ab3a82 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -281,7 +281,7 @@ func TestAccAzureRMContainerGroup_linuxBasicUpdate(t *testing.T) { ri := tf.AccRandTimeInt() config := testAccAzureRMContainerGroup_linuxBasic(ri, testLocation()) - updatedConfig := testaccazurermcontainergroupLinuxbasicupdated(ri, testLocation()) + updatedConfig := testAccAzureRMContainerGroup_linuxBasicUpdated(ri, testLocation()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -823,7 +823,7 @@ resource "azurerm_container_group" "test" { `, ri, location, ri, ri) } -func testaccazurermcontainergroupLinuxbasicupdated(ri int, location string) string { +func testAccAzureRMContainerGroup_linuxBasicUpdated(ri int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d"