Skip to content

Bug: powerplatform_connection.connection_parameters state is persisted inconsistently after apply #1139

@AdamCoulterOz

Description

@AdamCoulterOz

Describe the bug

powerplatform_connection.connection_parameters can violate Terraform's apply contract by ending up inconsistent or unknown after apply.

The provider currently mixes two sources of truth for connection_parameters:

  • the configured value from Terraform
  • the API response from Power Platform, which may omit the field or return only a partial/redacted subset

That leads to provider errors such as:

Error: Provider returned invalid result object after apply

After the apply operation, the provider still indicated an unknown value for
powerplatform_connection.example.connection_parameters.
All values must be known after apply, so this is always a bug in the provider.

and, depending on the connector / returned payload, also:

Error: Provider produced inconsistent result after apply

Sample Terraform Code

resource "powerplatform_connection" "example" {
  environment_id = "00000000-0000-0000-0000-000000000000"
  name           = "shared_azureopenai"
  display_name   = "Example Connection"

  connection_parameters = jsonencode({
    azureOpenAIResourceName = "example-resource"
    azureOpenAIApiKey       = "example-key"
    azureSearchEndpointUrl  = "https://example.search.windows.net"
    azureSearchApiKey       = "example-search-key"
  })

  lifecycle {
    ignore_changes = [
      connection_parameters,
    ]
  }
}

A second variant that can also reproduce the issue is when connection_parameters is omitted from config, but the platform returns parameter data in the create/read response.

Expected behavior

After terraform apply, the provider should always write a fully known Terraform state for connection_parameters.

Specifically:

  • if Terraform config provided a known connection_parameters value, the provider should preserve that known value in state even if the API returns only a partial/redacted payload
  • if Terraform config omitted connection_parameters, but the API returns a known value, the provider should write that known value to state
  • if the API does not return the field, the provider should write null, not unknown

The provider should never leave connection_parameters unknown after apply.

System Information

  • Provider Version: 4.1.0
  • OS & Version: Linux (Azure DevOps hosted agent)

Additional context

This appears to be a Terraform provider state-normalization bug in the powerplatform_connection resource.

The problem is caused by connection_parameters being declared as Optional + Computed, while the provider does not consistently normalize the final state after Create / Update. Some connector APIs return only a subset of the submitted parameters, which makes blindly trusting the API response invalid. Other responses omit the field entirely, which can leave the provider returning an unknown value after apply.

This is not a user configuration error; it is a provider contract bug.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcommunityRequest or issue originated from a customer or community request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions