@@ -1961,6 +1961,9 @@ func TestContext2Plan_importIdentityModule(t *testing.T) {
1961
1961
State : cty .ObjectVal (map [string ]cty.Value {
1962
1962
"id" : cty .StringVal ("foo" ),
1963
1963
}),
1964
+ Identity : cty .ObjectVal (map [string ]cty.Value {
1965
+ "name" : cty .StringVal ("bar" ),
1966
+ }),
1964
1967
},
1965
1968
},
1966
1969
}
@@ -2138,3 +2141,79 @@ import {
2138
2141
}
2139
2142
})
2140
2143
}
2144
+
2145
+ func TestContext2Plan_importIdentityModuleWithOptional (t * testing.T ) {
2146
+ p := testProvider ("aws" )
2147
+ m := testModule (t , "import-identity-module" )
2148
+
2149
+ p .GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema (& providerSchema {
2150
+ ResourceTypes : map [string ]* configschema.Block {
2151
+ "aws_lb" : {
2152
+ Attributes : map [string ]* configschema.Attribute {
2153
+ "id" : {
2154
+ Type : cty .String ,
2155
+ Computed : true ,
2156
+ },
2157
+ },
2158
+ },
2159
+ },
2160
+ IdentityTypes : map [string ]* configschema.Object {
2161
+ "aws_lb" : {
2162
+ Attributes : map [string ]* configschema.Attribute {
2163
+ "name" : {
2164
+ Type : cty .String ,
2165
+ Required : true ,
2166
+ },
2167
+ "something" : {
2168
+ Type : cty .Number ,
2169
+ Optional : true ,
2170
+ },
2171
+ },
2172
+ Nesting : configschema .NestingSingle ,
2173
+ },
2174
+ },
2175
+ })
2176
+ wantIdentity := cty .ObjectVal (map [string ]cty.Value {
2177
+ "name" : cty .StringVal ("bar" ),
2178
+ "something" : cty .NumberIntVal (42 ),
2179
+ })
2180
+ p .ImportResourceStateResponse = & providers.ImportResourceStateResponse {
2181
+ ImportedResources : []providers.ImportedResource {
2182
+ {
2183
+ TypeName : "aws_lb" ,
2184
+ State : cty .ObjectVal (map [string ]cty.Value {
2185
+ "id" : cty .StringVal ("foo" ),
2186
+ }),
2187
+ Identity : wantIdentity ,
2188
+ },
2189
+ },
2190
+ }
2191
+ ctx := testContext2 (t , & ContextOpts {
2192
+ Providers : map [addrs.Provider ]providers.Factory {
2193
+ addrs .NewDefaultProvider ("aws" ): testProviderFuncFixed (p ),
2194
+ },
2195
+ })
2196
+
2197
+ diags := ctx .Validate (m , & ValidateOpts {})
2198
+ if diags .HasErrors () {
2199
+ t .Fatalf ("unexpected errors\n %s" , diags .Err ().Error ())
2200
+ }
2201
+
2202
+ plan , diags := ctx .Plan (m , states .NewState (), DefaultPlanOpts )
2203
+ if diags .HasErrors () {
2204
+ t .Fatalf ("unexpected errors: %s" , diags .Err ())
2205
+ }
2206
+
2207
+ addr := mustResourceInstanceAddr ("aws_lb.foo" )
2208
+ instPlan := plan .Changes .ResourceInstance (addr )
2209
+ if instPlan == nil {
2210
+ t .Fatalf ("no plan for %s at all" , addr )
2211
+ }
2212
+
2213
+ identityMatches := instPlan .Importing .Identity .Equals (wantIdentity )
2214
+ if ! identityMatches .True () {
2215
+ t .Errorf ("identity does not match\n got: %s\n want: %s" ,
2216
+ tfdiags .ObjectToString (instPlan .Importing .Identity ),
2217
+ tfdiags .ObjectToString (wantIdentity ))
2218
+ }
2219
+ }
0 commit comments