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

Modify resource_pagerduty_schedule.go to send "end": null when a layer's end is removed #460

Merged
merged 7 commits into from
Feb 15, 2022

Conversation

shotarok
Copy link
Contributor

@shotarok shotarok commented Feb 9, 2022

What

Why

@shotarok shotarok changed the title Unset end when deleted Modify resource_pagerduty_schedule.go to send "end": null when a layer's end is removed Feb 9, 2022
@shotarok
Copy link
Contributor Author

shotarok commented Feb 9, 2022

[MEMO] I tested the modified code locally, and I confirmed it worked expectedly. I attached a part of the debug logs.

debug logs when I executed terraform apply locally
$ terraform apply -auto-approve
...
-----------------------------------------------------: timestamp=2022-02-09T08:46:37.346-0800
2022-02-09T08:46:37.349-0800 [INFO]  provider.terraform-provider-pagerduty_v2.2.2: 2022/02/09 08:46:37 [INFO] PagerDuty client configured: timestamp=2022-02-09T08:46:37.347-0800
2022-02-09T08:46:37.349-0800 [INFO]  provider.terraform-provider-pagerduty_v2.2.2: 2022/02/09 08:46:37 [INFO] Updating PagerDuty schedule: P83EUIV: timestamp=2022-02-09T08:46:37.348-0800
2022-02-09T08:46:37.349-0800 [INFO]  provider.terraform-provider-pagerduty_v2.2.2: 2022/02/09 08:46:37 [DEBUG] Waiting for state to become: [success]: timestamp=2022-02-09T08:46:37.348-0800
2022-02-09T08:46:37.349-0800 [INFO]  provider.terraform-provider-pagerduty_v2.2.2: 2022/02/09 08:46:37 [DEBUG] PagerDuty - Preparing PUT request to /schedules/P83EUIV with body: {"schedule":{"description":"Managed by Terraform","name":"test-shotarok-schedule","schedule_layers":[{"end":null,"id":"PGQWKMX","name":"Layer 1","rotation_turn_length_seconds":86400,"rotation_virtual_start":"2017-11-13 03:00:00 +0000 UTC","start":"2022-02-10T01:04:35+09:00","users":[{"user":{"id":"PVPRM30","type":"user"}}]}],"time_zone":"Asia/Tokyo","teams":[{"id":"P15AA14","type":"team_reference"}]}}: timestamp=2022-02-09T08:46:37.348-0800
2022-02-09T08:46:37.349-0800 [INFO]  provider.terraform-provider-pagerduty_v2.2.2: 2022/02/09 08:46:37 [DEBUG] PagerDuty API Request Details:
---[ REQUEST ]---------------------------------------
PUT /schedules/P83EUIV HTTP/1.1
Host: api.pagerduty.com
User-Agent: heimweh/go-pagerduty(terraform)
Content-Length: 405
Accept: application/vnd.pagerduty+json;version=2
Authorization: Token token=u+xzybunssDczzoaEWmQ
Content-Type: application/json
Accept-Encoding: gzip

{
 "schedule": {
  "description": "Managed by Terraform",
  "name": "test-shotarok-schedule",
  "schedule_layers": [
   {
    "end": null,
    "id": "PGQWKMX",
    "name": "Layer 1",
    "rotation_turn_length_seconds": 86400,
    "rotation_virtual_start": "2017-11-13 03:00:00 +0000 UTC",
    "start": "2022-02-10T01:04:35+09:00",
    "users": [
     {
      "user": {
       "id": "PVPRM30",
       "type": "user"
      }
     }
    ]
   }
  ],
  "time_zone": "Asia/Tokyo",
  "teams": [
   {
    "id": "P15AA14",
    "type": "team_reference"
   }
  ]
 }
}

-----------------------------------------------------: timestamp=2022-02-09T08:46:37.349-0800
2022-02-09T08:46:37.886-0800 [INFO]  provider.terraform-provider-pagerduty_v2.2.2: 2022/02/09 08:46:37 [DEBUG] PagerDuty API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Access-Control-Allow-Headers: Authorization, Content-Type, AuthorizationOauth, X-EARLY-ACCESS
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: 
Access-Control-Max-Age: 1728000
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Wed, 09 Feb 2022 16:46:37 GMT
Etag: W/"0563a73d7e51741ef220a5bba37daff5"
Feature-Policy: accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Request-Id: 7de6df80b6ecf43d1beca59d5dac378a
X-Xss-Protection: 1; mode=block

{
 "schedule": {
  "id": "P83EUIV",
  "type": "schedule",
  "summary": "test-shotarok-schedule",
  "self": "https://api.pagerduty.com/schedules/P83EUIV",
  "html_url": "https://mercari.pagerduty.com/schedules/P83EUIV",
  "name": "test-shotarok-schedule",
  "time_zone": "Asia/Tokyo",
  "description": "Managed by Terraform",
  "web_cal_url": "webcal://mercari.pagerduty.com/private/8dbd54c3531491edf0c5a11e71564d60547db673046abc081d13a8974153771e/feed/P83EUIV",
  "http_cal_url": "https://mercari.pagerduty.com/private/8dbd54c3531491edf0c5a11e71564d60547db673046abc081d13a8974153771e/feed/P83EUIV",
  "personal_web_cal_url": "webcal://mercari.pagerduty.com/private/8dbd54c3531491edf0c5a11e71564d60547db673046abc081d13a8974153771e/feed/P83EUIV?user_id=PVPRM30",
  "personal_http_cal_url": "https://mercari.pagerduty.com/private/8dbd54c3531491edf0c5a11e71564d60547db673046abc081d13a8974153771e/feed/P83EUIV?user_id=PVPRM30",
  "users": [
   {
    "id": "PVPRM30",
    "type": "user_reference",
    "summary": "kohama@mercari.com",
    "self": "https://api.pagerduty.com/users/PVPRM30",
    "html_url": "https://mercari.pagerduty.com/users/PVPRM30"
   }
  ],
  "escalation_policies": [
   {
    "id": "P42GDDF",
    "type": "escalation_policy_reference",
    "summary": "test-shotarok-escalation-policy",
    "self": "https://api.pagerduty.com/escalation_policies/P42GDDF",
    "html_url": "https://mercari.pagerduty.com/escalation_policies/P42GDDF"
   }
  ],
  "schedule_layers": [
   {
    "name": "Layer 1",
    "rendered_schedule_entries": [],
    "rendered_coverage_percentage": null,
    "id": "PGQWKMX",
    "start": "2022-02-10T01:46:37+09:00",
    "end": null,
    "rotation_virtual_start": "2017-11-13T12:00:00+09:00",
    "rotation_turn_length_seconds": 86400,
    "users": [
     {
      "user": {
       "id": "PVPRM30",
       "type": "user_reference",
       "summary": "kohama@mercari.com",
       "self": "https://api.pagerduty.com/users/PVPRM30",
       "html_url": "https://mercari.pagerduty.com/users/PVPRM30"
      }
     }
    ],
    "restrictions": []
   }
  ],
  "overrides_subschedule": {
   "name": "Overrides",
   "rendered_schedule_entries": [],
   "rendered_coverage_percentage": null
  },
  "final_schedule": {
   "name": "Final Schedule",
   "rendered_schedule_entries": [],
   "rendered_coverage_percentage": null
  },
  "teams": [
   {
    "id": "P15AA14",
    "type": "team_reference",
    "summary": "test-shotarok",
    "self": "https://api.pagerduty.com/teams/P15AA14",
    "html_url": "https://mercari.pagerduty.com/teams/P15AA14"
   }
  ]
 }
}
-----------------------------------------------------: timestamp=2022-02-09T08:46:37.886-0800
2022-02-09T08:46:37.891-0800 [WARN]  Provider "provider[\"terraform.example.com/local/pagerduty\"]" produced an unexpected new value for pagerduty_schedule.test_schedule, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .layer[0].end: was null, but now cty.StringVal("")
pagerduty_schedule.test_schedule: Modifications complete after 1s [id=P83EUIV]
2022-02-09T08:46:37.924-0800 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2022-02-09T08:46:37.926-0800 [DEBUG] provider: plugin process exited: path=.terraform/providers/terraform.example.com/local/pagerduty/2.2.2/darwin_amd64/terraform-provider-pagerduty_v2.2.2 pid=75082
2022-02-09T08:46:37.926-0800 [DEBUG] provider: plugin exited

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

@shotarok
Copy link
Contributor Author

shotarok commented Feb 9, 2022

[MEMO] I found terraform destroy failed due to a nil pointer deference error. I fixed the code in 13b485d.

After that, I confirmed the terraform plan, terraform apply, and terraform destroy worked for the terraform resources I mentioned in #451.

@stmcallister
Copy link
Contributor

@shotarok Love the concept of this! Could you fix the conflicts that were introduced from the last merge to master? Thanks!

@shotarok
Copy link
Contributor Author

shotarok commented Feb 10, 2022

@stmcallister I merged the latest master (a0d1acf) into the branch locally, but it seems there are no conflicts. Would you like me to push the merge commit just in case?

[UPDATED] I merged the master into this branch in 7fd8311.

@shotarok
Copy link
Contributor Author

shotarok commented Feb 11, 2022

This is my first time to contribute this project. We may need an approval to run the GitHub workflow, and it'd be a blocker to merge this PR.

image

Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

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

Awesome! Thank you! And, thank you @smaeda-ks for the suggestion on creating the util function.

@stmcallister stmcallister merged commit 184f3f7 into PagerDuty:master Feb 15, 2022
@shotarok shotarok deleted the unset-end-when-deleted branch February 16, 2022 15:14
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.

3 participants