-
Notifications
You must be signed in to change notification settings - Fork 16
helper/resource: plannable import re-work to support resources with dependencies #476
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e96524f
Error on use of ImportStatePersist with plannable import
bbasata 12842ab
Error on use of ImportStateVerify with plannable import
bbasata 91b5a0c
Rename test functions for consistency and for running by pattern
bbasata 2456d71
Import block works for a resource with a dependency
bbasata ccff991
Simplify no-op action check
bbasata 35f3b06
Add prerelease changelog entries
bbasata 90f5656
Add a catch-up prerelease changelog entry
bbasata e472964
Refactor test provider functions
bbasata cde5001
Fix 'No changes. Your infrastructure matches the configuration.' fals…
bbasata 372066c
Log (or do not log) consistently
bbasata 526853c
Fix format string syntax
bbasata 88a9bc9
Merge branch 'main' into zone-record
bbasata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: BREAKING CHANGES | ||
body: 'importstate: `ImportStatePersist` and `ImportStateVerify` are not supported for plannable import (`ImportBlockWith*`) and will return an error' | ||
time: 2025-04-04T17:06:56.900935-04:00 | ||
custom: | ||
Issue: "476" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: BREAKING CHANGES | ||
body: 'importstate: renamed `ImportStateWithId` to `ImportStateWithID` and renamed `ImportCommandWithId` to `ImportCommandWithID`.' | ||
time: 2025-04-04T17:10:48.525611-04:00 | ||
custom: | ||
Issue: "465" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
kind: BUG FIXES | ||
body: 'importstate: plannable import (`ImportBlockWith*`) fixed for a resource with a dependency' | ||
time: 2025-04-04T17:07:34.428542-04:00 | ||
custom: | ||
Issue: "476" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
helper/resource/importstate/import_block_for_resource_with_a_dependency_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package importstate_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
r "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
) | ||
|
||
func TestImportBlockForResourceWithADependency(t *testing.T) { | ||
bbasata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Parallel() | ||
|
||
config := ` | ||
resource "examplecloud_zone" "zone" { | ||
name = "example.net" | ||
} | ||
|
||
resource "examplecloud_zone_record" "record" { | ||
zone_id = examplecloud_zone.zone.id | ||
name = "www" | ||
} | ||
` | ||
r.UnitTest(t, r.TestCase{ | ||
bbasata marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later | ||
}, | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{ | ||
Resources: map[string]testprovider.Resource{ | ||
"examplecloud_zone": examplecloudZone(), | ||
"examplecloud_zone_record": examplecloudZoneRecord(), | ||
}, | ||
}), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
{ | ||
ImportState: true, | ||
ImportStateKind: r.ImportBlockWithID, | ||
ResourceName: "examplecloud_zone_record.record", | ||
}, | ||
}, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is less of a nit and more of a discussion our team should probably have at some point.
I'm not really sure how to do the changelogs for alpha/beta releases. I've currently been doing just one or two
NOTE
changelogs mentioning the general features and not specific deltas between releases, but I can see why you'd want to be more explicit in-case anyone was trying the features out 🤔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, I failed to call out the import test changes in the first changelog for alpha, so maybe a general note would be useful.
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.
💯
Right, I'm thinking to bias toward clarity here. Pre-releases will have partial implementations, so a little expectation-setting can go a long way.