-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Generate config for list results #37173
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
base: main
Are you sure you want to change the base?
Conversation
0220cd9
to
5c3631d
Compare
9c45eda
to
31abfb0
Compare
24d0a55
to
439cb9e
Compare
49d6d13
to
b1fec46
Compare
0d9f62d
to
b0a7c2e
Compare
b1fec46
to
8c12ea0
Compare
a4fd5e9
to
68a752e
Compare
}, | ||
DeposedKey: states.NotDeposed, | ||
} | ||
|
||
ctx.Changes().AppendResourceInstanceChange(change) | ||
return diags | ||
} | ||
|
||
func (n *NodePlannableResourceInstance) generateListConfig(obj cty.Value, resourceSchema providers.Schema) (generated string, diags tfdiags.Diagnostics) { |
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.
This is almost entirely a copy of generateHCLStringAttributes
, is there any way we can combine them?
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.
This looks like a good start, I'm sure we're going to be coming back to this code as we figure out how code generation interacts with the cloud UI. It would be good if we can find a way reduce any copying between the import generation and this though, so we can evolve them together.
68a752e
to
4b2f4cb
Compare
4b2f4cb
to
d77f275
Compare
d77f275
to
bbe3024
Compare
912b10f
to
679b585
Compare
e331e73
to
052b03c
Compare
679b585
to
2066ea6
Compare
16dce47
to
8050ca1
Compare
a270992
to
e5bb256
Compare
1ed8a7c
to
fe3c957
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.
Nice work, but I encountered some issues while testing this.
I also wasn't able to have the config written to a file (when not using -json
). Maybe we need to update the backends to write the config
@@ -100,6 +100,16 @@ func (n *NodePlannableResourceInstance) listResourceExecute(ctx EvalContext) (di | |||
return diags | |||
} | |||
|
|||
// If a path is specified, generate the config for the resource | |||
if n.generateConfigPath != "" { |
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.
This needs to happen before the hook is called. Otherwise results.Generated
will always be null
|
||
result := json.NewQueryResult(addr, 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.
We only want to include config in the JSON when it has been requested and generated. Otherwise we will run into a panic
internal/command/views/json/query.go
Outdated
Address: addr.String(), | ||
func NewQueryResult(listAddr addrs.AbsResourceInstance, value cty.Value, generated *genconfig.Resource) QueryResult { | ||
result := QueryResult{ | ||
Address: generated.Addr.String(), |
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.
The address was a reference to the list block that produced this result. We should introduce another field if we want to expose the generated reference as well. But do we need that?
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.
👍 Perhaps we do not. I will leave it for now
internal/command/views/json/query.go
Outdated
ResourceObject: marshalValues(value.GetAttr("state")), | ||
// TODO: Add config once we have it available | ||
Config: string(generated.Body), |
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 think this should be generated.String()
to output the full resource block with labels
Fixes #
Target Release
1.13.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