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

Add support for service level auto_pause_notifications_parameters #525

Merged
merged 3 commits into from
Aug 9, 2022
Merged

Add support for service level auto_pause_notifications_parameters #525

merged 3 commits into from
Aug 9, 2022

Conversation

pdecat
Copy link
Contributor

@pdecat pdecat commented Jun 10, 2022

This PR adds support for service level auto_pause_notifications_parameters.

Dependencies were updated with go get -u ./... && go mod vendor && go mod tidy to fetch updates from:

Acceptance test results:

make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_AutoPauseNotificationsParameters'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_AutoPauseNotificationsParameters -timeout 120m
=== RUN   TestAccPagerDutyService_AutoPauseNotificationsParameters
--- PASS: TestAccPagerDutyService_AutoPauseNotificationsParameters (20.23s)
PASS
ok      github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   20.240s

service := fmt.Sprintf("tf-%s", acctest.RandString(5))

resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t); testAccPreCheckPagerDutyAbility(t, "XXX") }, // FIXME: not sure which ability this feature is depending on https://developer.pagerduty.com/api-reference/9def78ed82b74-list-abilities
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure which ability this feature is depending on https://developer.pagerduty.com/api-reference/9def78ed82b74-list-abilities

@pdecat
Copy link
Contributor Author

pdecat commented Jun 10, 2022

Maybe vendored dependencies should be dropped altogether to only rely on go.sum, and avoid having so many files impacted on dependencies updates.

@pdecat pdecat marked this pull request as draft June 10, 2022 12:01
@pdecat
Copy link
Contributor Author

pdecat commented Jun 10, 2022

Marked as draft as I missed some important parts in my former commit, and I'm now facing issues.

@pdecat
Copy link
Contributor Author

pdecat commented Jun 10, 2022

Submitted heimweh/go-pagerduty#94 to fix issues with JSON serialization. Next time, I'll submit both library and provider PR at the same time as I used to do before.

@pdecat pdecat marked this pull request as ready for review June 11, 2022 13:34
@pdecat
Copy link
Contributor Author

pdecat commented Jun 11, 2022

This is now ready for review.

Acceptance test results:

make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_AutoPauseNotificationsParameters'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_AutoPauseNotificationsParameters -timeout 120m
=== RUN   TestAccPagerDutyService_AutoPauseNotificationsParameters
--- PASS: TestAccPagerDutyService_AutoPauseNotificationsParameters (19.31s)
PASS
ok      github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   19.323s

