Skip to content

Commit

Permalink
Tests for custom DiffSuppressFuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
richeney committed May 2, 2020
1 parent af8760c commit b002ce4
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ func TestAccAzureRMPolicyDefinitionAtMgmtGroup_basic(t *testing.T) {
})
}

func TestAccAzureRMPolicyDefinition_metadata(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_policy_definition", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMPolicyDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAzureRMPolicyDefinition_metadata(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPolicyDefinitionExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMPolicyDefinitionExistsInMgmtGroup(policyName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Policy.DefinitionsClient
Expand Down Expand Up @@ -342,3 +360,51 @@ PARAMETERS
}
`, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testAzureRMPolicyDefinition_metadata(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_policy_definition" "test" {
name = "acctestpol-%d"
policy_type = "Custom"
mode = "All"
display_name = "acctestpol-%d"
policy_rule = <<POLICY_RULE
{
"if": {
"not": {
"field": "location",
"in": "[parameters('allowedLocations')]"
}
},
"then": {
"effect": "audit"
}
}
POLICY_RULE
parameters = <<PARAMETERS
{
"allowedLocations": {
"type": "Array",
"metadata": {
"description": "The list of allowed locations for resources.",
"displayName": "Allowed locations",
"strongType": "location"
}
}
}
PARAMETERS
metadata = <<METADATA
{
"foo": "bar"
}
METADATA
}
`, data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ func TestAccAzureRMPolicySetDefinition_ManagementGroup(t *testing.T) {
})
}

func TestAccAzureRMPolicySetDefinition_metadata(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAzureRMPolicySetDefinition_metadata(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMPolicySetDefinitionExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testAzureRMPolicySetDefinition_builtIn(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -258,6 +276,52 @@ POLICY_DEFINITIONS
`, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testAzureRMPolicySetDefinition_metadata(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_policy_set_definition" "test" {
name = "acctestpolset-%d"
policy_type = "Custom"
display_name = "acctestpolset-%d"
parameters = <<PARAMETERS
{
"allowedLocations": {
"type": "Array",
"metadata": {
"description": "The list of allowed locations for resources.",
"displayName": "Allowed locations",
"strongType": "location"
}
}
}
PARAMETERS
policy_definitions = <<POLICY_DEFINITIONS
[
{
"parameters": {
"listOfAllowedLocations": {
"value": "[parameters('allowedLocations')]"
}
},
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988"
}
]
POLICY_DEFINITIONS
metadata = <<METADATA
{
"foo": "bar"
}
METADATA
}
`, data.RandomInteger, data.RandomInteger)
}

func testCheckAzureRMPolicySetDefinitionExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Policy.SetDefinitionsClient
Expand Down

0 comments on commit b002ce4

Please sign in to comment.