Skip to content

Commit 9438807

Browse files
committed
Add TestStep flag to opt out of config modification
1 parent a21e44b commit 9438807

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

helper/resource/importstate/import_block_in_config_directory_test.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,40 @@ func TestImportBlock_InConfigDirectory(t *testing.T) {
3535
ConfigDirectory: config.StaticDirectory(`testdata/1`),
3636
},
3737
{
38-
ResourceName: "examplecloud_container.test",
39-
ImportState: true,
40-
ImportStateKind: r.ImportBlockWithID,
41-
ConfigDirectory: config.StaticDirectory(`testdata/2`),
38+
ResourceName: "examplecloud_container.test",
39+
ImportState: true,
40+
ImportStateKind: r.ImportBlockWithID,
41+
ImportStateReadOnlyConfig: true, // TODO: naming
42+
ConfigDirectory: config.StaticDirectory(`testdata/2`),
43+
},
44+
},
45+
})
46+
}
47+
48+
func TestImportBlock_InConfigDirectory_Writeable(t *testing.T) {
49+
t.Parallel()
50+
51+
r.UnitTest(t, r.TestCase{
52+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
53+
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later
54+
},
55+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
56+
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
57+
Resources: map[string]testprovider.Resource{
58+
"examplecloud_container": examplecloudResource(),
59+
},
60+
}),
61+
},
62+
Steps: []r.TestStep{
63+
{
64+
ConfigDirectory: config.StaticDirectory(`testdata/1`),
65+
},
66+
{
67+
ResourceName: "examplecloud_container.test",
68+
ImportState: true,
69+
ImportStateKind: r.ImportBlockWithID,
70+
ImportStateReadOnlyConfig: false,
71+
ConfigDirectory: config.StaticDirectory(`testdata/helper/writeable-config-directory`),
4272
},
4373
},
4474
})

helper/resource/testing.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ type TestStep struct {
666666

667667
ImportStateKind ImportStateKind
668668

669+
// ImportStateReadOnlyConfig indicates that the test framework should not
670+
// modify ConfigFile or ConfigDirectory inputs to the test step.
671+
ImportStateReadOnlyConfig bool
672+
669673
// ImportStateId is the ID to perform an ImportState operation with.
670674
// This is optional. If it isn't set, then the resource ID is automatically
671675
// determined by inspecting the state for ResourceName's ID.

0 commit comments

Comments
 (0)