|
|
|
|
@ -47,27 +47,43 @@ func TestManagedDataValidate(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestManagedDataUpgradeState(t *testing.T) {
|
|
|
|
|
schema := dataStoreResourceSchema()
|
|
|
|
|
ty := schema.Body.ImpliedType()
|
|
|
|
|
rawState := `{
|
|
|
|
|
"id": "not-quite-unique",
|
|
|
|
|
"input": {
|
|
|
|
|
"value": "input",
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
"output": {
|
|
|
|
|
"value": "input",
|
|
|
|
|
"type": "string"
|
|
|
|
|
},
|
|
|
|
|
"triggers_replace": {
|
|
|
|
|
"value": [
|
|
|
|
|
"a",
|
|
|
|
|
"b"
|
|
|
|
|
],
|
|
|
|
|
"type": [
|
|
|
|
|
"list",
|
|
|
|
|
"string"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}`
|
|
|
|
|
|
|
|
|
|
state := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
upgradedState, err := dataStoreResourceSchema().Body.CoerceValue(cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
"output": cty.StringVal("input"),
|
|
|
|
|
"triggers_replace": cty.ListVal([]cty.Value{
|
|
|
|
|
cty.StringVal("a"), cty.StringVal("b"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
jsState, err := ctyjson.Marshal(state, ty)
|
|
|
|
|
}))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// empty
|
|
|
|
|
req := providers.UpgradeResourceStateRequest{
|
|
|
|
|
TypeName: "terraform_data",
|
|
|
|
|
RawStateJSON: jsState,
|
|
|
|
|
RawStateJSON: []byte(rawState),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp := upgradeDataStoreResourceState(req)
|
|
|
|
|
@ -75,8 +91,8 @@ func TestManagedDataUpgradeState(t *testing.T) {
|
|
|
|
|
t.Error("upgrade state error:", resp.Diagnostics.ErrWithWarnings())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !resp.UpgradedState.RawEquals(state) {
|
|
|
|
|
t.Errorf("prior state was:\n%#v\nupgraded state is:\n%#v\n", state, resp.UpgradedState)
|
|
|
|
|
if !resp.UpgradedState.RawEquals(upgradedState) {
|
|
|
|
|
t.Errorf("prior state was:\n%s\nupgraded state is:\n%#v\n", rawState, resp.UpgradedState)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -135,12 +151,49 @@ func TestManagedDataPlan(t *testing.T) {
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.Number),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.String),
|
|
|
|
|
"output": cty.NullVal(cty.String),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.UnknownVal(cty.String).RefineNotNull(),
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
// write-only values are always returned as null
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.NullVal(cty.Number),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"create-typed-null-sensitive-write-only": {
|
|
|
|
|
prior: cty.NullVal(ty),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.String),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.Number),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.String),
|
|
|
|
|
"output": cty.NullVal(cty.String),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.UnknownVal(cty.String).RefineNotNull(),
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"sensitive_output": cty.NullVal(cty.Number),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@ -228,26 +281,279 @@ func TestManagedDataPlan(t *testing.T) {
|
|
|
|
|
"id": cty.UnknownVal(cty.String).RefineNotNull(),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-trigger": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(1),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem"),
|
|
|
|
|
"version": cty.NumberIntVal(2),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(2),
|
|
|
|
|
"output": cty.UnknownVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-trigger-to-sensitive": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(1),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem"),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
"version": cty.NumberIntVal(2),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
"version": cty.NumberIntVal(2),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"sensitive_output": cty.UnknownVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-auto": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem_1"),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.UnknownVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-auto-replace": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem_1"),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.UnknownVal(cty.String),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.UnknownVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"remove-value-auto-replace": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_1"),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_1"),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.UnknownVal(cty.DynamicPseudoType),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.UnknownVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-auto-sensitive": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
"sensitive_output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem_1"),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
"sensitive_output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
"sensitive_output": cty.UnknownVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no-update-store-trigger": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(1),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem 2"),
|
|
|
|
|
"version": cty.NumberIntVal(1),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(1),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no-update-store-auto": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem_2"),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_2"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"swap-sensitive": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("ephem_1"),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
proposed: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("ephem_1"),
|
|
|
|
|
"output": cty.StringVal("ephem_1"),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
// sensitive changes, swap the outputs
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"replace": cty.BoolVal(true),
|
|
|
|
|
"sensitive_output": cty.StringVal("ephem_1"),
|
|
|
|
|
"sensitive": cty.BoolVal(true),
|
|
|
|
|
}),
|
|
|
|
|
// swapping outputs does not replace, the value is not changing
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run("plan-"+name, func(t *testing.T) {
|
|
|
|
|
req := providers.PlanResourceChangeRequest{
|
|
|
|
|
TypeName: "terraform_data",
|
|
|
|
|
PriorState: tc.prior,
|
|
|
|
|
ProposedNewState: tc.proposed,
|
|
|
|
|
PriorState: mustCoerceManagedData(t, tc.prior),
|
|
|
|
|
ProposedNewState: mustCoerceManagedData(t, tc.proposed),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp := planDataStoreResourceChange(req)
|
|
|
|
|
if resp.Diagnostics.HasErrors() {
|
|
|
|
|
t.Fatal(resp.Diagnostics.ErrWithWarnings())
|
|
|
|
|
}
|
|
|
|
|
expectedPlanned := mustCoerceManagedData(t, tc.planned)
|
|
|
|
|
|
|
|
|
|
if !resp.PlannedState.RawEquals(tc.planned) {
|
|
|
|
|
t.Errorf("expected:\n%#v\ngot:\n%#v\n", tc.planned, resp.PlannedState)
|
|
|
|
|
if !resp.PlannedState.RawEquals(expectedPlanned) {
|
|
|
|
|
t.Errorf("expected:\n%#v\ngot:\n%#v\n", expectedPlanned, resp.PlannedState)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func mustCoerceManagedData(t *testing.T, v cty.Value) cty.Value {
|
|
|
|
|
schema := dataStoreResourceSchema().Body
|
|
|
|
|
v, err := schema.CoerceValue(v)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to coerce value: %s", err)
|
|
|
|
|
}
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
testUUIDHook = func() string {
|
|
|
|
|
return "not-quite-unique"
|
|
|
|
|
@ -257,15 +563,14 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
schema := dataStoreResourceSchema().Body
|
|
|
|
|
ty := schema.ImpliedType()
|
|
|
|
|
|
|
|
|
|
for name, tc := range map[string]struct {
|
|
|
|
|
prior cty.Value
|
|
|
|
|
config cty.Value
|
|
|
|
|
planned cty.Value
|
|
|
|
|
state cty.Value
|
|
|
|
|
}{
|
|
|
|
|
"create": {
|
|
|
|
|
prior: cty.NullVal(ty),
|
|
|
|
|
config: schema.EmptyValue(),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
@ -281,7 +586,12 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"create-output": {
|
|
|
|
|
prior: cty.NullVal(ty),
|
|
|
|
|
config: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
"output": cty.UnknownVal(cty.String),
|
|
|
|
|
@ -297,11 +607,11 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-input": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
"output": cty.StringVal("input"),
|
|
|
|
|
config: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("new-input"),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.ListVal([]cty.Value{cty.StringVal("new-input")}),
|
|
|
|
|
@ -318,11 +628,11 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-trigger": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
config: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
"output": cty.StringVal("input"),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.StringVal("new-value"),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
@ -339,13 +649,13 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-input-trigger": {
|
|
|
|
|
prior: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("input"),
|
|
|
|
|
"output": cty.StringVal("input"),
|
|
|
|
|
config: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.ListVal([]cty.Value{cty.StringVal("new-input")}),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.MapVal(map[string]cty.Value{
|
|
|
|
|
"key": cty.StringVal("value"),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.ListVal([]cty.Value{cty.StringVal("new-input")}),
|
|
|
|
|
@ -364,12 +674,69 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-trigger": {
|
|
|
|
|
config: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("new_ephem"),
|
|
|
|
|
"version": cty.NumberIntVal(1),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"replace": cty.NullVal(cty.Bool),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(2),
|
|
|
|
|
"output": cty.UnknownVal(cty.String),
|
|
|
|
|
"replace": cty.NullVal(cty.Bool),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
state: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"version": cty.NumberIntVal(2),
|
|
|
|
|
"output": cty.StringVal("new_ephem"),
|
|
|
|
|
"replace": cty.NullVal(cty.Bool),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"update-store-auto": {
|
|
|
|
|
config: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.StringVal("new_ephem"),
|
|
|
|
|
"output": cty.StringVal("ephem"),
|
|
|
|
|
"replace": cty.NullVal(cty.Bool),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.NullVal(cty.String),
|
|
|
|
|
}),
|
|
|
|
|
planned: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.UnknownVal(cty.String),
|
|
|
|
|
"replace": cty.NullVal(cty.Bool),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
state: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"store": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.StringVal("new_ephem"),
|
|
|
|
|
"replace": cty.NullVal(cty.Bool),
|
|
|
|
|
}),
|
|
|
|
|
"id": cty.StringVal("not-quite-unique"),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
} {
|
|
|
|
|
t.Run("apply-"+name, func(t *testing.T) {
|
|
|
|
|
req := providers.ApplyResourceChangeRequest{
|
|
|
|
|
TypeName: "terraform_data",
|
|
|
|
|
PriorState: tc.prior,
|
|
|
|
|
PlannedState: tc.planned,
|
|
|
|
|
Config: mustCoerceManagedData(t, tc.config),
|
|
|
|
|
PlannedState: mustCoerceManagedData(t, tc.planned),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp := applyDataStoreResourceChange(req)
|
|
|
|
|
@ -377,8 +744,10 @@ func TestManagedDataApply(t *testing.T) {
|
|
|
|
|
t.Fatal(resp.Diagnostics.ErrWithWarnings())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !resp.NewState.RawEquals(tc.state) {
|
|
|
|
|
t.Errorf("expected:\n%#v\ngot:\n%#v\n", tc.state, resp.NewState)
|
|
|
|
|
expected := mustCoerceManagedData(t, tc.state)
|
|
|
|
|
|
|
|
|
|
if !resp.NewState.RawEquals(expected) {
|
|
|
|
|
t.Errorf("expected:\n%#v\ngot:\n%#v\n", expected, resp.NewState)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@ -409,12 +778,14 @@ func TestMoveDataStoreResourceState_Id(t *testing.T) {
|
|
|
|
|
t.Errorf("unexpected diagnostics: %s", resp.Diagnostics.Err())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedTargetState := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"id": cty.StringVal("test"),
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
})
|
|
|
|
|
expected, err := dataStoreResourceSchema().Body.CoerceValue(cty.EmptyObjectVal)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
expectedMap := expected.AsValueMap()
|
|
|
|
|
|
|
|
|
|
expectedMap["id"] = cty.StringVal("test")
|
|
|
|
|
expectedTargetState := cty.ObjectVal(expectedMap)
|
|
|
|
|
|
|
|
|
|
if !resp.TargetState.RawEquals(expectedTargetState) {
|
|
|
|
|
t.Errorf("expected state was:\n%#v\ngot state is:\n%#v\n", expectedTargetState, resp.TargetState)
|
|
|
|
|
@ -475,14 +846,17 @@ func TestMoveDataStoreResourceState_Triggers(t *testing.T) {
|
|
|
|
|
t.Errorf("unexpected diagnostics: %s", resp.Diagnostics.Err())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expectedTargetState := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"id": cty.StringVal("test"),
|
|
|
|
|
"input": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"output": cty.NullVal(cty.DynamicPseudoType),
|
|
|
|
|
"triggers_replace": cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"testkey": cty.StringVal("testvalue"),
|
|
|
|
|
}),
|
|
|
|
|
expected, err := dataStoreResourceSchema().Body.CoerceValue(cty.EmptyObjectVal)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
expectedMap := expected.AsValueMap()
|
|
|
|
|
|
|
|
|
|
expectedMap["id"] = cty.StringVal("test")
|
|
|
|
|
expectedMap["triggers_replace"] = cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"testkey": cty.StringVal("testvalue"),
|
|
|
|
|
})
|
|
|
|
|
expectedTargetState := cty.ObjectVal(expectedMap)
|
|
|
|
|
|
|
|
|
|
if !resp.TargetState.RawEquals(expectedTargetState) {
|
|
|
|
|
t.Errorf("expected state was:\n%#v\ngot state is:\n%#v\n", expectedTargetState, resp.TargetState)
|
|
|
|
|
|