Commit graph

25 commits

Author SHA1 Message Date
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Samsondeen
2274026c68
query: add -query flag to validate command (#37671) 2025-10-01 11:33:52 +02:00
James Bardin
13faebed35 move ExtractLegacyConfigFromState calls out of genconfig 2025-08-29 15:11:56 -04:00
James Bardin
4c610ac5e6 use the new genconfig types throughout 2025-08-29 15:11:56 -04:00
James Bardin
ddc47f15e7 remove the recursive genconfig resource struct
The Resource struct didn't really match the data structure. Refactor
this to make it easier to break up the config generation calls so we can
pass in final config from the provider.
2025-08-29 15:11:56 -04:00
James Bardin
ee6588aba0 remove ctyCollectionValues and check deprected
make sure deprecated attrs don't show up
2025-08-26 14:43:55 -04:00
James Bardin
542ebed0aa remove the attr processor callbacks from genconfig
Since the config value is now filtered before formatting, we don't need
to make attribute formatting conditional on anything other than the
value being `null` or not.
2025-08-26 11:17:57 -04:00
James Bardin
5973586f2f refactor config generation
Config generation was mixing the "what" to generate with the "how" to
generate it, making it impossible to use other means of creating a
configuration value. We extract the filtering of the state into a
configuration value from the formatting code, maintaining the quirks
necessary to work with the legacy SDK.

We also removed all marks handling from the config generation, because
non-schema marks can only come from configuration, which this value is
not a part of.
2025-08-26 11:17:57 -04:00
Samsondeen
69fb908eaa
Always generate provider address for resources (#37318) 2025-07-16 08:52:50 +02:00
Samsondeen
8d8b2bb694
Generate config for list results (#37173) 2025-07-04 11:35:39 +02:00
Samsondeen
c0a7ff235b
Apply some new go collection features (#36818) 2025-04-02 16:20:16 +02:00
Ben Plotnick
de69c2285f
Fix overly-eager jsonencode (#35984)
* Fix overly-eager jsonencode

* Update internal/genconfig/generate_config_test.go

---------

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
2024-11-13 15:46:19 +00:00
Liam Cervante
c986269f45
configgen: escape any invalid HCL syntax in map keys (#35837) 2024-10-14 10:36:20 +02:00
Liam Cervante
f0d06bbf96 config generation: escape map keys with whitespace 2024-09-20 09:12:49 +02:00
Liam Cervante
3d211eb42f
Fix crash when importing a resource with complex sensitive attributes (#34996) 2024-04-16 16:59:02 +02:00
Daniel Schmidt
ba043a04d5
in import-generated code represent JSON values in HCL instead of as strings
This makes the value easier to read and is mostly an aesthetic change.

Closes #34444
2024-02-07 15:06:54 +01:00
CJ Horton
98b81d3c50 add missing copyright headers 2023-08-16 11:21:49 -07:00
CJ Horton
6ca13bfc1e fix static check errors 2023-05-30 18:00:41 -07:00
CJ Horton
cdce4c4a6d write generated config when using the cloud integration 2023-05-30 00:17:02 -07:00
kmoe
be2ad69eda
plannable import: safer config generation and schema filters (#33232)
* genconfig: fix nil nested block panic

* genconfig: null NestingSingle blocks should be absent

A NestingSingle block that is null in state should be completely absent from config.

* configschema: make FilterOr variadic

* configschema: apply filters to nested types

* configschema: filter helper/schema id attribute

The legacy SDK adds an Optional+Computed "id" attribute to the
resource schema even if not defined in provider code.
During validation, however, the presence of an extraneous "id"
attribute in config will cause an error.
Remove this attribute so we do not generate an "id" attribute
where there is a risk that it is not in the real resource schema.

* configschema: filter test

* terraform: do not pre-validate generated config

Config generated from a resource's import state may fail validation in
the case of schema behaviours such as ExactlyOneOf and ConflictsWith.
We don't want to fail the plan now, because that would give the user no
way to proceed and fix the config to make it valid. We allow the plan to
complete and output the generated config.

* generate config alongside import process

Rather than waiting until we call `plan()`, generate the configuration
at the point of the import call, so we have the necessary data to return
in case planning fails later.

The `plan` and `state` predeclared variables in the plan() method were
obfuscating the actual return of nil throughout, so those identifiers
were removed for clarity.

* move generateHCLStringAttributes closer to caller

* store generated config in plan on error

* test for config gen with error

* add simple warning when generating config

---------

Co-authored-by: James Bardin <j.bardin@gmail.com>
2023-05-24 11:16:05 +01:00
kmoe
4015f1aa30
genconfig: do not generate null NestingSingle blocks (#33213)
* genconfig: fix nil nested block panic

* always InternalValidate test schemas

* genconfig: null NestingSingle blocks should be absent

A NestingSingle block that is null in state should be completely absent from config.
2023-05-19 11:32:28 -07:00
kmoe
b4d1146f58
plannable import: improve gen config human plan output (#33194)
* renderer: remove hard-coded config gen path

* mention config gen file in plan next steps
2023-05-15 15:21:41 +01:00
Liam Cervante
d5fed58fc5
plannable import: write generated config to out flag (#33186)
* plannable import: write generated config to out flag

* Add example command to diagnostic
2023-05-12 23:05:00 +01:00
Liam Cervante
cd06543b39
plannable import: fix config generation printing empty collections instead of null values (#33183) 2023-05-11 20:18:25 +02:00
Liam Cervante
79f7f59155
Plannable import: Generate config for imported resources during the plan. (#33153)
* command: keep our promises

* remove some nil config checks

Remove some of the safety checks that ensure plan nodes have config attached at the appropriate time.

* add GeneratedConfig to plan changes objects

Add a new GeneratedConfig field alongside Importing in plan changes.

* add config generation package

The genconfig package implements HCL config generation from provider state values.

Thanks to @mildwonkey whose implementation of terraform add is the basis for this package.

* generate config during plan

If a resource is being imported and does not already have config, attempt to generate that config during planning. The config is generated from the state as an HCL string, and then parsed back into an hcl.Body to attach to the plan graph node.

The generated config string is attached to the change emitted by the plan.

* complete config generation prototype, and add tests

---------

Co-authored-by: Katy Moe <katy@katy.moe>
2023-05-11 08:38:37 +02:00