refactor: only fetch variables if unset variables are not allowed
This commit is contained in:
parent
dd856f8a1b
commit
9963bf940a
|
@ -82,22 +82,6 @@ func (b *Cloud) LocalRun(op *backend.Operation) (*backend.LocalRun, statemgr.Ful
|
||||||
}
|
}
|
||||||
ret.Config = config
|
ret.Config = config
|
||||||
|
|
||||||
// The underlying API expects us to use the opaque workspace id to request
|
|
||||||
// variables, so we'll need to look that up using our organization name
|
|
||||||
// and workspace name.
|
|
||||||
remoteWorkspaceID, err := b.getRemoteWorkspaceID(context.Background(), op.Workspace)
|
|
||||||
if err != nil {
|
|
||||||
diags = diags.Append(fmt.Errorf("error finding remote workspace: %w", err))
|
|
||||||
return nil, nil, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Printf("[TRACE] cloud: retrieving variables from workspace %s/%s (%s)", remoteWorkspaceName, b.organization, remoteWorkspaceID)
|
|
||||||
tfeVariables, err := b.client.Variables.List(context.Background(), remoteWorkspaceID, tfe.VariableListOptions{})
|
|
||||||
if err != nil && err != tfe.ErrResourceNotFound {
|
|
||||||
diags = diags.Append(fmt.Errorf("error loading variables: %w", err))
|
|
||||||
return nil, nil, diags
|
|
||||||
}
|
|
||||||
|
|
||||||
if op.AllowUnsetVariables {
|
if op.AllowUnsetVariables {
|
||||||
// If we're not going to use the variables in an operation we'll be
|
// If we're not going to use the variables in an operation we'll be
|
||||||
// more lax about them, stubbing out any unset ones as unknown.
|
// more lax about them, stubbing out any unset ones as unknown.
|
||||||
|
@ -105,6 +89,22 @@ func (b *Cloud) LocalRun(op *backend.Operation) (*backend.LocalRun, statemgr.Ful
|
||||||
// but not enough information to run a real operation (plan, apply, etc)
|
// but not enough information to run a real operation (plan, apply, etc)
|
||||||
ret.PlanOpts.SetVariables = stubAllVariables(op.Variables, config.Module.Variables)
|
ret.PlanOpts.SetVariables = stubAllVariables(op.Variables, config.Module.Variables)
|
||||||
} else {
|
} else {
|
||||||
|
// The underlying API expects us to use the opaque workspace id to request
|
||||||
|
// variables, so we'll need to look that up using our organization name
|
||||||
|
// and workspace name.
|
||||||
|
remoteWorkspaceID, err := b.getRemoteWorkspaceID(context.Background(), op.Workspace)
|
||||||
|
if err != nil {
|
||||||
|
diags = diags.Append(fmt.Errorf("error finding remote workspace: %w", err))
|
||||||
|
return nil, nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[TRACE] cloud: retrieving variables from workspace %s/%s (%s)", remoteWorkspaceName, b.organization, remoteWorkspaceID)
|
||||||
|
tfeVariables, err := b.client.Variables.List(context.Background(), remoteWorkspaceID, tfe.VariableListOptions{})
|
||||||
|
if err != nil && err != tfe.ErrResourceNotFound {
|
||||||
|
diags = diags.Append(fmt.Errorf("error loading variables: %w", err))
|
||||||
|
return nil, nil, diags
|
||||||
|
}
|
||||||
|
|
||||||
if tfeVariables != nil {
|
if tfeVariables != nil {
|
||||||
if op.Variables == nil {
|
if op.Variables == nil {
|
||||||
op.Variables = make(map[string]backend.UnparsedVariableValue)
|
op.Variables = make(map[string]backend.UnparsedVariableValue)
|
||||||
|
|
Loading…
Reference in New Issue