@@ -1890,3 +1890,107 @@ output "foo" {
18901890 t .Errorf ("should have reported the cycle to contain the target resource, but got %s" , got )
18911891 }
18921892}
1893+
1894+ func TestContext2Plan_importIdentityModule (t * testing.T ) {
1895+ p := testProvider ("aws" )
1896+ m := testModule (t , "import-identity-module" )
1897+
1898+ p .GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema (& providerSchema {
1899+ ResourceTypes : map [string ]* configschema.Block {
1900+ "aws_lb" : {
1901+ Attributes : map [string ]* configschema.Attribute {
1902+ "id" : {
1903+ Type : cty .String ,
1904+ Computed : true ,
1905+ },
1906+ },
1907+ },
1908+ },
1909+ IdentityTypes : map [string ]* configschema.Object {
1910+ "aws_lb" : {
1911+ Attributes : map [string ]* configschema.Attribute {
1912+ "name" : {
1913+ Type : cty .String ,
1914+ Required : true ,
1915+ },
1916+ },
1917+ Nesting : configschema .NestingSingle ,
1918+ },
1919+ },
1920+ })
1921+ p .ImportResourceStateResponse = & providers.ImportResourceStateResponse {
1922+ ImportedResources : []providers.ImportedResource {
1923+ {
1924+ TypeName : "aws_lb" ,
1925+ State : cty .ObjectVal (map [string ]cty.Value {
1926+ "id" : cty .StringVal ("foo" ),
1927+ }),
1928+ },
1929+ },
1930+ }
1931+ ctx := testContext2 (t , & ContextOpts {
1932+ Providers : map [addrs.Provider ]providers.Factory {
1933+ addrs .NewDefaultProvider ("aws" ): testProviderFuncFixed (p ),
1934+ },
1935+ })
1936+
1937+ diags := ctx .Validate (m , & ValidateOpts {})
1938+ if diags .HasErrors () {
1939+ t .Fatalf ("unexpected errors\n %s" , diags .Err ().Error ())
1940+ }
1941+
1942+ _ , diags = ctx .Plan (m , states .NewState (), DefaultPlanOpts )
1943+ if diags .HasErrors () {
1944+ t .Fatalf ("unexpected errors: %s" , diags .Err ())
1945+ }
1946+ }
1947+
1948+ func TestContext2Plan_importIdentityMissingRequired (t * testing.T ) {
1949+ p := testProvider ("aws" )
1950+ m := testModule (t , "import-identity-module" )
1951+
1952+ p .GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema (& providerSchema {
1953+ ResourceTypes : map [string ]* configschema.Block {
1954+ "aws_lb" : {
1955+ Attributes : map [string ]* configschema.Attribute {
1956+ "id" : {
1957+ Type : cty .String ,
1958+ Computed : true ,
1959+ },
1960+ },
1961+ },
1962+ },
1963+ IdentityTypes : map [string ]* configschema.Object {
1964+ "aws_lb" : {
1965+ Attributes : map [string ]* configschema.Attribute {
1966+ "name" : {
1967+ Type : cty .String ,
1968+ Required : true ,
1969+ },
1970+ "id" : {
1971+ Type : cty .String ,
1972+ Required : true ,
1973+ },
1974+ },
1975+ Nesting : configschema .NestingSingle ,
1976+ },
1977+ },
1978+ })
1979+
1980+ ctx := testContext2 (t , & ContextOpts {
1981+ Providers : map [addrs.Provider ]providers.Factory {
1982+ addrs .NewDefaultProvider ("aws" ): testProviderFuncFixed (p ),
1983+ },
1984+ })
1985+
1986+ diags := ctx .Validate (m , & ValidateOpts {})
1987+
1988+ if len (diags ) != 1 {
1989+ t .Fatalf ("expected one diag, got %d: %s" , len (diags ), diags .ErrWithWarnings ())
1990+ }
1991+
1992+ got := diags .Err ().Error ()
1993+ if ! strings .Contains (got , "Missing required field:" ) {
1994+ t .Errorf ("should have reported a missing required field, but got %s" , got )
1995+ }
1996+ }
0 commit comments