-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
show deprecation warning if -state is used with plan, apply, refresh #35660
Conversation
internal/command/apply.go
Outdated
if diags.HasWarnings() { | ||
view.Diagnostics(diags) | ||
diags = nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this, the warning should still be printed whenever the diagnostics are chosen to be delayed.
Is there something else that is dropping / ignoring the warning diagnostics later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it is required to print the diagnostics before, since on line number 73 planFile, diags := c.LoadPlanFile(args.PlanPath)
returns a new diagnostic slice, it doesn't append to the already available diags
variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I think we can change the other part instead of doing this 👍 It's more in keeping with the way the diagnostics are intended to work to just gather them up and report once.
You can change line 73 to something like:
planFile, moreDiags := c.LoadPlanFile(args.PlanPath)
diags = diags.Append(moreDiags)
if moreDiags.HasErrors() {
view.Diagnostics(diags)
return 1
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I think we can change the other part instead of doing this 👍 It's more in keeping with the way the diagnostics are intended to work to just gather them up and report once.
You can change line 73 to something like:
planFile, moreDiags := c.LoadPlanFile(args.PlanPath) diags = diags.Append(moreDiags) if moreDiags.HasErrors() { view.Diagnostics(diags) return 1 }
Yeah, this can be done.
internal/command/arguments/apply.go
Outdated
@@ -43,6 +43,9 @@ func ParseApply(args []string) (*Apply, tfdiags.Diagnostics) { | |||
} | |||
|
|||
cmdFlags := extendedFlagSet("apply", apply.State, apply.Operation, apply.Vars) | |||
if apply.State != nil { | |||
diags = append(diags, tfdiags.SimpleWarning("state is deprecated")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if this error message could present an alternative instead.
The correct thing to do is update the configuration to point to the chosen state file: #35562 (comment)
Maybe we could make this a proper diagnostic with the detail stating to use the path variable in the local backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will update and add a commit. And also, I have found a better way to check if the state
flag is specified, will add this also in the next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @liamcervante
Does this align with your thoughts? I also added the link to the resource for easier navigation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looking good, just some recommendations over the content of the error!
internal/command/arguments/apply.go
Outdated
"state is deprecated", | ||
fmt.Sprintf("use path variable of local backend instead : https://developer.hashicorp.com/terraform/language/settings/backends/local\n"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"state is deprecated", | |
fmt.Sprintf("use path variable of local backend instead : https://developer.hashicorp.com/terraform/language/settings/backends/local\n"), | |
"Deprecated flag: -state", | |
fmt.Sprintf("Use `path` attribute within the `local` backend instead: https://developer.hashicorp.com/terraform/language/v1.10.x/settings/backends/local#path"), |
Just a couple of nits over the language here.
I'd want to call out that it's the flag specifically that is deprecated.
Also, the documentation can change over time so I think it's better for us to link to the v1.10.x documentation directly given we're adding this deprecation warning for the 1.10 release. That way if we change the local
backend in the future, people using this version will get a direct link to something that makes sense.
Can you copy these changes over to the other places we raise the warning?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense.
Thanks
Oh yeah, the consistency checks make the point that you don't need to use Sprintf for the detail part of the error since the string is constant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good! Will merge after the checks have finished!
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
Merged, and CHANGELOG updated. Will be released as part of 1.10.0, thanks for your contribution! |
Thanks for your guidance throughout the PR :) |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR adds the functionality of showing a deprecation warning when
-state
is used along withplan
,apply
, andrefresh
. So, to add this functionality, I pushed a warning sayingstate is deprecated
in thediags
slice if thestate
field is notnil
in all those three files i.e. plan.go, apply.go and refresh.go.Fixes #35562
Target Release
1.8.x
Draft CHANGELOG entry
-state
flag when used withplan
,apply
, andrefresh
.ENHANCEMENTS
terraform plan -state=mstate.tfstate
shows**Warning**: state is deprecated
.terraform refresh -state=mstate.tfstate
shows**Warning**: state is deprecated
.terraform apply -state=mstate.tfstate
shows**Warning**: state is deprecated
.Output