github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/terraform/context_refresh.go (about) 1 package terraform 2 3 import ( 4 "log" 5 6 "github.com/muratcelep/terraform/not-internal/configs" 7 "github.com/muratcelep/terraform/not-internal/plans" 8 "github.com/muratcelep/terraform/not-internal/states" 9 "github.com/muratcelep/terraform/not-internal/tfdiags" 10 ) 11 12 // Refresh is a vestigial operation that is equivalent to call to Plan and 13 // then taking the prior state of the resulting plan. 14 // 15 // We retain this only as a measure of semi-backward-compatibility for 16 // automation relying on the "terraform refresh" subcommand. The modern way 17 // to get this effect is to create and then apply a plan in the refresh-only 18 // mode. 19 func (c *Context) Refresh(config *configs.Config, prevRunState *states.State, opts *PlanOpts) (*states.State, tfdiags.Diagnostics) { 20 if opts == nil { 21 // This fallback is only here for tests, not for real code. 22 opts = &PlanOpts{ 23 Mode: plans.NormalMode, 24 } 25 } 26 if opts.Mode != plans.NormalMode { 27 panic("can only Refresh in the normal planning mode") 28 } 29 30 log.Printf("[DEBUG] Refresh is really just plan now, so creating a %s plan", opts.Mode) 31 p, diags := c.Plan(config, prevRunState, opts) 32 if diags.HasErrors() { 33 return nil, diags 34 } 35 36 return p.PriorState, diags 37 }