Skip to content

Commit

Permalink
[azurerm_security_center_contact] Security center contacts opti… (#3761)
Browse files Browse the repository at this point in the history
* Make phone optional in azurerm_security_center_contact

* Edit documentation that phone is now optional in security center contact
  • Loading branch information
benjamin37 authored and katbyte committed Jul 1, 2019
1 parent b7a1058 commit 2ef8c65
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion azurerm/resource_arm_security_center_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func resourceArmSecurityCenterContact() *schema.Resource {

"phone": {
Type: schema.TypeString,
Required: true,
Optional: true,
ValidateFunc: validate.NoEmptyStrings,
},

Expand Down
39 changes: 39 additions & 0 deletions azurerm/resource_arm_security_center_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestAccAzureRMSecurityCenter_contact(t *testing.T) {
"basic": testAccAzureRMSecurityCenterContact_basic,
"update": testAccAzureRMSecurityCenterContact_update,
"requiresImport": testAccAzureRMSecurityCenterContact_requiresImport,
"phoneOptional": testAccAzureRMSecurityCenterContact_phoneOptional,
},
}

Expand Down Expand Up @@ -127,6 +128,33 @@ func testAccAzureRMSecurityCenterContact_update(t *testing.T) {
})
}

func testAccAzureRMSecurityCenterContact_phoneOptional(t *testing.T) {
resourceName := "azurerm_security_center_contact.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSecurityCenterContactDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMSecurityCenterContact_templateWithoutPhone("[email protected]", true, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSecurityCenterContactExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "email", "[email protected]"),
resource.TestCheckResourceAttr(resourceName, "phone", ""),
resource.TestCheckResourceAttr(resourceName, "alert_notifications", "true"),
resource.TestCheckResourceAttr(resourceName, "alerts_to_admins", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMSecurityCenterContactExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).securityCenter.ContactsClient
Expand Down Expand Up @@ -183,6 +211,17 @@ resource "azurerm_security_center_contact" "test" {
`, email, phone, notifications, adminAlerts)
}

func testAccAzureRMSecurityCenterContact_templateWithoutPhone(email string, notifications, adminAlerts bool) string {
return fmt.Sprintf(`
resource "azurerm_security_center_contact" "test" {
email = "%s"
alert_notifications = %t
alerts_to_admins = %t
}
`, email, notifications, adminAlerts)
}

func testAccAzureRMSecurityCenterContact_requiresImportCfg(email, phone string, notifications, adminAlerts bool) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/security_center_contact.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resource "azurerm_security_center_contact" "example" {
The following arguments are supported:

* `email` - (Required) The email of the Security Center Contact.
* `phone` - (Required) The phone number of the Security Center Contact.
* `phone` - (Optional) The phone number of the Security Center Contact.
* `alert_notifications` - (Required) Whether to send security alerts notifications to the security contact.
* `alerts_to_admins` - (Required) Whether to send security alerts notifications to subscription admins.

Expand Down

0 comments on commit 2ef8c65

Please sign in to comment.