@@ -8,7 +8,10 @@ import (
88 "regexp"
99 "testing"
1010
11+ "github.com/hashicorp/terraform-plugin-testing/knownvalue"
12+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
1113 "github.com/hashicorp/terraform-plugin-testing/terraform"
14+ "github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1215
1316 "github.com/hashicorp/terraform-plugin-go/tfprotov6"
1417 "github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -376,3 +379,50 @@ func TestImportBlock_WithID_WithBlankComputedAttribute_GeneratesCorrectPlan(t *t
376379 },
377380 })
378381}
382+
383+ func TestImportBlock_WithID_WithExternalProvider (t * testing.T ) {
384+ t .Parallel ()
385+
386+ config := `
387+ resource "random_string" "mystery_message" {
388+ length = 31
389+ }
390+ `
391+
392+ configWithImportBlock := config + `
393+ import {
394+ to = random_string.mystery_message
395+ id = "It was a dark and stormy night."
396+ }
397+ `
398+
399+ r .UnitTest (t , r.TestCase {
400+ TerraformVersionChecks : []tfversion.TerraformVersionCheck {
401+ tfversion .SkipBelow (tfversion .Version1_5_0 ), // ImportBlockWithID requires Terraform 1.5.0 or later
402+ },
403+ ExternalProviders : map [string ]r.ExternalProvider {
404+ "random" : {
405+ Source : "hashicorp/random" ,
406+ },
407+ },
408+ Steps : []r.TestStep {
409+ {
410+ Config : config ,
411+ },
412+ {
413+ ImportState : true ,
414+ ImportStateKind : r .ImportBlockWithID ,
415+ Config : configWithImportBlock ,
416+ ResourceName : "random_string.mystery_message" ,
417+ ImportPlanChecks : r.ImportPlanChecks {
418+ PreApply : []plancheck.PlanCheck {
419+ plancheck .ExpectKnownValue (
420+ "random_string.mystery_message" ,
421+ tfjsonpath .New ("result" ),
422+ knownvalue .StringExact ("It was a dark and stormy night." )),
423+ },
424+ },
425+ },
426+ },
427+ })
428+ }
0 commit comments