feat: add getImportIDFn#677
Conversation
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
📝 WalkthroughWalkthroughAdds an optional ChangesSeparate Terraform Import ID from State ID
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Thanks for this contribution! A couple of clarifying questions to help understand the design decisions:
🚥 Pre-merge checks | ✅ 7✅ Passed checks (7 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/terraform/store.go (1)
260-278: 💤 Low valueThanks for implementing this separation cleanly!
The logic correctly ensures that:
tfStateID(fromGetIDFn) is used forEnsureTFState— maintaining state consistencyw.terraformIDcan be overridden viaGetImportIDFn— enabling different import formatsThis aligns well with the downstream usage in
workspace.gowherew.terraformIDis explicitly noted as the import ID.One small suggestion for debugging ergonomics: both error paths (lines 263 and 274) wrap with the same
errGetIDmessage. If a provider developer hits an error, it might be tricky to know which function failed. Would you consider differentiating them? For example:💡 Optional: Differentiate error messages
tfStateID, err := fp.Config.ExternalName.GetIDFn(ctx, externalName, fp.parameters, fp.Setup.Map()) if err != nil { - return nil, errors.Wrap(err, errGetID) + return nil, errors.Wrap(err, "cannot get state ID") } // ... if fp.Config.ExternalName.GetImportIDFn != nil { w.terraformID, err = fp.Config.ExternalName.GetImportIDFn(ctx, externalName, fp.parameters, fp.Setup.Map()) if err != nil { - return nil, errors.Wrap(err, errGetID) + return nil, errors.Wrap(err, "cannot get import ID") } }This is purely optional — the current approach is consistent with the existing pattern. What do you think?
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/terraform/store.go` around lines 260 - 278, The error handling for GetIDFn and GetImportIDFn both wrap errors with the same errGetID message, making it difficult to distinguish which function failed during debugging. In the error wrapping calls after GetIDFn (line 263) and GetImportIDFn (line 274), use differentiated error messages for each path. For example, keep errGetID for the GetIDFn error and create or use a separate error constant (such as errGetImportID) for the GetImportIDFn error path to help provider developers quickly identify which function failed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/terraform/store.go`:
- Around line 260-278: The error handling for GetIDFn and GetImportIDFn both
wrap errors with the same errGetID message, making it difficult to distinguish
which function failed during debugging. In the error wrapping calls after
GetIDFn (line 263) and GetImportIDFn (line 274), use differentiated error
messages for each path. For example, keep errGetID for the GetIDFn error and
create or use a separate error constant (such as errGetImportID) for the
GetImportIDFn error path to help provider developers quickly identify which
function failed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 52f2ccf6-f4ec-437e-bae2-415036e32894
📒 Files selected for processing (2)
pkg/config/resource.gopkg/terraform/store.go
Description of your changes
Some Terraform providers store resource IDs in a different format than what their import function expects. Until now, upjet used a single function (
GetIDFn) to produce the ID for both purposes, making it impossible to support these providers correctly.This PR introduces an optional
GetImportIDFnfield toExternalName. When set, upjet uses it to produce the ID passed toterraform import, while continuing to useGetIDFnfor the state file used byterraform refresh. When unset, the existing behavior is preserved.Fixes #676
I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
Built provider-mongodbatlas 1.2.0-rc.1 on top of these changes, now I can set a custom function for
GetImportIDFnfor those resources where the upstream TF provider works as explained above.