Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azurerm_security_center_contact] Security center contacts optional phone #3761

Merged
merged 2 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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