pass the option via context

pull/36186/head
Samsondeen Dare 1 year ago
parent 77c362b414
commit d213d45cc5

@ -115,6 +115,7 @@ func (c *GraphCommand) Run(args []string) int {
c.showDiagnostics(diags)
return 1
}
lr.Core.SetGraphOpts(&terraform.ContextGraphOpts{SkipGraphValidation: true})
if graphTypeStr == "" {
if planFile == nil {

@ -61,6 +61,8 @@ type ContextOpts struct {
PreloadedProviderSchemas map[addrs.Provider]providers.ProviderSchema
UIInput UIInput
SkipGraphValidation bool
}
// ContextMeta is metadata about the running context. This is information
@ -95,9 +97,10 @@ type Context struct {
plugins *contextPlugins
hooks []Hook
sh *stopHook
uiInput UIInput
hooks []Hook
sh *stopHook
uiInput UIInput
graphOpts *ContextGraphOpts
l sync.Mutex // Lock acquired during any task
parallelSem Semaphore
@ -154,6 +157,9 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
hooks: hooks,
meta: opts.Meta,
uiInput: opts.UIInput,
graphOpts: &ContextGraphOpts{
SkipGraphValidation: opts.SkipGraphValidation,
},
plugins: plugins,
@ -163,6 +169,11 @@ func NewContext(opts *ContextOpts) (*Context, tfdiags.Diagnostics) {
}, diags
}
func (c *Context) SetGraphOpts(opts *ContextGraphOpts) tfdiags.Diagnostics {
c.graphOpts = opts
return nil
}
func (c *Context) Schemas(config *configs.Config, state *states.State) (*Schemas, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
@ -179,8 +190,8 @@ func (c *Context) Schemas(config *configs.Config, state *states.State) (*Schemas
}
type ContextGraphOpts struct {
// If true, validates the graph structure (checks for cycles).
Validate bool
// If false, skip the graph structure validation.
SkipGraphValidation bool
// Legacy graphs only: won't prune the graph
Verbose bool

@ -370,7 +370,7 @@ func (c *Context) applyGraph(plan *plans.Plan, config *configs.Config, opts *App
Operation: operation,
ExternalReferences: plan.ExternalReferences,
Overrides: plan.Overrides,
SkipValidation: !validate,
SkipValidation: c.graphOpts.SkipGraphValidation,
}).Build(addrs.RootModuleInstance)
diags = diags.Append(moreDiags)
if moreDiags.HasErrors() {

@ -135,9 +135,6 @@ type PlanOpts struct {
// Forget if set to true will cause the plan to forget all resources. This is
// only allowd in the context of a destroy plan.
Forget bool
// SkipGraphValidation if set to true will skip the graph validation step
SkipGraphValidation bool
}
// Plan generates an execution plan by comparing the given configuration
@ -918,7 +915,7 @@ func (c *Context) planGraph(config *configs.Config, prevRunState *states.State,
forgetResources: forgetResources,
forgetModules: forgetModules,
GenerateConfigPath: opts.GenerateConfigPath,
SkipValidation: opts.SkipGraphValidation,
SkipValidation: c.graphOpts.SkipGraphValidation,
}).Build(addrs.RootModuleInstance)
return graph, walkPlan, diags
case plans.RefreshOnlyMode:
@ -1113,7 +1110,7 @@ func (c *Context) PlanGraphForUI(config *configs.Config, prevRunState *states.St
var diags tfdiags.Diagnostics
opts := &PlanOpts{Mode: mode, SkipGraphValidation: true}
opts := &PlanOpts{Mode: mode}
graph, _, moreDiags := c.planGraph(config, prevRunState, opts)
diags = diags.Append(moreDiags)

Loading…
Cancel
Save