Skip to content

Add optional GetImportIDFn to ExternalName for providers where import ID differs from state ID #676

Description

@fernandezcuesta

What problem are you facing?

GetIDFn in config.ExternalName serves dual purpose: its return value is used both as the terraform import ID argument and as d.Id() in the reconstructed tfstate for terraform refresh.

Some Terraform providers use different ID formats for import vs state, making it impossible to satisfy both consumers with a single function.

For instance, with provider-mongodbatlas we identified in #127 that the upstream Terraform provider uses a custom conversion.EncodeStateID that base64-encodes compound keys into d.Id():

  • State d.Id(): cHJvamVjdF9pZA==:NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2-cm9sZV9uYW1l:dGVzdHhwLXJ3 (base64-encoded key:value, joined by -).
  • Import format: 666666666666666666666666-testxp-rw (plain values joined by -).

That is:

  • If GetIDFn returns the plain import format, terraform import works ✅ but terraform refresh breaks ❌ (DecodeStateID gets garbage).
  • If GetIDFn returns the base64 state format, terraform refresh works ✅ but terraform import breaks ❌ (import function can't parse base64).

How could Upjet help solve your problem?

Add an optional GetImportIDFn field to config.ExternalName, which optionally returns the ID to pass to terraform import.
When nil, GetIDFn is used (current behavior, backwards compatible).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions