Add deprecation warns during variables prompts

Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
This commit is contained in:
yottta
2025-03-07 10:36:35 +02:00
committed by Christian Mesh
parent 00ad53b1d5
commit 5c23fa5ccd
2 changed files with 25 additions and 2 deletions

View File

@@ -446,7 +446,7 @@ func (b *Local) interactiveCollectVariables(ctx context.Context, existing map[st
rawValue, err := uiInput.Input(ctx, &tofu.InputOpts{
Id: fmt.Sprintf("var.%s", name),
Query: fmt.Sprintf("var.%s", name),
Description: vc.Description,
Description: variableInputDescription(vc),
Secret: vc.Sensitive,
})
if err != nil {
@@ -461,6 +461,21 @@ func (b *Local) interactiveCollectVariables(ctx context.Context, existing map[st
return ret
}
// variableInputDescription compiles a message for the description when the variable input is needed.
// This is returning only the configs.Variable#Description if the variable is not deprecated,
// or it returns both, the description and the deprecation message in one string to be able to
// notify the user about the deprecation of the variable.
func variableInputDescription(v *configs.Variable) string {
switch {
case v.Description != "" && v.DeprecatedSet:
return fmt.Sprintf("%s.\nVariable deprecated: %s", v.Description, v.Deprecated)
case v.DeprecatedSet:
return fmt.Sprintf("Variable deprecated: %s", v.Deprecated)
default:
return v.Description
}
}
// stubUnsetVariables ensures that all required variables defined in the
// configuration exist in the resulting map, by adding new elements as necessary.
//