-
Notifications
You must be signed in to change notification settings - Fork 17
helper/resource: add ImportBlockWithResourceIdentity kind
#480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ImportBlockWithResourceIdentity kind
b986ce0 to
5072047
Compare
5072047 to
c2a5b46
Compare
austinvalle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is looking great! I do have some specific questions and suggestions around the version check
helper/resource/importstate/import_block_with_resource_identity_test.go
Outdated
Show resolved
Hide resolved
| if kind.resourceIdentity() { | ||
| err := runProviderCommandApply(ctx, t, wd, providers) | ||
| if err != nil { | ||
| return fmt.Errorf("applying plan with import config: %s", err) | ||
| } | ||
|
|
||
| newStateJSON, err := runProviderCommandGetStateJSON(ctx, t, wd, providers) | ||
| if err != nil { | ||
| return fmt.Errorf("getting state after applying plan with import config: %s", err) | ||
| } | ||
|
|
||
| newIdentityValues := identityValuesFromState(newStateJSON, resourceName) | ||
| if !cmp.Equal(priorIdentityValues, newIdentityValues) { | ||
| return fmt.Errorf("importing resource %s: expected identity values %v, got %v", resourceName, priorIdentityValues, newIdentityValues) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I'm more leaning towards not applying and just waiting for TF core to give us the data during plan for comparison (it sounds like it should be included)
At least how it is ATM, core is validating that the data doesn't change during apply, and if they remove that logic, the SDKs should probably add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly because we can't fully trust providers to apply what they plan (since the testing framework also supports SDKv2 😆 ), so if we can avoid it, I think we should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. Since we have a working implementation in this PR, it should be no trouble to switch to planned values & expect tests to remain green.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about this offline and we're good with keeping apply with the caveat that we'll remove it before full release
Co-authored-by: Austin Valle <[email protected]>
Co-authored-by: Austin Valle <[email protected]>
| case []any: | ||
| var quotedV []string | ||
| for _, v := range v.([]any) { | ||
| quotedV = append(quotedV, fmt.Sprintf(`%q`, v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 also need to handle lists of numbers and lists of booleans
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or not? I added list of numbers and lists of booleans to the test resource schema and ... still green 🟢.
austinvalle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great work on this @bbasata!
Co-authored-by: Austin Valle <[email protected]>
austinvalle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
To merge after #476. This pull request adds resource identity support to
ImportStatetest steps. For example:terraform-plugin-testing/helper/resource/importstate/import_block_with_resource_identity_test.go
Lines 32 to 48 in c2a5b46
In this example, the test author writes in-line config in Step 1. In Step 3 with
ImportBlockWithResourceIdentity, the test appends animportblock. The test constructs thisimportblock using resource identity values from the Step 1 state:terraform-plugin-testing/helper/resource/testing_new_import_state.go
Lines 118 to 126 in c2a5b46
The test generates a plan and asserts that the plan is a no-op import of a single resource:
terraform-plugin-testing/helper/resource/testing_new_import_state.go
Lines 221 to 227 in c2a5b46
Finally, the test compares the Step 3 identity values with the identity values in Step 1 state. 💭 I want to take another look to consider whether this is necessary or duplicative of the "no-op import" assertion. 💭
At the time of writing this PR, I observed that a generated plan does not include resource identity values. And I reasoned that it's safe to run
applyby this point -- the test applies a no-op import plan to a "sandboxed" statefile. Cross-ref #476 "Error on use of ImportStatePersist with plannable import"terraform-plugin-testing/helper/resource/testing_new_import_state.go
Lines 233 to 250 in c2a5b46