-
Notifications
You must be signed in to change notification settings - Fork 212
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
Address: Unable to switch off alert grouping on a service #527
Address: Unable to switch off alert grouping on a service #527
Conversation
0714106
to
6b59244
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! That util function will be useful! 👍 🌮 🎉
"pagerduty_service.foo", "incident_urgency_rule.0.type", "constant"), | ||
), | ||
ExpectNonEmptyPlan: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should not be used in this test. It prevents detecting changes in the API response from what is expected.
resource.TestCheckResourceAttr( | ||
"pagerduty_service.foo", "alert_grouping", "rules"), | ||
resource.TestCheckNoResourceAttr( | ||
"pagerduty_service.foo", "alert_grouping_parameters.0.config"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this check does not work as expected. Newer versions of the terraform SDK reject this:
=== RUN TestAccPagerDutyService_AlertContentGrouping
resource_pagerduty_service_test.go:206: Step 2/2 error: Check failed: Check 8/12 error: pagerduty_service.foo: list or set attribute 'alert_grouping_parameters.0.config' must be checked by element count key (alert_grouping_parameters.0.config.#) or element value keys (e.g. alert_grouping_parameters.0.config.0). Set element value checks should use TestCheckTypeSet functions instead.
--- FAIL: TestAccPagerDutyService_AlertContentGrouping (13.98s)
See #525 (comment)
Changing it to the recommended way reveals an issue:
diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go
index 7cda1e3d..dceef04a 100644
--- a/pagerduty/resource_pagerduty_service_test.go
+++ b/pagerduty/resource_pagerduty_service_test.go
@@ -254,8 +254,8 @@ func TestAccPagerDutyService_AlertContentGrouping(t *testing.T) {
"pagerduty_service.foo", "alert_creation", "create_alerts_and_incidents"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_grouping", "rules"),
- resource.TestCheckNoResourceAttr(
- "pagerduty_service.foo", "alert_grouping_parameters.0.config"),
+ resource.TestCheckResourceAttr(
+ "pagerduty_service.foo", "alert_grouping_parameters.0.config.#", "0"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "alert_grouping_parameters.0.type", ""),
resource.TestCheckResourceAttr(
=>
make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_AlertContentGrouping'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_AlertContentGrouping -timeout 120m
=== RUN TestAccPagerDutyService_AlertContentGrouping
resource_pagerduty_service_test.go:206: Step 2/2 error: Check failed: Check 8/12 error: pagerduty_service.foo: Attribute 'alert_grouping_parameters.0.config.#' expected "0", got "1"
--- FAIL: TestAccPagerDutyService_AlertContentGrouping (14.80s)
FAIL
FAIL github.com/terraform-providers/terraform-provider-pagerduty/pagerduty 14.813s
FAIL
make: *** [GNUmakefile:17: testacc] Error 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted #532 to replicate the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new terraform SDK check comes from hashicorp/terraform-plugin-sdk#920 which was released in https://github.com/hashicorp/terraform-plugin-sdk/blob/v2.13.0/CHANGELOG.md#2130-march-31-2022
Addressing #520
With this fix the Provider will not crash when trying to switch off alert grouping on a service, and also it will accept an interface more alike with the API and GUI.
Tests result: