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
Fix for no json output of state locking actions for --json flag #32451
Conversation
Thanks for this submission. I will bring this to triage to see if it can be reviewed. |
Hi @zetHannes, thanks for this! I think this is a good start, and your implementation of the state locker view itself is fine. I'm just not entirely comfortable with how you are parsing the ViewType from the arguments because different commands are now initialising the view in different ways. For example:
I do agree that this is in large part due to a weakness in Terraform with all the different commands parsing their flags in their own way, and it's hard to work within that framework. Due to 4, I'd hesitate to add the var json bool
cmdFlags.BoolVar(&json, "json", false, "json") I understand this is going to be duplicating code, but at least we're being explicit about exactly which command supports JSON output and what that means for them. Just for the clarity, this is required before I'd be willing to accept this PR. If you're interested in a larger challenge, and something that might take a step to improving the inconsistencies, then we could try a larger refactor. Note, I'd be happy to accept the changes discussed above without this, and I think what I'm about to propose is substantially more work so I understand completely if you just implement the short term fix. But still, in case you are interested: All the view implementations already accept a View object that provide some behavioural flags. We could add the You could then modify the The challenge is then how to merge the There's probably going to be challenges I've missed, or something that will require additional thinking, but I think with something like that above we can make it so that every command is both being explicit about what kind of formats they support, and they are all sharing the same approach to parsing the UI arguments. If you're interested in this, I'd be happy to answer any questions and can do further reviews. If not, I'd be more than happy to accept the modified short term fix I proposed first, which shouldn't be too difficult. |
Hello. I am sorry for not responding for a time, currently I have a lot of stress to deal with, this is going to be until next Saturday at least. But thank you very much for the input, those will be refactoring challenges, currently I'd suggest I adapt the code to fix the short term issue and then further changes can be planned accordingly. |
Finally I have got enough time now!
You did mention the state_mv command, I guess that was more an example on using cmdline flags? Or do we also want to support JSON output for other commands? |
Yes, you're correct. We shouldn't actually be adding the JSON flag anywhere new as part of this change. I hadn't considered this in my previous comment which is why I used that example. You just need to make sure that the correct I think there are more commands than you listed, here is my list:
But not all of these lock the state, so you will only need to pass the view type around for some of these commands. Of the ones that do lock the state file they do so through the Meta.Operation function, so you could modify that function to accept the view type alongside the backend as an argument. Any command that doesn't support the JSON flag can just pass in Human, and any flag that does can pass in the ViewType they retrieved from the flag when the parsed it. Hopefully that all makes sense! |
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.
Looking good, just a couple of small nits.
Another topic was popping up which is the initialization process of the Backend. I did add the viewtype as a field of |
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.
New changes all look fine, just still some other unwanted changes left over from the first attempt.
internal/command/meta.go
Outdated
@@ -553,9 +553,13 @@ func (m *Meta) extendedFlagSet(n string) *flag.FlagSet { | |||
return f | |||
} | |||
|
|||
// process will process any -no-color entries out of the arguments. This |
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.
There's still some unwanted changes left over in this file.
internal/command/meta.go
Outdated
// will potentially modify the args in-place. It will return the resulting | ||
// slice, and update the Meta and Ui. | ||
// and b: |
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.
and here as well
Oh, sorry about that, I misread something here. Of course, that should have been erased as well already. |
All looks good, I'll merge this and update the changelog and we'll see the fix in v1.4.0! Thanks for your contribution! Much appreciated. |
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
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. |
Fixes #32265
Target Release
1.4.x
Draft CHANGELOG
BUG FIXES