diff --git a/azurerm/resource_arm_security_center_contact.go b/azurerm/resource_arm_security_center_contact.go index 14706b7f2a87..ec8c3bbbae95 100644 --- a/azurerm/resource_arm_security_center_contact.go +++ b/azurerm/resource_arm_security_center_contact.go @@ -38,7 +38,7 @@ func resourceArmSecurityCenterContact() *schema.Resource { "phone": { Type: schema.TypeString, - Required: true, + Optional: true, ValidateFunc: validate.NoEmptyStrings, }, diff --git a/azurerm/resource_arm_security_center_contact_test.go b/azurerm/resource_arm_security_center_contact_test.go index 64596917d6bd..893a9e086a9c 100644 --- a/azurerm/resource_arm_security_center_contact_test.go +++ b/azurerm/resource_arm_security_center_contact_test.go @@ -16,6 +16,7 @@ func TestAccAzureRMSecurityCenter_contact(t *testing.T) { "basic": testAccAzureRMSecurityCenterContact_basic, "update": testAccAzureRMSecurityCenterContact_update, "requiresImport": testAccAzureRMSecurityCenterContact_requiresImport, + "phoneOptional": testAccAzureRMSecurityCenterContact_phoneOptional, }, } @@ -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("basic@example.com", true, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSecurityCenterContactExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "email", "basic@example.com"), + 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 @@ -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 diff --git a/website/docs/r/security_center_contact.markdown b/website/docs/r/security_center_contact.markdown index 5de33d8da632..26b129967147 100644 --- a/website/docs/r/security_center_contact.markdown +++ b/website/docs/r/security_center_contact.markdown @@ -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.