SDK set ID during plan

Hi, I’m using terraform-plugin-sdk/v2 and I’m trying to set my resource ID during plan.
Currently, my resource ID appear as (known after apply) in plan.
I tried doing it in a CustomizeDiff but setting a new id does not seems to work.
When using diff.SetNew("id", newID), it seems that it requires a declared id attribute, but making so does not change the resource’s ID in plan.

I found a stackoverflow answer that mention setting ID to a concrete value during the planning phase but I could not figure a way to do so.

Is there a way to do this with the SDKv2 ?
If not, can the terraform framework solve my issue ? I’m still reluctant to use it as hashicorp’s main providers does not seems to use it extensively.

The id attribute is special in the legacy SDK, and setting id was essentially equivalent to signaling that the resource has been created (and also deleted by removing the id). I doubt you could get around that to generate a planned id value. This is contrary to how Terraform core works, where id is a normal attribute juts like any other, and doesn’t even need to exist as an attribute

The main providers are primarily not using the framework only because they are massive codebases which will take a long time to migrate, but they have no real desire to remain on SDKv2.

2 Likes