terraform-provider-pagerduty icon indicating copy to clipboard operation
terraform-provider-pagerduty copied to clipboard

Job Title cannot be unset

Open drastawi opened this issue 2 years ago • 2 comments

Hello,

Unsetting a job_title in pagerduty_user does not work. If a job title is unset, the diff is generated correctly showing

job_title = "abc" -> null

but then the job_value is omitted in the API request

Terraform Version

1.1.2 plugin version 2.5.2

Affected Resource(s)

pagerduty_user

Terraform Configuration Files

resource "pagerduty_user" "user1" { name = "user" email = "[email protected]" job_title = "developer" }

Debug Output

Panic Output

Expected Behavior

Job Title should be unset

Actual Behavior

Job Title is not unset

Steps to Reproduce

Set a job title on a user, remove it

Important Factoids

References

drastawi avatar Aug 03 '22 03:08 drastawi

This is a 2 part problem. The PagerDuty REST API will error with "Job title must be a String." if you send a user update payload with the attribute job_title: null and it will error with "The length of Job title must be within 1..100." if you send the user update payload with the attribute job_title: "". With a payload of {} (i.e. no reference to job_title) the attribute is completely ignored. So, the REST API needs to be first updated to allow unsetting of job_title. After that is updated, we can then address this issue. In most customer use cases they are not at all using job_title and so it is likely why this issue has never been addressed. Most customers just ignore the job_title attribute if it does happen to be set.

johncoleman83 avatar Sep 21 '22 20:09 johncoleman83

We have fixed the API for this to support unsetting job_title via an API request that sets job_title to null:

{
  "user":
    {
      "job_title": null
    }
}

However, in order to fix this terraform issue we need the ability for terraform to set null values for resources, but apparently terraform just removes the attribute from a resource if it's value is set to null in the config. I have been unable to discover how to allow null values to be set for resource attributes, which would then support the required data for the API to unset job_title. This appears to be a problem with terraform SDK as referenced here: https://github.com/hashicorp/terraform-plugin-sdk/issues/90

There may be support for this in upgraded versions of terraform-plugin-SDK, but I have been unable to get a fix introduced into this provider with the current version of the plugin-SDK, which is apparently v2 the version indicated in the above issue that has the fix.

@imjaroiswebdev are you aware of how to allow Resource Schema's to have a default value of nil? If someone can provide some insight on this, then this issue should be able to be fixed fairly easily.

johncoleman83 avatar Jan 27 '23 14:01 johncoleman83