@@ -2217,3 +2217,61 @@ func TestContext2Plan_importIdentityModuleWithOptional(t *testing.T) {
22172217 tfdiags .ObjectToString (wantIdentity ))
22182218 }
22192219}
2220+
2221+ func TestContext2Plan_importIdentityMissingResponse (t * testing.T ) {
2222+ p := testProvider ("aws" )
2223+ m := testModule (t , "import-identity-module" )
2224+
2225+ p .GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema (& providerSchema {
2226+ ResourceTypes : map [string ]* configschema.Block {
2227+ "aws_lb" : {
2228+ Attributes : map [string ]* configschema.Attribute {
2229+ "id" : {
2230+ Type : cty .String ,
2231+ Computed : true ,
2232+ },
2233+ },
2234+ },
2235+ },
2236+ IdentityTypes : map [string ]* configschema.Object {
2237+ "aws_lb" : {
2238+ Attributes : map [string ]* configschema.Attribute {
2239+ "name" : {
2240+ Type : cty .String ,
2241+ Required : true ,
2242+ },
2243+ },
2244+ Nesting : configschema .NestingSingle ,
2245+ },
2246+ },
2247+ })
2248+ p .ImportResourceStateResponse = & providers.ImportResourceStateResponse {
2249+ ImportedResources : []providers.ImportedResource {
2250+ {
2251+ TypeName : "aws_lb" ,
2252+ State : cty .ObjectVal (map [string ]cty.Value {
2253+ "id" : cty .StringVal ("foo" ),
2254+ }),
2255+ // No identity returned
2256+ },
2257+ },
2258+ }
2259+ ctx := testContext2 (t , & ContextOpts {
2260+ Providers : map [addrs.Provider ]providers.Factory {
2261+ addrs .NewDefaultProvider ("aws" ): testProviderFuncFixed (p ),
2262+ },
2263+ })
2264+
2265+ diags := ctx .Validate (m , & ValidateOpts {})
2266+ if diags .HasErrors () {
2267+ t .Fatalf ("unexpected errors\n %s" , diags .Err ().Error ())
2268+ }
2269+
2270+ _ , diags = ctx .Plan (m , states .NewState (), DefaultPlanOpts )
2271+ if ! diags .HasErrors () {
2272+ t .Fatal ("succeeded; want errors" )
2273+ }
2274+ if got , want := diags .Err ().Error (), `import of aws_lb.foo didn't return an identity` ; ! strings .Contains (got , want ) {
2275+ t .Fatalf ("wrong error:\n got: %s\n want: message containing %q" , got , want )
2276+ }
2277+ }
0 commit comments