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

Trying to fix Issue #18971 #18999

Merged

Conversation

sinc59
Copy link
Contributor

@sinc59 sinc59 commented Oct 26, 2022

A PR to trying to fix the issue #18971.

Add the name argument and the ability to add one or more ressources with non-hardcoded contact name.
The API REST accept one or more contacts and the name "default1" is not anymore required see documentation.

Testing on an azure account:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_security_center_contact.example will be created
  + resource "azurerm_security_center_contact" "example" {
      + alert_notifications = true
      + alerts_to_admins    = true
      + email               = "default@test.fr"
      + id                  = (known after apply)
      + name                = "me"
    }

  # azurerm_security_center_contact.example2 will be created
  + resource "azurerm_security_center_contact" "example2" {
      + alert_notifications = true
      + alerts_to_admins    = true
      + email               = "test2@test.fr"
      + id                  = (known after apply)
      + name                = "test2"
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Result (using the azure cli to list accounts):

]$ az security contact list 
AlertNotifications    AlertsToAdmins    Email                    Location     Name    Phone
--------------------  ----------------  -----------------------  -----------  ------  -------
On                    On                default@test.fr          West Europe  me
On                    On                test2@test.fr            West Europe  test2

Best regards,
Sébastien Caloone

Sébastien Caloone added 3 commits October 26, 2022 13:45
Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @sinc59, unfortunately it looks like we have a test failure:

------- Stdout: -------
=== RUN   TestAccSecurityCenterContact
=== RUN   TestAccSecurityCenterContact/contact
=== RUN   TestAccSecurityCenterContact/contact/update
testcase.go:117: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) {
}
(map[string]string) (len=1) {
(string) (len=4) "name": (string) (len=12) "test-account"
}
=== RUN   TestAccSecurityCenterContact/contact/requiresImport
testcase.go:117: Step 2/2, expected an error but got none
=== RUN   TestAccSecurityCenterContact/contact/phoneOptional
testcase.go:117: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) {
}
(map[string]string) (len=1) {
(string) (len=4) "name": (string) (len=12) "test-account"
}
=== RUN   TestAccSecurityCenterContact/contact/basic
testcase.go:117: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.
(map[string]string) {
}
(map[string]string) (len=1) {
(string) (len=4) "name": (string) (len=12) "test-account"
}
--- FAIL: TestAccSecurityCenterContact (497.63s)
--- FAIL: TestAccSecurityCenterContact/contact (497.63s)
--- FAIL: TestAccSecurityCenterContact/contact/update (165.09s)
--- FAIL: TestAccSecurityCenterContact/contact/requiresImport (158.78s)
--- FAIL: TestAccSecurityCenterContact/contact/phoneOptional (86.93s)
--- FAIL: TestAccSecurityCenterContact/contact/basic (86.83s)
FAIL

@sinc59
Copy link
Contributor Author

sinc59 commented Oct 27, 2022

HI @stephybun
I'va pushed a new commit to fix the tests failed but, i get a new error on the acctests command:

$ make acctests SERVICE='securitycenter' TESTARGS='-run=TestAccSecurityCenterContact' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/securitycenter -run=TestAccSecurityCenterContact -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccSecurityCenterContact
=== RUN   TestAccSecurityCenterContact/contact
=== RUN   TestAccSecurityCenterContact/contact/basic
=== RUN   TestAccSecurityCenterContact/contact/update
=== RUN   TestAccSecurityCenterContact/contact/requiresImport
    testcase.go:117: Step 2/2, expected an error but got none
=== RUN   TestAccSecurityCenterContact/contact/phoneOptional
--- FAIL: TestAccSecurityCenterContact (702.89s)
    --- FAIL: TestAccSecurityCenterContact/contact (702.89s)
        --- PASS: TestAccSecurityCenterContact/contact/basic (106.19s)
        --- PASS: TestAccSecurityCenterContact/contact/update (324.70s)
        --- FAIL: TestAccSecurityCenterContact/contact/requiresImport (159.76s)
        --- PASS: TestAccSecurityCenterContact/contact/phoneOptional (112.23s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-azurerm/internal/services/securitycenter        702.926s
FAIL
make: *** [GNUmakefile:100 : acctests] Erreur 1

I don't know why i get this error, after a manual import of the ressource, i get the contact name in the state ressource.
Did you have an idea ?
(I'm beginner on terraform and the go language)

Sébastien

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sinc59 - looks like we have a test failure (by not failing)

------- Stdout: -------
=== RUN   TestAccSecurityCenterContact
=== RUN   TestAccSecurityCenterContact/contact
=== RUN   TestAccSecurityCenterContact/contact/basic
=== RUN   TestAccSecurityCenterContact/contact/update
=== RUN   TestAccSecurityCenterContact/contact/requiresImport
    testcase.go:117: Step 2/2, expected an error but got none
=== RUN   TestAccSecurityCenterContact/contact/phoneOptional
--- FAIL: TestAccSecurityCenterContact (477.09s)
    --- FAIL: TestAccSecurityCenterContact/contact (477.09s)
        --- PASS: TestAccSecurityCenterContact/contact/basic (94.99s)
        --- PASS: TestAccSecurityCenterContact/contact/update (150.93s)
        --- FAIL: TestAccSecurityCenterContact/contact/requiresImport (146.30s)
        --- PASS: TestAccSecurityCenterContact/contact/phoneOptional (84.87s)
FAIL

@@ -42,6 +36,13 @@ func resourceSecurityCenterContact() *pluginsdk.Resource {
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are adding this property we'll need to update the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, i have not yet run the scaffold website command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docs still need updating & we'll need to make this Optional/Defaulted in 3.x / make this Required in 4.0 since otherwise this is a breaking change

@stephybun
Copy link
Member

stephybun commented Oct 28, 2022

@sinc59 the test that's currently failing is expecting an error from this line

return tf.ImportAsExistsError("azurerm_security_center_contact", id.ID())

So something is amiss within that block.

Also if my understanding is correct it's possible to create multiple contacts with custom names now? This means we can split the tests out instead of grouping them which will make it possible to run them individually and might help with debugging the issue.

@sinc59
Copy link
Contributor Author

sinc59 commented Oct 28, 2022

Yes @stephybun we can set multiple contacts with custom names.
I don't understand why i have an error on the tf.ImportAsExistsError because the import of the resource works (within the terraform import command).

But it's certainly a misapprehension from my part.

Sébastien

@stephybun
Copy link
Member

Just to clarify, the requiresImport test validates that if the resource already exists then tf.ImportAsExistsError will throw an error, so the test is expecting an error but isn't receiving one.

@stephybun stephybun force-pushed the issue_18971_security_center_contact_resource branch from 8e221e0 to fbb9951 Compare November 3, 2022 07:56
@stephybun
Copy link
Member

Tests are passing now
image

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment inline but otherwise 👍

@@ -42,6 +36,13 @@ func resourceSecurityCenterContact() *pluginsdk.Resource {
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the docs still need updating & we'll need to make this Optional/Defaulted in 3.x / make this Required in 4.0 since otherwise this is a breaking change

@stephybun stephybun merged commit 36f6aaa into hashicorp:main Nov 3, 2022
@github-actions github-actions bot added this to the v3.30.0 milestone Nov 3, 2022
stephybun added a commit that referenced this pull request Nov 3, 2022
@github-actions
Copy link

github-actions bot commented Nov 4, 2022

This functionality has been released in v3.30.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Dec 5, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants