Skip to content

Commit

Permalink
combined security center pricing and workspace tests to prevent confl…
Browse files Browse the repository at this point in the history
…icts
  • Loading branch information
katbyte committed Oct 14, 2018
1 parent e592b32 commit 94473be
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 12 deletions.
3 changes: 2 additions & 1 deletion azurerm/resource_arm_security_center_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
31 changes: 31 additions & 0 deletions azurerm/resource_arm_security_center_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
})
}
}
6 changes: 4 additions & 2 deletions azurerm/resource_arm_security_center_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"},
Expand Down
33 changes: 25 additions & 8 deletions azurerm/resource_arm_security_center_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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),
Expand All @@ -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()

Expand All @@ -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),
Expand All @@ -67,6 +71,10 @@ func TestAccAzureRMSecurityCenterWorkspace_update(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
//reset pricing to free
Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Free"),
},
},
})
}
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 94473be

Please sign in to comment.