Repository: opentofu/opentofu
File: internal/command/meta_config.go (Go)

Code before:
				}
				m.updateInputVariableCache(name, v)
			} else {
				return variable.Default, nil
			}
		}

		parsed, parsedDiags := v.ParseVariableValue(variable.ParsingMode)
		return parsed.Value, parsedDiags.ToHCL()
	}, rootDir, workspace)
	m.rootModuleCallCache = &call
	return call, diags
}

func (m *Meta) getInput(ctx context.Context, variable *configs.Variable) (string, error) {
	if !m.Input() {
		return "", fmt.Errorf("input is disabled")
	}

	varDesc := variable.Description
	switch {
	case variable.Description != "" && variable.DeprecatedSet:
		varDesc = fmt.Sprintf("%s.\nVariable is marked as deprecated with the following message: %s", variable.Description, variable.Deprecated)
	case variable.DeprecatedSet:
		varDesc = fmt.Sprintf("Variable is marked as deprecated with the following message: %s", variable.Deprecated)
	}
	uiInput := m.UIInput()
	rawValue, err := uiInput.Input(ctx, &tofu.InputOpts{
		Id:          fmt.Sprintf("var.%s", variable.Name),
		Query:       fmt.Sprintf("var.%s", variable.Name),
		Description: varDesc,
		Secret:      variable.Sensitive,
	})
	if err != nil {
		log.Printf("[TRACE] Meta.getInput Failed to prompt for %s: %s", variable.Name, err)
		return "", err
	}
	return rawValue, nil
}

// loadSingleModuleWithTests matches loadSingleModule except it also loads any
// tests for the target module.
func (m *Meta) loadSingleModuleWithTests(dir string, testDir string) (*configs.Module, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	dir = m.normalizePath(dir)

	loader, err := m.initConfigLoader()
	if err != nil {
		diags = diags.Append(err)
		return nil, diags
	}

Review comment (refactor):
nit: it seems like a duplicate of the function from `backend_local.go`. We could move it to `configs.Variable` and reuse in both places.

Code after:
				}
				m.updateInputVariableCache(name, v)
			} else {
				return variable.Default, nil
			}
		}

		parsed, parsedDiags := v.ParseVariableValue(variable.ParsingMode)
		return parsed.Value, parsedDiags.ToHCL()
	}, rootDir, workspace)
	m.rootModuleCallCache = &call
	return call, diags
}

func (m *Meta) getInput(ctx context.Context, variable *configs.Variable) (string, error) {
	if !m.Input() {
		return "", fmt.Errorf("input is disabled")
	}

	uiInput := m.UIInput()
	rawValue, err := uiInput.Input(ctx, &tofu.InputOpts{
		Id:          fmt.Sprintf("var.%s", variable.Name),
		Query:       fmt.Sprintf("var.%s", variable.Name),
		Description: variable.InputPrompt(),
		Secret:      variable.Sensitive,
	})
	if err != nil {
		log.Printf("[TRACE] Meta.getInput Failed to prompt for %s: %s", variable.Name, err)
		return "", err
	}
	return rawValue, nil
}

// loadSingleModuleWithTests matches loadSingleModule except it also loads any
// tests for the target module.
func (m *Meta) loadSingleModuleWithTests(dir string, testDir string) (*configs.Module, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	dir = m.normalizePath(dir)

	loader, err := m.initConfigLoader()
	if err != nil {
		diags = diags.Append(err)
		return nil, diags
	}

	call, vDiags := m.rootModuleCall(dir)
	diags = diags.Append(vDiags)
	if diags.HasErrors() {
		return nil, diags
	}