Skip to content
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

feat: Generate show outputs with mappers #2886

Merged
merged 29 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
44ec626
generater show output with mappers starts here
sfc-gh-asawicki Jun 17, 2024
3170d49
Print all SDK struct field names with types
sfc-gh-asawicki Jun 22, 2024
c1ed52f
Change tabs to spaces
sfc-gh-asawicki Jun 22, 2024
4026d42
Reorganize code
sfc-gh-asawicki Jun 22, 2024
8124687
Test struct details extractor (WIP)
sfc-gh-asawicki Jun 22, 2024
352739f
Test struct details extractor
sfc-gh-asawicki Jun 22, 2024
47dffcd
Test column output
sfc-gh-asawicki Jun 22, 2024
f98da5c
Prepare schema field mapper (WIP)
sfc-gh-asawicki Jun 23, 2024
aa6ac60
Test all currently implemented schema types
sfc-gh-asawicki Jun 23, 2024
c902e23
Prepare model for generation (WIP)
sfc-gh-asawicki Jun 23, 2024
8b1b7c4
Print generated schemas and mappers
sfc-gh-asawicki Jun 23, 2024
2e9a566
Change logic a bit
sfc-gh-asawicki Jun 23, 2024
f44afe5
Extract generator and cleanup main
sfc-gh-asawicki Jun 23, 2024
041b4aa
Prepare saving to file
sfc-gh-asawicki Jun 23, 2024
09d9e1f
Add preamble
sfc-gh-asawicki Jun 23, 2024
7db2a89
Add generate
sfc-gh-asawicki Jun 23, 2024
d6f61fc
Add guards and generated comment
sfc-gh-asawicki Jun 23, 2024
915c07c
Handle pointers
sfc-gh-asawicki Jun 23, 2024
585c48f
Change comment and remove unused
sfc-gh-asawicki Jun 23, 2024
01dcc48
Add generating show output schemas to the makefile
sfc-gh-asawicki Jun 24, 2024
6c155fd
Add README and cleanup comments
sfc-gh-asawicki Jun 24, 2024
9189376
Generate all
sfc-gh-asawicki Jun 24, 2024
b250f0f
Improve README
sfc-gh-asawicki Jun 24, 2024
30183ea
Use the generated schemas and mappers instead of the manually created…
sfc-gh-asawicki Jun 24, 2024
cdc8053
Run make pre-push
sfc-gh-asawicki Jun 24, 2024
306100a
Fix after review
sfc-gh-asawicki Jun 25, 2024
1ec9d8e
Merge branch 'main' into generate-show-outputs-with-mappers
sfc-gh-asawicki Jun 25, 2024
9f96f50
Fix after merge
sfc-gh-asawicki Jun 25, 2024
b2cdf94
Fix the test
sfc-gh-asawicki Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,10 @@ generate-docs-additional-files: ## generate docs additional files
generate-docs-additional-files-check: generate-docs-additional-files ## check that docs additional files have been generated
git diff --exit-code -- examples/additional

generate-show-output-schemas: ## Generate show output schemas with mappers
go generate ./pkg/schemas/generate.go

clean-show-output-schemas: ## Clean generated show output schemas
rm -f ./pkg/schemas/*_gen.go

.PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance uninstall-tf
3 changes: 2 additions & 1 deletion docs/data-sources/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ Read-Only:

- `comment` (String)
- `created_on` (String)
- `dropped_on` (String)
- `is_current` (Boolean)
- `is_default` (Boolean)
- `is_transient` (Boolean)
- `kind` (String)
- `name` (String)
- `options` (String)
Expand All @@ -367,3 +367,4 @@ Read-Only:
- `owner_role_type` (String)
- `resource_group` (String)
- `retention_time` (Number)
- `transient` (Boolean)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/text v0.15.0
)

Expand Down Expand Up @@ -110,7 +111,6 @@ require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/zclconf/go-cty v1.14.2 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion pkg/datasources/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func ReadDatabases(ctx context.Context, d *schema.ResourceData, meta any) diag.D
flattenedDatabases := make([]map[string]any, len(databases))

for i, database := range databases {
database := database
var databaseDescription []map[string]any
if d.Get("with_describe").(bool) {
describeResult, err := client.Databases.Describe(ctx, database.ID())
Expand All @@ -158,7 +159,7 @@ func ReadDatabases(ctx context.Context, d *schema.ResourceData, meta any) diag.D
}

flattenedDatabases[i] = map[string]any{
"show_output": []map[string]any{schemas.DatabaseShowToSchema(database)},
"show_output": []map[string]any{schemas.DatabaseToSchema(&database)},
"describe_output": databaseDescription,
"parameters": databaseParameters,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/datasources/databases_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAcc_Databases_Complete(t *testing.T) {
resource.TestCheckResourceAttrSet("data.snowflake_databases.test", "databases.0.show_output.0.created_on"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.name", databaseName),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.kind", "STANDARD"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_transient", "false"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.transient", "false"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_default", "false"),
// Commenting as this value depends on the currently used database, which is different when running as a single test and multiple tests (e.g., on CI)
// resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.is_current", "true"),
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestAcc_Databases_Complete(t *testing.T) {
resource.TestCheckResourceAttrSet("data.snowflake_databases.test", "databases.0.show_output.0.created_on"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.name", databaseName),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.kind", "STANDARD"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_transient", "false"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.transient", "false"),
resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.show_output.0.is_default", "false"),
// Commenting for the same reason as above
// resource.TestCheckResourceAttr("data.snowflake_databases.test", "databases.0.is_current", "false"),
Expand Down
101 changes: 101 additions & 0 deletions pkg/schemas/account_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions pkg/schemas/alert_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions pkg/schemas/api_integration_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading