command: Update "terraform show -json" tests for changed provider contract
We now require a provider to populate all of its defaults -- including unknown value placeholders -- during PlanResourceChange. That means the mock provider for testing "terraform show -json" must now manage the population of the computed "id" attribute during plan. To make this logic a little easier, we also change the ApplyResourceChange implementation to fill in a non-null id, since that makes it easier for the mock PlanResourceChange to recognize when it needs to populate that default value during an update.
This commit is contained in:
parent
82588af892
commit
7e186f72d9
|
@ -244,13 +244,29 @@ func showFixtureProvider() *terraform.MockProvider {
|
|||
p := testProvider()
|
||||
p.GetSchemaReturn = showFixtureSchema()
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse {
|
||||
idVal := req.ProposedNewState.GetAttr("id")
|
||||
amiVal := req.ProposedNewState.GetAttr("ami")
|
||||
if idVal.IsNull() {
|
||||
idVal = cty.UnknownVal(cty.String)
|
||||
}
|
||||
return providers.PlanResourceChangeResponse{
|
||||
PlannedState: req.ProposedNewState,
|
||||
PlannedState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": idVal,
|
||||
"ami": amiVal,
|
||||
}),
|
||||
}
|
||||
}
|
||||
p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse {
|
||||
idVal := req.PlannedState.GetAttr("id")
|
||||
amiVal := req.PlannedState.GetAttr("ami")
|
||||
if !idVal.IsKnown() {
|
||||
idVal = cty.StringVal("placeholder")
|
||||
}
|
||||
return providers.ApplyResourceChangeResponse{
|
||||
NewState: cty.UnknownAsNull(req.PlannedState),
|
||||
NewState: cty.ObjectVal(map[string]cty.Value{
|
||||
"id": idVal,
|
||||
"ami": amiVal,
|
||||
}),
|
||||
}
|
||||
}
|
||||
return p
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"schema_version": 0,
|
||||
"values": {
|
||||
"ami": "bar",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -37,11 +37,11 @@
|
|||
],
|
||||
"before": {
|
||||
"ami": "foo",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": {
|
||||
"ami": "bar",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after_unknown": {
|
||||
"ami": false,
|
||||
|
@ -61,7 +61,7 @@
|
|||
],
|
||||
"before": {
|
||||
"ami": "foo",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": null,
|
||||
"after_unknown": false
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"ami": "foo"
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -28,7 +29,8 @@
|
|||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"ami": "foo"
|
||||
"ami": "foo",
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"schema_version": 0,
|
||||
"values": {
|
||||
"ami": "bar",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -37,11 +37,11 @@
|
|||
],
|
||||
"before": {
|
||||
"ami": "bar",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after": {
|
||||
"ami": "bar",
|
||||
"id": null
|
||||
"id": "placeholder"
|
||||
},
|
||||
"after_unknown": {
|
||||
"ami": false,
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"ami": "bar"
|
||||
"ami": "bar",
|
||||
"id": "placeholder"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue