From cb49a4c8d69980c723875d50033f54acb92fd633 Mon Sep 17 00:00:00 2001 From: Chris Arcand Date: Mon, 3 May 2021 21:16:38 -0500 Subject: [PATCH] backend/remote: Remove the -refresh=false restriction --- internal/backend/remote/backend_apply.go | 34 +++++++++------- internal/backend/remote/backend_plan.go | 49 ++++++++++-------------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/internal/backend/remote/backend_apply.go b/internal/backend/remote/backend_apply.go index 1cf8be8a0..14be147ba 100644 --- a/internal/backend/remote/backend_apply.go +++ b/internal/backend/remote/backend_apply.go @@ -60,15 +60,6 @@ func (b *Remote) opApply(stopCtx, cancelCtx context.Context, op *backend.Operati )) } - if !op.PlanRefresh { - diags = diags.Append(tfdiags.Sourceless( - tfdiags.Error, - "Applying without refresh is currently not supported", - `Currently the "remote" backend will always do an in-memory refresh of `+ - `the Terraform state prior to generating the plan.`, - )) - } - if b.hasExplicitVariableValues(op) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, @@ -96,11 +87,28 @@ func (b *Remote) opApply(stopCtx, cancelCtx context.Context, op *backend.Operati )) } + // For API versions prior to 2.3, RemoteAPIVersion will return an empty string, + // so if there's an error when parsing the RemoteAPIVersion, it's handled as + // equivalent to an API version < 2.3. + currentAPIVersion, parseErr := version.NewVersion(b.client.RemoteAPIVersion()) + + if !op.PlanRefresh { + desiredAPIVersion, _ := version.NewVersion("2.4") + + if parseErr != nil || currentAPIVersion.LessThan(desiredAPIVersion) { + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Error, + "Planning without refresh is not supported", + fmt.Sprintf( + `The host %s does not support the -refresh=false option for `+ + `remote plans.`, + b.hostname, + ), + )) + } + } + if len(op.Targets) != 0 { - // For API versions prior to 2.3, RemoteAPIVersion will return an empty string, - // so if there's an error when parsing the RemoteAPIVersion, it's handled as - // equivalent to an API version < 2.3. - currentAPIVersion, parseErr := version.NewVersion(b.client.RemoteAPIVersion()) desiredAPIVersion, _ := version.NewVersion("2.3") if parseErr != nil || currentAPIVersion.LessThan(desiredAPIVersion) { diff --git a/internal/backend/remote/backend_plan.go b/internal/backend/remote/backend_plan.go index da9b0064d..d73328bcd 100644 --- a/internal/backend/remote/backend_plan.go +++ b/internal/backend/remote/backend_plan.go @@ -65,23 +65,6 @@ func (b *Remote) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operatio )) } - if !op.PlanRefresh { - diags = diags.Append(tfdiags.Sourceless( - tfdiags.Error, - "Planning without refresh is currently not supported", - `Currently the "remote" backend will always do an in-memory refresh of `+ - `the Terraform state prior to generating the plan.`, - )) - } - - if op.PlanMode == plans.RefreshOnlyMode { - diags = diags.Append(tfdiags.Sourceless( - tfdiags.Error, - "Refresh-only mode is currently not supported", - `The "remote" backend does not currently support the refresh-only planning mode.`, - )) - } - if b.hasExplicitVariableValues(op) { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, @@ -110,19 +93,28 @@ func (b *Remote) opPlan(stopCtx, cancelCtx context.Context, op *backend.Operatio )) } - if len(op.ForceReplace) != 0 { - diags = diags.Append(tfdiags.Sourceless( - tfdiags.Error, - "Forced replacement is currently not supported", - `The "remote" backend does not currently support the -replace=... planning option.`, - )) + // For API versions prior to 2.3, RemoteAPIVersion will return an empty string, + // so if there's an error when parsing the RemoteAPIVersion, it's handled as + // equivalent to an API version < 2.3. + currentAPIVersion, parseErr := version.NewVersion(b.client.RemoteAPIVersion()) + + if !op.PlanRefresh { + desiredAPIVersion, _ := version.NewVersion("2.4") + + if parseErr != nil || currentAPIVersion.LessThan(desiredAPIVersion) { + diags = diags.Append(tfdiags.Sourceless( + tfdiags.Error, + "Planning without refresh is not supported", + fmt.Sprintf( + `The host %s does not support the -refresh=false option for `+ + `remote plans.`, + b.hostname, + ), + )) + } } if len(op.Targets) != 0 { - // For API versions prior to 2.3, RemoteAPIVersion will return an empty string, - // so if there's an error when parsing the RemoteAPIVersion, it's handled as - // equivalent to an API version < 2.3. - currentAPIVersion, parseErr := version.NewVersion(b.client.RemoteAPIVersion()) desiredAPIVersion, _ := version.NewVersion("2.3") if parseErr != nil || currentAPIVersion.LessThan(desiredAPIVersion) { @@ -255,8 +247,9 @@ in order to capture the filesystem context the remote workspace expects: } runOptions := tfe.RunCreateOptions{ - Message: tfe.String(queueMessage), ConfigurationVersion: cv, + Message: tfe.String(queueMessage), + Refresh: tfe.Bool(op.PlanRefresh), Workspace: w, }