diff --git a/internal/command/graph.go b/internal/command/graph.go index 24ee3e4054..d47e5b0de9 100644 --- a/internal/command/graph.go +++ b/internal/command/graph.go @@ -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 { diff --git a/internal/terraform/context.go b/internal/terraform/context.go index a6fe56006e..efae0769a9 100644 --- a/internal/terraform/context.go +++ b/internal/terraform/context.go @@ -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 diff --git a/internal/terraform/context_apply.go b/internal/terraform/context_apply.go index 72f277cc63..1aba22f8cf 100644 --- a/internal/terraform/context_apply.go +++ b/internal/terraform/context_apply.go @@ -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() { diff --git a/internal/terraform/context_plan.go b/internal/terraform/context_plan.go index e25172076b..9536f7f9fb 100644 --- a/internal/terraform/context_plan.go +++ b/internal/terraform/context_plan.go @@ -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)