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

Print name of resource in error message

Open alexs77 opened this issue 2 years ago • 1 comments

It would be tremendously helpful, if the name of a resource would be mentioned in a generated error message. If this were done, remediation would be a lot easier.

In my usecase, I'm setting the name of a pagerduty_service to the contents of a variable that I pass into a module. If the name were known/shown, I'd terraform import it or maybe delete it on the Pagerduty web interface.

Terraform Version

$ terraform -v
Terraform v1.2.6
on linux_amd64
+ provider registry.terraform.io/hashicorp/azuread v2.26.1
+ provider registry.terraform.io/hashicorp/azurerm v3.15.1
+ provider registry.terraform.io/hashicorp/random v3.3.2
+ provider registry.terraform.io/pagerduty/pagerduty v2.5.2

Affected Resource(s)

  • pagerduty_servicepagerduty_service

Terraform Configuration Files

resource "pagerduty_service" "this" {
  name                    = var.name
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 600
  escalation_policy       = data.pagerduty_escalation_policy.default.id
  alert_creation          = "create_alerts_and_incidents"
}

Expected Behavior

Name should be shown in error message.

Actual Behavior

What actually happened?

│ Error: POST API call to https://api.pagerduty.com/services failed 400 Bad Request. Code: 2001, Errors: [Name has already been taken], Message: Invalid Input Provided
│ 
│   with module.asp["memory"].module.warn_asp_pagerduty["proc"].pagerduty_service.this,
│   on modules/pagerduty_action/main.tf line 18, in resource "pagerduty_service" "this":
│   18: resource "pagerduty_service" "this" {

alexs77 avatar Aug 04 '22 11:08 alexs77

@imjaroiswebdev I took a look at this issue and the error "Name has already been taken" comes from the REST API since the service model has a unique constraint on the name. Therefore, I would consider this a feature request for the REST API and should be filed as a customer support request. I would say that in most cases, the PagerDuty API does not send back the payload that the caller provides. We expect that API callers would be able to manage what attributes they send in their request and would be able to align their errors with the provided payload.

The terraform provider should not be expected to manage what validations failed and print those arguments in error messages. What we could do though is print all attributes used for the terraform resource upon any errors, but I do not know if that is possible, or if that would create too much noise for our error outputs, or if that would even be desirable for most customers. I think for most customers the 3 lines that reference the resource and resource name is good enough:

18: resource "pagerduty_service" "this" {

johncoleman83 avatar Sep 21 '22 12:09 johncoleman83