terraform: MergeDiff uses a Diff as an argument
This commit is contained in:
parent
c646c9c9ad
commit
e8808db8c3
|
@ -110,8 +110,7 @@ type ResourceState struct {
|
|||
// If the diff attribute requires computing the value, and hence
|
||||
// won't be available until apply, the value is replaced with the
|
||||
// computeID.
|
||||
func (s *ResourceState) MergeDiff(
|
||||
d map[string]*ResourceAttrDiff) *ResourceState {
|
||||
func (s *ResourceState) MergeDiff(d *ResourceDiff) *ResourceState {
|
||||
var result ResourceState
|
||||
if s != nil {
|
||||
result = *s
|
||||
|
@ -123,7 +122,7 @@ func (s *ResourceState) MergeDiff(
|
|||
result.Attributes[k] = v
|
||||
}
|
||||
}
|
||||
for k, diff := range d {
|
||||
for k, diff := range d.Attributes {
|
||||
if diff.NewComputed {
|
||||
result.Attributes[k] = config.UnknownVariableValue
|
||||
continue
|
||||
|
|
|
@ -16,19 +16,21 @@ func TestResourceState_MergeDiff(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
diff := map[string]*ResourceAttrDiff{
|
||||
"foo": &ResourceAttrDiff{
|
||||
Old: "bar",
|
||||
New: "baz",
|
||||
},
|
||||
"bar": &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo",
|
||||
},
|
||||
"baz": &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo",
|
||||
NewComputed: true,
|
||||
diff := &ResourceDiff{
|
||||
Attributes: map[string]*ResourceAttrDiff{
|
||||
"foo": &ResourceAttrDiff{
|
||||
Old: "bar",
|
||||
New: "baz",
|
||||
},
|
||||
"bar": &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo",
|
||||
},
|
||||
"baz": &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "foo",
|
||||
NewComputed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -48,10 +50,12 @@ func TestResourceState_MergeDiff(t *testing.T) {
|
|||
func TestResourceState_MergeDiff_nil(t *testing.T) {
|
||||
var rs *ResourceState = nil
|
||||
|
||||
diff := map[string]*ResourceAttrDiff{
|
||||
"foo": &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "baz",
|
||||
diff := &ResourceDiff{
|
||||
Attributes: map[string]*ResourceAttrDiff{
|
||||
"foo": &ResourceAttrDiff{
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ func (t *Terraform) diffWalkFn(
|
|||
|
||||
// Determine the new state and update variables
|
||||
vars := make(map[string]string)
|
||||
rs := r.State.MergeDiff(diff.Attributes)
|
||||
rs := r.State.MergeDiff(diff)
|
||||
for ak, av := range rs.Attributes {
|
||||
vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue