Skip to content

pagerduty_tag_assignment Missing Resource State after applying multiple tags in a single plan/apply #1019

@michael-sweikata-ilx

Description

@michael-sweikata-ilx

Just started using the PagerDuty provider.

Title changed to reflect new contents. The issue isn't the loop, it's applying multiple tags in a single plan/apply. See comments below.

If I use the pagerduty_tag and pagerduty_tag_assignment with strings against a team, it's fine:

resource "pagerduty_tag" "name" {
 label = "Testing:Testing"
}
resource "pagerduty_tag_assignment" "name" {
  entity_type = "teams"
  tag_id = pagerduty_tag.name.id
  entity_id = pagerduty_team.this.id
}

However, if I introduce a for_each to the two:

locals {
  vals = {
    "testing":"testing",
    "t2":"t2"
  }
}
resource "pagerduty_tag" "name" {
  for_each = local.vals
  label = each.value
}
resource "pagerduty_tag_assignment" "name" {
  for_each = local.vals
  entity_type = "teams"
  tag_id = pagerduty_tag.name[each.key].id
  entity_id = pagerduty_team.this.id
}

The tags will apply, however the provider reports an error:


│ Error: Missing Resource State After Create
│ 
│   with pagerduty_tag_assignment.name["t2"],
│   on main.tf line 46, in resource "pagerduty_tag_assignment" "name":
│   46: resource "pagerduty_tag_assignment" "name" {
│ 
│ The Terraform Provider unexpectedly returned no resource state after having no errors in the resource creation. This is always an issue in the Terraform Provider and should be reported to the provider
│ developers.
│ 
│ The resource may have been successfully created, but Terraform is not tracking it. Applying the configuration again with no other action may result in duplicate resource errors. Import the resource if the
│ resource was actually created and Terraform should be tracking it.
╵
╷
│ Error: Missing Resource State After Create
│ 
│   with pagerduty_tag_assignment.name["testing"],
│   on main.tf line 46, in resource "pagerduty_tag_assignment" "name":
│   46: resource "pagerduty_tag_assignment" "name" {
│ 
│ The Terraform Provider unexpectedly returned no resource state after having no errors in the resource creation. This is always an issue in the Terraform Provider and should be reported to the provider
│ developers.
│ 
│ The resource may have been successfully created, but Terraform is not tracking it. Applying the configuration again with no other action may result in duplicate resource errors. Import the resource if the
│ resource was actually created and Terraform should be tracking it.

They show up as being created, but the provider doesn't list them:

terraform state list
pagerduty_tag.name["t2"]
pagerduty_tag.name["testing"]
pagerduty_team.this

Terraform version 1.11.4, PagerDuty provider version 3.25.0

Edit:

What's interesting is that when I convert it to a list of strings, I get one error, not two:

locals {
  vals = {
    "testing":"testing",
    "t2":"t2"
  }
  val = [for k,v in local.vals : "${k}:${v}"]
}

resource "pagerduty_tag" "name" {
  count = length(local.val)
  label = local.val[count.index]
}
resource "pagerduty_tag_assignment" "name" {
  count = length(local.val)
  entity_type = "teams"
  tag_id = pagerduty_tag.name[count.index].id
  entity_id = pagerduty_team.this.id
}

Yields:

pagerduty_tag.name[0]: Creating...
pagerduty_tag.name[1]: Creation complete after 0s [id=PDA1K9U]
pagerduty_tag.name[0]: Creation complete after 0s [id=PA0DJX4]
pagerduty_tag_assignment.name[1]: Creating...
pagerduty_tag_assignment.name[0]: Creating...
pagerduty_tag_assignment.name[1]: Creation complete after 1s [id=PYG2YOI.PDA1K9U]
╷
│ Error: Missing Resource State After Create
│ 
│   with pagerduty_tag_assignment.name[0],
│   on main.tf line 47, in resource "pagerduty_tag_assignment" "name":
│   47: resource "pagerduty_tag_assignment" "name" {
│ 
│ The Terraform Provider unexpectedly returned no resource state after having no errors in the resource creation. This is always an issue in the Terraform Provider and should be reported to the provider
│ developers.
│ 
│ The resource may have been successfully created, but Terraform is not tracking it. Applying the configuration again with no other action may result in duplicate resource errors. Import the resource if the
│ resource was actually created and Terraform should be tracking it.
╵
terraform state list
pagerduty_tag.name[1]
pagerduty_tag_assignment.name[1]
pagerduty_team.this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions