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

Getting "Error: Provider produced inconsistent result after apply" in tfe_workspace_settings

Open tyu0912 opened this issue 5 months ago • 1 comments
trafficstars

Terraform version

1.12.1

Expected Behavior

The apply should complete.

Actual Behavior

I am getting this error.

Error: Provider produced inconsistent result after apply
When applying changes to tfe_workspace_settings.resource_name["env"], provider "provider[\"registry.terraform.io/hashicorp/tfe\"]" produced an unexpected new value: .remote_state_consumer_ids: planned set element cty.StringVal("ws-xxxxxxxx") does not correlate with any element in actual.

This is a bug in the provider, which should be reported in the provider's own issue tracker.

Sample code that produces the error

resource "tfe_workspace_settings" "resource_name" {
  for_each     = local.env_list
  workspace_id = tfe_workspace.this_workspace[each.key].id

  global_remote_state = false
  remote_state_consumer_ids = [
    tfe_workspace.another_workspace[each.key].id
  ]
}

Additional Context

  • The code had applied successfully before.
  • I'm using version = "0.66.0" of the TFE provider.

tyu0912 avatar Jun 04 '25 19:06 tyu0912

@tyu0912 Hi, there, thanks for reporting the issue. Unfortunately, I'm not able to reproduce it using the config provided under a couple different methodologies. Can you provide more specific steps, including config modifications? Thanks so much.

brandonc avatar Jun 10 '25 17:06 brandonc

Hi @brandonc , sorry for the late reply. Not sure what happened but it doesn't seem like we're getting this issue anymore. I'll go ahead and close.

tyu0912 avatar Jun 24 '25 16:06 tyu0912

Hello, I believe we've tracked down the problem. We had multiple tfe_workspace_settings resources declared for the same workspace, which conflicted with each other, like this:

resource "tfe_workspace_settings" "allow_workspace_a" {
  workspace_id = tfe_workspace.core_workspace.id

  global_remote_state = false
  remote_state_consumer_ids = [
    tfe_workspace.workspace_a.id,
  ]
}

resource "tfe_workspace_settings" "allow_workspace_a_again_for_some_reason" {
  workspace_id = tfe_workspace.core_workspace.id

  global_remote_state = false
  remote_state_consumer_ids = [
    tfe_workspace.workspace_a.id,
  ]
}

resource "tfe_workspace_settings" "allow_workspace_b" {
  workspace_id = tfe_workspace.core_workspace.id

  global_remote_state = false
  remote_state_consumer_ids = [
    tfe_workspace.workspace_b.id,
  ]
}

They were spread over multiple files so it was difficult to notice the duplication.

The fix was to just combine them:

resource "tfe_workspace_settings" "core_workspace_settings" {
  workspace_id = tfe_workspace.core_workspace.id

  global_remote_state = false
  remote_state_consumer_ids = [
    tfe_workspace.workspace_a.id,
    tfe_workspace.workspace_b.id
  ]
}

Maybe we could document this restriction here? https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace_settings

For inspiration, S3 lifecycle rules have a similar restriction where you can only declare one lifecycle rule resource per bucket, which they document here: https://registry.terraform.io/providers/hashicorp/aws/6.0.0/docs/resources/s3_bucket_lifecycle_configuration

mchaffee-anaconda avatar Jul 11 '25 19:07 mchaffee-anaconda