Skip to content

Commit

Permalink
Add DetailedDiff to RefreshStep
Browse files Browse the repository at this point in the history
  • Loading branch information
Frassle committed Apr 11, 2024
1 parent 1b65e6c commit ac5ec5d
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions pkg/resource/deploy/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,11 +794,12 @@ func (s *ReadStep) Apply(preview bool) (resource.Status, StepCompleteFunc, error
// resource by reading its current state from its provider plugin. These steps are not issued by the step generator;
// instead, they are issued by the deployment executor as the optional first step in deployment execution.
type RefreshStep struct {
deployment *Deployment // the deployment that produced this refresh
old *resource.State // the old resource state, if one exists for this urn
new *resource.State // the new resource state, to be used to query the provider
done chan<- bool // the channel to use to signal completion, if any
provider plugin.Provider // the optional provider to use.
deployment *Deployment // the deployment that produced this refresh
old *resource.State // the old resource state, if one exists for this urn
new *resource.State // the new resource state, to be used to query the provider
done chan<- bool // the channel to use to signal completion, if any
provider plugin.Provider // the optional provider to use.
detailedDiff map[string]plugin.PropertyDiff // the structured property diff.
}

// NewRefreshStep creates a new Refresh step.
Expand All @@ -814,15 +815,16 @@ func NewRefreshStep(deployment *Deployment, old *resource.State, done chan<- boo
}
}

func (s *RefreshStep) Op() display.StepOp { return OpRefresh }
func (s *RefreshStep) Deployment() *Deployment { return s.deployment }
func (s *RefreshStep) Type() tokens.Type { return s.old.Type }
func (s *RefreshStep) Provider() string { return s.old.Provider }
func (s *RefreshStep) URN() resource.URN { return s.old.URN }
func (s *RefreshStep) Old() *resource.State { return s.old }
func (s *RefreshStep) New() *resource.State { return s.new }
func (s *RefreshStep) Res() *resource.State { return s.old }
func (s *RefreshStep) Logical() bool { return false }
func (s *RefreshStep) Op() display.StepOp { return OpRefresh }
func (s *RefreshStep) Deployment() *Deployment { return s.deployment }
func (s *RefreshStep) Type() tokens.Type { return s.old.Type }
func (s *RefreshStep) Provider() string { return s.old.Provider }
func (s *RefreshStep) URN() resource.URN { return s.old.URN }
func (s *RefreshStep) Old() *resource.State { return s.old }
func (s *RefreshStep) New() *resource.State { return s.new }
func (s *RefreshStep) Res() *resource.State { return s.old }
func (s *RefreshStep) Logical() bool { return false }
func (s *RefreshStep) DetailedDiff() map[string]plugin.PropertyDiff { return s.detailedDiff }

// ResultOp returns the operation that corresponds to the change to this resource after reading its current state, if
// any.
Expand Down Expand Up @@ -911,6 +913,16 @@ func (s *RefreshStep) Apply(preview bool) (resource.Status, StepCompleteFunc, er
now := time.Now().UTC()
s.new.Modified = &now
}

// Diff the user inputs against the provider inputs. If there are any differences, fail the import unless this step
// is from an import deployment.
diff, err := diffResource(s.new.URN, s.new.ID, s.old.Inputs, s.old.Outputs, s.new.Inputs, prov, preview, nil)
if err != nil {
return rst, nil, err
}

s.detailedDiff = diff.DetailedDiff

} else {
s.new = nil
}
Expand Down

0 comments on commit ac5ec5d

Please sign in to comment.