Skip to content

Commit 971fa87

Browse files
committed
ImportBlockWithResourceIdentity requires Terraform 1.12.0+
1 parent c2a5b46 commit 971fa87

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

helper/resource/importstate/import_block_with_resource_identity_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package importstate_test
55

66
import (
7+
"regexp"
78
"testing"
89

910
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
@@ -20,7 +21,7 @@ func TestImportBlock_WithResourceIdentity(t *testing.T) {
2021

2122
r.UnitTest(t, r.TestCase{
2223
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
23-
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later
24+
tfversion.SkipBelow(tfversion.Version1_12_0), // ImportBlockWithResourceIdentity requires Terraform 1.12.0 or later
2425
},
2526
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
2627
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
@@ -48,3 +49,39 @@ func TestImportBlock_WithResourceIdentity(t *testing.T) {
4849
},
4950
})
5051
}
52+
53+
func TestImportBlock_WithResourceIdentity_RequiresVersion1_12_0(t *testing.T) {
54+
t.Parallel()
55+
56+
r.UnitTest(t, r.TestCase{
57+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
58+
tfversion.SkipBelow(tfversion.Version1_0_0), // ProtoV6ProviderFactories
59+
tfversion.SkipAbove(tfversion.Version1_11_0), // ImportBlockWithResourceIdentity requires Terraform 1.12.0 or later
60+
},
61+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
62+
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
63+
Resources: map[string]testprovider.Resource{
64+
"examplecloud_container": examplecloudResource(),
65+
},
66+
}),
67+
},
68+
Steps: []r.TestStep{
69+
{
70+
Config: `
71+
resource "examplecloud_container" "test" {
72+
location = "westeurope"
73+
name = "somevalue"
74+
}`,
75+
},
76+
{
77+
RefreshState: true,
78+
},
79+
{
80+
ResourceName: "examplecloud_container.test",
81+
ImportState: true,
82+
ImportStateKind: r.ImportBlockWithResourceIdentity,
83+
ExpectError: regexp.MustCompile(`Terraform 1.12.0 or later`),
84+
},
85+
},
86+
})
87+
}

helper/resource/testing_new_import_state.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ func importStatePreconditions(t testing.T, helper *plugintest.Helper, step TestS
473473

474474
case kind.plannable() && step.ImportStateVerify:
475475
return fmt.Errorf(`ImportStateVerify is not supported with plannable import blocks`)
476+
477+
case kind.resourceIdentity() && versionUnderTest.LessThan(tfversion.Version1_12_0):
478+
return fmt.Errorf(
479+
`ImportState steps using resource identity require Terraform 1.12.0 or later. Either ` +
480+
`upgrade the Terraform version running the test or add a ` + "`TerraformVersionChecks`" + ` to ` +
481+
`the test case to skip this test.` + "\n\n" +
482+
`https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/tfversion-checks#skip-version-checks`)
476483
}
477484

478485
return nil

0 commit comments

Comments
 (0)