-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Add terraform query
subcommand (TF-25494)
#37174
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
Conversation
69f538d
to
5964722
Compare
5964722
to
788a724
Compare
518bd67
to
4ff576a
Compare
ee5b81f
to
0d9f62d
Compare
788a724
to
ad7d289
Compare
0d9f62d
to
b0a7c2e
Compare
ad7d289
to
5651d47
Compare
5651d47
to
b23cd80
Compare
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.
just some very early thoughts that jumped out to me - don't need to be addressed properly yet or anything.
internal/plans/changes.go
Outdated
|
||
ProviderAddr addrs.AbsProviderConfig | ||
|
||
Results cty.Value |
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.
Results cty.Value | |
Results []cty.Value |
Since this must be a slice / tuple - is it perhaps more clear to just not include that part in the cty encoding? This makes it totally unambiguous that this is a list of things.
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.
Currently we're storing the result in the following form:
cty.ObjectVal(map[string]cty.Value{"data": cty.TupleVal(results), "config": config})
This matches the schema and makes encoding/decoding easy, but I guess we really only need the tuple val in the plan 🤔
internal/plans/changes.go
Outdated
|
||
ProviderAddr addrs.AbsProviderConfig | ||
|
||
Results cty.Value |
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.
metanote: because of the way things might change over time this may eventually become a list of structs in which one of the things that it might contain is the value. We might add some metadata about the query results (like you see in the ResourceInstanceChange
for example.
This representation can change as it likes (as it is internal only) but eventually this will go into the jsonplan
package which has to be more backwards compatible. At that point - I'd pre-emptively add this into a json object instead of just adding the value directly. This makes it easier to add metadata in the future, as it wouldn't be a breaking change.
You could also do that here as well, to keep the internal and external representations closer together. But, that is totally optional for here, but definitely something you should consider for the external representation.
644e296
to
dd4ba88
Compare
679b585
to
2066ea6
Compare
result := log.ListQueryResult | ||
renderer.Streams.Printf("%s\t%s\t%s\n", | ||
result.Address, | ||
result.Identity, |
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.
Identity here is a map, but we are using it with the %s
string directive. Do we want to jsonify that map first?
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.
Good catch! I've added a TODO to revisit this renderer once the cloud backend supports list runs.
type QueryCommand struct { | ||
Meta | ||
} |
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.
Could we embed the PlanCommand
in here, and use its methods PrepareBackend, GatherVariables, OperationRequest? Query is kind of a Plan anyway.
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.
Interesting idea! Right now GatherVariables
is the only method with the exact same body, the other two are similar, but different. I'll check if GatherVariables
can stay as is for passing variables to the query command in a separate PR
The structured JSON now only logs a status on which list query is currently running. The new jsonlist package can marshal the query fields of a plan.
a270992
to
e5bb256
Compare
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.
Great work! 💯
This PR introduces a new (experimental) query command. The command reuses as much as possible from the existing plan operation implementation.
PreListQuery
andPostListQuery
. The latter is used to output the results of an individual list blockQueryInstance
in the plan changes, instead of using theResourceInstanceChange
. Even though we don't use this field for the CLI outputUX
Local Backend Human

Local Backend JSON

Cloud Backend

Target Release
1.14.x
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry