Rename the CLI arg for deprecation outputs/variables (#2774)

Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
This commit is contained in:
Andrei Ciobanu
2025-05-09 14:01:32 +03:00
committed by GitHub
parent 47875921a1
commit 8305bfb2ef
11 changed files with 45 additions and 20 deletions

View File

@@ -400,8 +400,8 @@ Options:
suitable for use in text editor integrations and suitable for use in text editor integrations and
other automated systems. Always disables color. other automated systems. Always disables color.
-deprecation-warns=lvl Specify what type of warnings are shown. Accepted -deprecation=module:m Specify what type of warnings are shown. Accepted
values for lvl: all, local, none. Default: all. values for "m": all, local, none. Default: all.
When "all" is selected, OpenTofu will show the When "all" is selected, OpenTofu will show the
deprecation warnings for all modules. When "local" deprecation warnings for all modules. When "local"
is selected, the warns will be shown only for the is selected, the warns will be shown only for the

View File

@@ -54,7 +54,7 @@ func ParseApply(args []string) (*Apply, tfdiags.Diagnostics) {
cmdFlags.BoolVar(&apply.AutoApprove, "auto-approve", false, "auto-approve") cmdFlags.BoolVar(&apply.AutoApprove, "auto-approve", false, "auto-approve")
cmdFlags.BoolVar(&apply.InputEnabled, "input", true, "input") cmdFlags.BoolVar(&apply.InputEnabled, "input", true, "input")
cmdFlags.BoolVar(&apply.ShowSensitive, "show-sensitive", false, "displays sensitive values") cmdFlags.BoolVar(&apply.ShowSensitive, "show-sensitive", false, "displays sensitive values")
cmdFlags.StringVar(&apply.ModuleDeprecationWarnings, "deprecation-warns", "", "control the level of deprecation warnings") cmdFlags.StringVar(&apply.ModuleDeprecationWarnings, "deprecation", "", "control the level of deprecation warnings")
var json bool var json bool
cmdFlags.BoolVar(&json, "json", false, "json") cmdFlags.BoolVar(&json, "json", false, "json")

View File

@@ -59,7 +59,7 @@ func ParsePlan(args []string) (*Plan, tfdiags.Diagnostics) {
cmdFlags.StringVar(&plan.OutPath, "out", "", "out") cmdFlags.StringVar(&plan.OutPath, "out", "", "out")
cmdFlags.StringVar(&plan.GenerateConfigPath, "generate-config-out", "", "generate-config-out") cmdFlags.StringVar(&plan.GenerateConfigPath, "generate-config-out", "", "generate-config-out")
cmdFlags.BoolVar(&plan.ShowSensitive, "show-sensitive", false, "displays sensitive values") cmdFlags.BoolVar(&plan.ShowSensitive, "show-sensitive", false, "displays sensitive values")
cmdFlags.StringVar(&plan.ModuleDeprecationWarnLevel, "deprecation-warns", "", "control the level of deprecation warnings") cmdFlags.StringVar(&plan.ModuleDeprecationWarnLevel, "deprecation", "", "control the level of deprecation warnings")
var json bool var json bool
cmdFlags.BoolVar(&json, "json", false, "json") cmdFlags.BoolVar(&json, "json", false, "json")

View File

@@ -47,7 +47,7 @@ func ParseView(args []string) (*View, []string) {
// argument we support, "i" will not be incremented. // argument we support, "i" will not be incremented.
i := 0 i := 0
for _, v := range args { for _, v := range args {
if prefix := "-deprecation-warns"; strings.HasPrefix(v, prefix) { if prefix := "-deprecation=module:"; strings.HasPrefix(v, prefix) {
common.ModuleDeprecationWarnLvl = tofu.ParseDeprecatedWarningLevel(strings.ReplaceAll(v, prefix, "")) common.ModuleDeprecationWarnLvl = tofu.ParseDeprecatedWarningLevel(strings.ReplaceAll(v, prefix, ""))
continue // continue to ensure that the counter is not incremented continue // continue to ensure that the counter is not incremented
} }

View File

@@ -9,6 +9,7 @@ import (
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/opentofu/opentofu/internal/tofu"
) )
func TestParseView(t *testing.T) { func TestParseView(t *testing.T) {
@@ -77,6 +78,26 @@ func TestParseView(t *testing.T) {
&View{NoColor: false, CompactWarnings: false, ConsolidateWarnings: false, Concise: false}, &View{NoColor: false, CompactWarnings: false, ConsolidateWarnings: false, Concise: false},
[]string{}, []string{},
}, },
"show all deprecation warnings": {
[]string{"-deprecation=module:all"},
&View{ModuleDeprecationWarnLvl: tofu.DeprecationWarningLevelAll, ConsolidateWarnings: true},
[]string{},
},
"show only local deprecation warnings": {
[]string{"-deprecation=module:local"},
&View{ModuleDeprecationWarnLvl: tofu.DeprecationWarningLevelLocal, ConsolidateWarnings: true},
[]string{},
},
"show no deprecation warnings": {
[]string{"-deprecation=module:none"},
&View{ModuleDeprecationWarnLvl: tofu.DeprecationWarningLevelNone, ConsolidateWarnings: true},
[]string{},
},
"deprecation used with other yet non-existing namespaces is returning those in the unparsed args": {
[]string{"-deprecation=othernamespace:arg", "-deprecation=module:none", "-deprecation=backend:arg"},
&View{ModuleDeprecationWarnLvl: tofu.DeprecationWarningLevelNone, ConsolidateWarnings: true},
[]string{"-deprecation=othernamespace:arg", "-deprecation=backend:arg"},
},
} }
for name, tc := range testCases { for name, tc := range testCases {
t.Run(name, func(t *testing.T) { t.Run(name, func(t *testing.T) {

View File

@@ -329,8 +329,8 @@ Other Options:
format, suitable for use in text editor format, suitable for use in text editor
integrations and other automated systems. integrations and other automated systems.
-deprecation-warns=lvl Specify what type of warnings are shown. -deprecation=module:m Specify what type of warnings are shown.
Accepted values for lvl: all, local, none. Accepted values for "m": all, local, none.
Default: all. When "all" is selected, OpenTofu Default: all. When "all" is selected, OpenTofu
will show the deprecation warnings for all will show the deprecation warnings for all
modules. When "local" is selected, the warns modules. When "local" is selected, the warns

View File

@@ -95,8 +95,12 @@ Silencing deprecation warnings could be presented in two different ways: globall
basis. This setting shouldn't be a part of a module call block since there could be multiple calls for the same module and each such basis. This setting shouldn't be a part of a module call block since there could be multiple calls for the same module and each such
call should either produce or silence the warnings. call should either produce or silence the warnings.
In this RFC I suggest to allow users to control module deprecation warnings via a CLI flag: `deprecation-warns`, which may In this RFC I suggest to allow users to control module deprecation warnings via a CLI flag: `deprecation`, which may
have the following values: `all` (default) or `local` (raise deprecation warnings only from module calls inside the local modules). have the following values:
* `module:all` (default) - shows all the deprecation warnings from local and remote module calls.
* `module:local` - raise deprecation warnings only from module calls inside the local modules.
* `module:none` - is silencing all the warnings regarding deprecated outputs/variables.
This could be extended later to include other options such as `none` to disable the deprecation warnings altogether. This could be extended later to include other options such as `none` to disable the deprecation warnings altogether.
### Technical Approach ### Technical Approach
@@ -123,7 +127,7 @@ presence.
We would need to extend module output nodes to also mark values as deprecated if the user specified so. Then, the mark should We would need to extend module output nodes to also mark values as deprecated if the user specified so. Then, the mark should
be checked where `tofu.EvalContext` is used to evaluate expressions and blocks (i.e. `EvalContext.EvaluateBlock` and be checked where `tofu.EvalContext` is used to evaluate expressions and blocks (i.e. `EvalContext.EvaluateBlock` and
`EvalContext.EvaluateExpr`). The deprecation mark check must take into account the value of `deprecation-warns` flag `EvalContext.EvaluateExpr`). The deprecation mark check must take into account the value of `deprecation` flag
and also it shouldn't fire if the value is used inside the module, which marked this value as deprecated. and also it shouldn't fire if the value is used inside the module, which marked this value as deprecated.
This approach would also allow us to reuse the implementation, if we want to mark more values as deprecated from different This approach would also allow us to reuse the implementation, if we want to mark more values as deprecated from different

View File

@@ -97,11 +97,11 @@ The following options change how the apply command executes and reports on the a
- `-show-sensitive` - If specified, sensitive values will not be - `-show-sensitive` - If specified, sensitive values will not be
redacted in te UI output. redacted in te UI output.
- `-deprecation-warns` - Specify what type of warnings are shown. - `-deprecation` - Specify what type of warnings are shown.
Accepted values: all, local, none. Default: all. When "all" is selected, Accepted values: "module:all", "module:local", "module:none". Default: module:all. When "module:all" is selected,
OpenTofu will show the deprecation warnings for all modules. When "local" is selected, OpenTofu will show the deprecation warnings for all modules. When "module:local" is selected,
the warnings will be shown only for the modules that are imported with a relative the warnings will be shown only for the modules that are imported with a relative
path. When "none" is selected, all the deprecation warnings will be dropped. path. When "module:none" is selected, all the deprecation warnings will be dropped.
- All [planning modes](plan.mdx#planning-modes) and - All [planning modes](plan.mdx#planning-modes) and
[planning options](plan.mdx#planning-options) for [planning options](plan.mdx#planning-options) for

View File

@@ -385,11 +385,11 @@ The available options are:
* `-json` - Produce output in a machine-readable JSON format, suitable for * `-json` - Produce output in a machine-readable JSON format, suitable for
use in text editor integrations and other automated systems. use in text editor integrations and other automated systems.
* `-deprecation-warns` - Specify what type of warnings are shown. * `-deprecation` - Specify what type of warnings are shown.
Accepted values: all, local, none. Default: all. When "all" is selected, Accepted values: "module:all", "module:local", "module:none". Default: "module:all". When "module:all" is selected,
OpenTofu will show the deprecation warnings for all modules. When "local" is selected, OpenTofu will show the deprecation warnings for all modules. When "module:local" is selected,
the warnings will be shown only for the modules that are imported with a relative the warnings will be shown only for the modules that are imported with a relative
path. When "none" is selected, all the deprecation warnings will be dropped. path. When "module:none" is selected, all the deprecation warnings will be dropped.
For configurations using For configurations using
[the `local` backend](../../language/settings/backends/local.mdx) only, [the `local` backend](../../language/settings/backends/local.mdx) only,

View File

@@ -243,5 +243,5 @@ their configuration:
│ 'examle' output must no longer be used due to a typo, use 'example' instead │ 'examle' output must no longer be used due to a typo, use 'example' instead
``` ```
Deprecation warnings can be filtered or disabled by using the `-deprecation-warns` CLI argument. For more details, check its description Deprecation warnings can be filtered or disabled by using the `-deprecation` CLI argument. For more details, check its description
in the command options for [plan](../../cli/commands/plan.mdx#other-options) and [apply](../../cli/commands/apply.mdx#apply-options). in the command options for [plan](../../cli/commands/plan.mdx#other-options) and [apply](../../cli/commands/apply.mdx#apply-options).

View File

@@ -329,7 +329,7 @@ their configuration:
│ 'examle' variable must no longer be used due to a typo, use 'example' instead │ 'examle' variable must no longer be used due to a typo, use 'example' instead
``` ```
Deprecation warnings can be filtered or disabled by using the `-deprecation-warns` CLI argument. For more details, check its description Deprecation warnings can be filtered or disabled by using the `-deprecation` CLI argument. For more details, check its description
in the command options for [plan](../../cli/commands/plan.mdx#other-options) and [apply](../../cli/commands/apply.mdx#apply-options). in the command options for [plan](../../cli/commands/plan.mdx#other-options) and [apply](../../cli/commands/apply.mdx#apply-options).
## Using Input Variable Values ## Using Input Variable Values