resource.TestCheckResourceAttr(
"pagerduty_service.foo", "auto_pause_notifications_parameters.0.enabled", "false"),
resource.TestCheckResourceAttr(
"pagerduty_service.foo", "auto_pause_notifications_parameters.0.timeout", "0"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We get 0 instead of null because that's the default for TypeInt, see hashicorp/terraform-plugin-sdk#90.

Switching to https://github.com/hashicorp/terraform-plugin-framework in the future may help here.

@pdecat
Copy link
Contributor Author

pdecat commented Jun 20, 2022

Rebased on master, acceptance tests results:

make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_ -timeout 120m
=== RUN   TestAccPagerDutyService_import
--- PASS: TestAccPagerDutyService_import (12.39s)
=== RUN   TestAccPagerDutyService_Basic
--- PASS: TestAccPagerDutyService_Basic (19.22s)
=== RUN   TestAccPagerDutyService_AlertGrouping
--- PASS: TestAccPagerDutyService_AlertGrouping (16.46s)
=== 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)
=== RUN   TestAccPagerDutyService_AutoPauseNotificationsParameters
--- PASS: TestAccPagerDutyService_AutoPauseNotificationsParameters (18.85s)
=== RUN   TestAccPagerDutyService_BasicWithIncidentUrgencyRules
--- PASS: TestAccPagerDutyService_BasicWithIncidentUrgencyRules (21.10s)
=== RUN   TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules
--- PASS: TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules (15.91s)
=== RUN   TestAccPagerDutyService_SupportHoursChange
--- PASS: TestAccPagerDutyService_SupportHoursChange (15.53s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   133.449s
FAIL
make: *** [GNUmakefile:17: testacc] Error 1

The TestAccPagerDutyService_AlertContentGrouping failure is caused by the updated terraform SDK that performs additional checks. I'll submit a fix.

@pdecat
Copy link
Contributor Author

pdecat commented Jul 23, 2022

Rebased on master and pulled in heimweh/go-pagerduty@5d470ed, acceptance tests results:

# make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_ -timeout 120m
=== RUN   TestAccPagerDutyService_import
--- PASS: TestAccPagerDutyService_import (12.67s)
=== RUN   TestAccPagerDutyService_Basic
--- PASS: TestAccPagerDutyService_Basic (19.62s)
=== RUN   TestAccPagerDutyService_AlertGrouping
--- PASS: TestAccPagerDutyService_AlertGrouping (15.56s)
=== 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 (14.85s)
=== RUN   TestAccPagerDutyService_AutoPauseNotificationsParameters
--- PASS: TestAccPagerDutyService_AutoPauseNotificationsParameters (19.02s)
=== RUN   TestAccPagerDutyService_BasicWithIncidentUrgencyRules
--- PASS: TestAccPagerDutyService_BasicWithIncidentUrgencyRules (20.84s)
=== RUN   TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules
--- PASS: TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules (16.19s)
=== RUN   TestAccPagerDutyService_SupportHoursChange
--- PASS: TestAccPagerDutyService_SupportHoursChange (15.84s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   134.603s
FAIL
make: *** [GNUmakefile:17: testacc] Error 1

@pdecat
Copy link
Contributor Author

pdecat commented Jul 23, 2022

Hi @imjaroiswebdev, the alert grouping acceptance test is still triggering errors with the new terraform SDK:

# 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: 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 (14.83s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   14.839s
FAIL
make: *** [GNUmakefile:17: testacc] Error 1

Changing this to:

git diff
diff --git a/pagerduty/resource_pagerduty_service_test.go b/pagerduty/resource_pagerduty_service_test.go
index a01fa7cd..f17d8101 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.TestCheckNoResourceAttr(
                                                "pagerduty_service.foo", "alert_grouping_parameters.0.type"),
                                        resource.TestCheckResourceAttr(

resolves the issue:

# 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
--- PASS: TestAccPagerDutyService_AlertContentGrouping (15.62s)
PASS
ok      github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   15.635s

See #525 (comment)

@imjaroiswebdev
Copy link
Contributor

Hi @pdecat thank you for this awesome addition to support Auto Pause Notifications Parameters, I've been reviewing it and looks great, but if you don't mind We would prefer to let the module vendoring and tidy for another PR like #532 which you already opened and focus this one in adding this improvement to the Provider. So thinking on that I have rebased and reapplied your commit in a new branch on my fork for you to see how We can do add the change without updating vendors and tidy and continue from there. Please take a look at it in the following branches comparison... https://github.com/pdecat/terraform-provider-pagerduty/compare/auto_pause_notifications_parameters...imjaroiswebdev:terraform-provider-pagerduty:auto_pause_notifications_parameters

The tests you added are also looking very good...
Screen Shot 2022-07-28 at 14 37 04

@pdecat
Copy link
Contributor Author

pdecat commented Aug 2, 2022

Hi @imjaroiswebdev, updating at least part of the dependencies is required because of heimweh/go-pagerduty@2e1f764

If you don't, go mod vendor complains:

# go get github.com/heimweh/go-pagerduty@5d470ed
go: upgraded github.com/heimweh/go-pagerduty v0.0.0-20220527195341-4e587aa9b58e => v0.0.0-20220722230120-5d470ed7c5fc

# go mod vendor
go: github.com/heimweh/go-pagerduty@v0.0.0-20220722230120-5d470ed7c5fc requires
        go.mongodb.org/mongo-driver@v1.9.1: missing go.sum entry; to add it:
        go mod download go.mongodb.org/mongo-driver
go: github.com/heimweh/go-pagerduty@v0.0.0-20220722230120-5d470ed7c5fc requires
        go.mongodb.org/mongo-driver@v1.9.1: missing go.sum entry; to add it:
        go mod download go.mongodb.org/mongo-driver

@pdecat
Copy link
Contributor Author

pdecat commented Aug 6, 2022

Hi @imjaroiswebdev, I've now rebased on master following your go modules updates, and dropped my corresponding commits from this branch.

Acceptance tests results:

# make testacc TEST=./pagerduty/ TESTARGS='-run=TestAccPagerDutyService_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./pagerduty/ -v -run=TestAccPagerDutyService_ -timeout 120m
=== RUN   TestAccPagerDutyService_import
--- PASS: TestAccPagerDutyService_import (13.13s)
=== RUN   TestAccPagerDutyService_Basic
--- PASS: TestAccPagerDutyService_Basic (19.95s)
=== RUN   TestAccPagerDutyService_AlertGrouping
--- PASS: TestAccPagerDutyService_AlertGrouping (16.48s)
=== RUN   TestAccPagerDutyService_AlertContentGrouping
--- PASS: TestAccPagerDutyService_AlertContentGrouping (16.27s)
=== RUN   TestAccPagerDutyService_AutoPauseNotificationsParameters
--- PASS: TestAccPagerDutyService_AutoPauseNotificationsParameters (19.37s)
=== RUN   TestAccPagerDutyService_BasicWithIncidentUrgencyRules
--- PASS: TestAccPagerDutyService_BasicWithIncidentUrgencyRules (21.66s)
=== RUN   TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules
--- PASS: TestAccPagerDutyService_FromBasicToCustomIncidentUrgencyRules (15.50s)
=== RUN   TestAccPagerDutyService_SupportHoursChange
--- PASS: TestAccPagerDutyService_SupportHoursChange (16.09s)
=== RUN   TestAccPagerDutyService_ResponsePlay
--- PASS: TestAccPagerDutyService_ResponsePlay (12.53s)
PASS
ok      github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   150.997s

Note: I had to run make fmt to fix an issue with pagerduty/resource_pagerduty_slack_connection.go:

# make test
==> Checking that code complies with gofmt requirements...
gofmt needs running on the following files:
./pagerduty/resource_pagerduty_slack_connection.go
You can use the command: `make fmt` to reformat code.
make: *** [GNUmakefile:32: fmtcheck] Error 1

# make fmt
gofmt -w $(find . -name '*.go' |grep -v vendor)

# make test
==> Checking that code complies with gofmt requirements...
go test -i $(go list ./... |grep -v 'vendor') || exit 1
go: -i flag is deprecated
echo $(go list ./... |grep -v 'vendor') | \
        xargs -t -n4 go test  -timeout=30s -parallel=4
go test '-timeout=30s' '-parallel=4' github.com/terraform-providers/terraform-provider-pagerduty github.com/terraform-providers/terraform-provider-pagerduty/pagerduty
?       github.com/terraform-providers/terraform-provider-pagerduty     [no test files]
ok      github.com/terraform-providers/terraform-provider-pagerduty/pagerduty   0.019s

Copy link
Contributor

@imjaroiswebdev imjaroiswebdev left a comment

Choose a reason for hiding this comment

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

This a great addition @pdecat thank you so much for your contribution🎉💪🏽, since you have done all the heavy lifting with this excellent PR and all the current and new tests are passing, in the end I only added the final and superficial touches for be able to merged adding a link to the docs which mention the plan restrictions for the PagerDuty account in the documentation you added, on top of that, I removed your inquire about the ability to do the precheck on the test and added the generic test precheck We have, since this configuration can be done by, but the limitation mentioned is related to its use, because of that there is no an explicit ability listed.

@imjaroiswebdev imjaroiswebdev merged commit bb12caa into PagerDuty:master Aug 9, 2022
@pdecat pdecat deleted the auto_pause_notifications_parameters branch August 9, 2022 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants