From 94473beadff61d86aec0a49f8bffdbe72146aa62 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 13 Oct 2018 20:25:03 -0700 Subject: [PATCH] combined security center pricing and workspace tests to prevent conflicts --- .../resource_arm_security_center_contact.go | 3 +- ...curity_center_subscription_pricing_test.go | 2 +- azurerm/resource_arm_security_center_test.go | 31 +++++++++++++++++ .../resource_arm_security_center_workspace.go | 6 ++-- ...urce_arm_security_center_workspace_test.go | 33 ++++++++++++++----- 5 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 azurerm/resource_arm_security_center_test.go diff --git a/azurerm/resource_arm_security_center_contact.go b/azurerm/resource_arm_security_center_contact.go index 6d1d24529d015..027b9f37d6913 100644 --- a/azurerm/resource_arm_security_center_contact.go +++ b/azurerm/resource_arm_security_center_contact.go @@ -2,11 +2,12 @@ package azurerm import ( "fmt" + "log" + "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/2017-08-01-preview/security" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "log" ) //seems you can only set one contact: diff --git a/azurerm/resource_arm_security_center_subscription_pricing_test.go b/azurerm/resource_arm_security_center_subscription_pricing_test.go index cc3504667fd39..6629cdcafa440 100644 --- a/azurerm/resource_arm_security_center_subscription_pricing_test.go +++ b/azurerm/resource_arm_security_center_subscription_pricing_test.go @@ -9,7 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMSecurityCenterSubscriptionPricing_update(t *testing.T) { +func testAccAzureRMSecurityCenterSubscriptionPricing_update(t *testing.T) { resourceName := "azurerm_security_center_subscription_pricing.test" resource.Test(t, resource.TestCase{ diff --git a/azurerm/resource_arm_security_center_test.go b/azurerm/resource_arm_security_center_test.go new file mode 100644 index 0000000000000..4a3ed04a4b073 --- /dev/null +++ b/azurerm/resource_arm_security_center_test.go @@ -0,0 +1,31 @@ +package azurerm + +import ( + "testing" +) + +func TestAccAzureRMSecurityCenter_pricingAndWorkspace(t *testing.T) { + // NOTE: this is a combined test rather than separate split out tests + // due to the workspace tests depending on the current pricing tier + testCases := map[string]map[string]func(t *testing.T){ + "pricing": { + "update": testAccAzureRMSecurityCenterSubscriptionPricing_update, + }, + "workspace": { + "basic": testAccAzureRMSecurityCenterWorkspace_basic, + "update": testAccAzureRMSecurityCenterWorkspace_update, + }, + } + + for group, m := range testCases { + m := m + t.Run(group, func(t *testing.T) { + for name, tc := range m { + tc := tc + t.Run(name, func(t *testing.T) { + tc(t) + }) + } + }) + } +} diff --git a/azurerm/resource_arm_security_center_workspace.go b/azurerm/resource_arm_security_center_workspace.go index 2e605c1b72d41..670deda4657d7 100644 --- a/azurerm/resource_arm_security_center_workspace.go +++ b/azurerm/resource_arm_security_center_workspace.go @@ -2,14 +2,15 @@ package azurerm import ( "fmt" + "log" + "time" + "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/2017-08-01-preview/security" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "log" - "time" ) //only valid name is default @@ -84,6 +85,7 @@ func resourceArmSecurityCenterWorkspaceCreateUpdate(d *schema.ResourceData, meta } } + //api returns "" for workspace id after an create/update and eventually the new value stateConf := &resource.StateChangeConf{ Pending: []string{"Waiting"}, Target: []string{"Populated"}, diff --git a/azurerm/resource_arm_security_center_workspace_test.go b/azurerm/resource_arm_security_center_workspace_test.go index 9498c1efeb262..01497ab5f9d32 100644 --- a/azurerm/resource_arm_security_center_workspace_test.go +++ b/azurerm/resource_arm_security_center_workspace_test.go @@ -2,16 +2,16 @@ package azurerm import ( "fmt" - "github.com/hashicorp/terraform/helper/acctest" "os" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMSecurityCenterWorkspace_basic(t *testing.T) { +func testAccAzureRMSecurityCenterWorkspace_basic(t *testing.T) { resourceName := "azurerm_security_center_workspace.test" ri := acctest.RandInt() @@ -23,7 +23,7 @@ func TestAccAzureRMSecurityCenterWorkspace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSecurityCenterWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSecurityCenterWorkspace_basic(ri, testLocation(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(ri, testLocation(), scope), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "scope", scope), @@ -34,11 +34,15 @@ func TestAccAzureRMSecurityCenterWorkspace_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + //reset pricing to free + Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Free"), + }, }, }) } -func TestAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { +func testAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { resourceName := "azurerm_security_center_workspace.test" ri := acctest.RandInt() @@ -49,14 +53,14 @@ func TestAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccAzureRMSecurityCenterWorkspace_basic(ri, testLocation(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(ri, testLocation(), scope), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "scope", scope), ), }, { - Config: testAccAzureRMSecurityCenterWorkspace_differentWorkspace(ri, testLocation(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_differentWorkspaceCfg(ri, testLocation(), scope), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), resource.TestCheckResourceAttr(resourceName, "scope", scope), @@ -67,6 +71,10 @@ func TestAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + //reset pricing to free + Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Free"), + }, }, }) } @@ -120,8 +128,13 @@ func testCheckAzureRMSecurityCenterWorkspaceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMSecurityCenterWorkspace_basic(rInt int, location, scope string) string { +func testAccAzureRMSecurityCenterWorkspace_basicCfg(rInt int, location, scope string) string { return fmt.Sprintf(` + +resource "azurerm_security_center_subscription_pricing" "test" { + tier = "Standard" +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -141,8 +154,12 @@ resource "azurerm_security_center_workspace" "test" { `, rInt, location, scope) } -func testAccAzureRMSecurityCenterWorkspace_differentWorkspace(rInt int, location, scope string) string { +func testAccAzureRMSecurityCenterWorkspace_differentWorkspaceCfg(rInt int, location, scope string) string { return fmt.Sprintf(` +resource "azurerm_security_center_subscription_pricing" "test" { + tier = "Standard" +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s"