mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-19 13:12:58 -06:00
terraform: some deepcopying going on
This commit is contained in:
parent
c14a17f39b
commit
1aff5e98e1
@ -752,8 +752,10 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
|
||||
cb := func(r *Resource) error {
|
||||
var diff *InstanceDiff
|
||||
|
||||
is := r.State.Primary
|
||||
|
||||
for _, h := range c.hooks {
|
||||
handleHook(h.PreDiff(r.Id, r.State.Primary))
|
||||
handleHook(h.PreDiff(r.Id, is))
|
||||
}
|
||||
|
||||
if r.Config == nil {
|
||||
@ -794,15 +796,15 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
|
||||
diff.Destroy = true
|
||||
}
|
||||
|
||||
if diff.RequiresNew() && r.State.Primary != nil && r.State.Primary.ID != "" {
|
||||
if diff.RequiresNew() && is != nil && is.ID != "" {
|
||||
// This will also require a destroy
|
||||
diff.Destroy = true
|
||||
}
|
||||
|
||||
if diff.RequiresNew() || r.State.Primary == nil || r.State.Primary.ID == "" {
|
||||
if diff.RequiresNew() || is == nil || is.ID == "" {
|
||||
var oldID string
|
||||
if r.State.Primary != nil {
|
||||
oldID = r.State.Primary.Attributes["id"]
|
||||
if is != nil {
|
||||
oldID = is.Attributes["id"]
|
||||
}
|
||||
|
||||
// Add diff to compute new ID
|
||||
@ -827,16 +829,20 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
|
||||
|
||||
// Determine the new state and update variables
|
||||
if !diff.Empty() {
|
||||
r.State.Primary = r.State.Primary.MergeDiff(diff)
|
||||
is = is.MergeDiff(diff)
|
||||
}
|
||||
|
||||
// TODO(mitchellh): do we really need this?
|
||||
state := r.State.deepcopy()
|
||||
state.Primary = is
|
||||
|
||||
// Update our internal state so that variable computation works
|
||||
c.sl.Lock()
|
||||
defer c.sl.Unlock()
|
||||
|
||||
// TODO: Handle other modules
|
||||
mod := c.state.RootModule()
|
||||
mod.Resources[r.Id] = r.State
|
||||
mod.Resources[r.Id] = state
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1780,7 +1780,7 @@ func TestContextPlan_diffVar(t *testing.T) {
|
||||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanDiffVarStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
t.Fatalf("actual:\n%s\n\nexpected:\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,11 +413,11 @@ func (i *InstanceState) deepcopy() *InstanceState {
|
||||
// won't be available until apply, the value is replaced with the
|
||||
// computeID.
|
||||
func (s *InstanceState) MergeDiff(d *InstanceDiff) *InstanceState {
|
||||
var result InstanceState
|
||||
if s != nil {
|
||||
result = *s
|
||||
result := s.deepcopy()
|
||||
if result == nil {
|
||||
result = new(InstanceState)
|
||||
result.init()
|
||||
}
|
||||
result.init()
|
||||
|
||||
if s != nil {
|
||||
for k, v := range s.Attributes {
|
||||
@ -439,7 +439,7 @@ func (s *InstanceState) MergeDiff(d *InstanceDiff) *InstanceState {
|
||||
}
|
||||
}
|
||||
|
||||
return &result
|
||||
return result
|
||||
}
|
||||
|
||||
func (i *InstanceState) GoString() string {
|
||||
|
Loading…
Reference in New Issue
Block a user