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

Resource missing argument validation leads to plan and apply inconsistency

Open Padorax opened this issue 3 years ago • 0 comments

Summary

PagerDuty has some internal validation on some arguments of schedule/escaltion_policy, which is missing in provider validation. As a consequence, terraform apply will error out while terraform plan can pass.
In some settings we want to apply continuously and automatically on the configuration files after plan can pass. This inconsistency will then become problematic as we will keep applying on broken configs.
Thus it would be good to add some ValidateFunc to the provider, so we can catch the invalid arguments before actual apply.

Validation items

Resource pagerduty_schedule

  • time_zone: there are a list of accepted values. e.g.,Europe/London, America/New_York, Asia/Singapore, Asia/Kolkata... terraform plan
  # module.teams.pagerduty_schedule.all["Terraform Test Schedule"] will be updated in-place
  ~ resource "pagerduty_schedule" "all" {
        id          = "<test_id>"
        name        = "Terraform Test Schedule"
      ~ time_zone   = "Asia/Singapore" -> "Asia/Foo"
        # (1 unchanged attribute hidden)

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

terraform apply

module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Modifying... [id=<test_id>]
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 10s elapsed]
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 20s elapsed]
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 30s elapsed]
...
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 1m50s elapsed]
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 2m0s elapsed]
╷
│ Error: PUT API call to https://api.pagerduty.com/schedules/<test_id>failed 400 Bad Request. Code: 2001, Errors: [Time zone must be a valid time zone string.], Message: Invalid Input Provided
  • users: cannot be empty list terraform plan
  # module.teams.pagerduty_schedule.all["Terraform Test Schedule"] will be updated in-place
  ~ resource "pagerduty_schedule" "all" {
        id          = "<test_id>"
        name        = "Terraform Test Schedule"
        # (2 unchanged attributes hidden)

      ~ layer {
            id                           = "<layer_id>"
            name                         = "Layer 1"
          ~ users                        = [
              - "<user_1>",
              - "<user_2>",
            ]
            # (3 unchanged attributes hidden)

            # (1 unchanged block hidden)
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

terraform apply

module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Modifying... [id=<test_id>]
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 10s elapsed]
...
module.teams.pagerduty_schedule.all["Terraform Test Schedule"]: Still modifying... [id=<test_id>, 2m0s elapsed]
╷
│ Error: PUT API call to https://api.pagerduty.com/schedules/<test_id> failed 400 Bad Request. Code: 3001, Errors: map[rotation_layers.users:[must contain at least one person]], Message: Invalid Schedule
  • type inside restriction block: can only be "daily_restriction" or "weekly_restriction"

Resource pagerduty_escalation_policy

  • num_loops: should be less than 10 terraform apply
│ Error: PUT API call to https://api.pagerduty.com/escalation_policies failed 400 Bad Request. Code: 2001, Errors:[Num loops must be less than 10], Message: Invalid Escalation_Policy
""
  • escalation_delay_in_minutes: should be bigger than 0 terraform apply
│ Error: PUT API call to https://api.pagerduty.com/escalation_policies failed 400 Bad Request. Code: 2001, Errors:[Escalation rules base Escalation delay must be at least 1 minute for a single target.], Message: Invalid Escalation_Policy
""

Padorax avatar May 18 '21 06:05 Padorax