Skip to content

Commit

Permalink
Generate "expand" and "flatten" functions for associated external typ…
Browse files Browse the repository at this point in the history
…es linked to list, map, set, single nested attributes and blocks (#32)

* Bumping terraform-plugin-codegen-spec to c6dffeb (#31)

* Updating IR JSON to use import object for associated_external_type rather than an array of objects (#31)

* Initial implementation for generation of to-from (expand-flatten) functions (#31)

* Add associated external type to single nested block in ir.json and update test data (#31)

* Remove unused templates (#31)

* Adding processing for bool with associated external type (#31)

* Using a struct for attributes nested within a block (#31)

* Adding type-specific fields for use with model object template (#31)

* Adding types for use with attribute fields and making the template for use with primitive attributes generic (#31)

* Using direct mapping for primitives in expand and flatten functions (#31)

* Updated ir.json to include associated external type defined on attribute within single nested block that has an associated external type (#31)

* Only suffix with newline if not already suffixed (#31)

* Removing handling of nested primitives with associated external type from model object template (#31)

* Remove processing of primitives with associated external type (#31)

  * Remove recursion, and only process top-level
    primitive attributes within nested attributes
    and nested blocks

* Set-up generation of expand and flatten functions for single nested (#31)

* Renaming template and fixing tests (#31)

* Add handling for list nested attribute/block with associated external type (#31)

* Add handling for map nested attribute with associated external type (#31)

* Add handling for set nested attribute/block with associated external type (#31)

* Add handling for list, map, set, single nested attributes and blocks for provider and resource (#31)

* Wiring-up generation of expand and flatten for provider and resources (#31)

* Loading imports for associated external type for list, map, set, single nested attributes and blocks (#31)

* Returning error diagnostic when types.List, types.Map, types.Set or types.Object passed into expand function is unknown (#31)

* Add handling in the expand functions for objects within a list, map or set that are unknown (#31)

* Add handling in the flatten functions for api objects that could be nil (#31)

* Consolidating logic (#31)

* Refactored adding Imports() method to AssocExtType and switching attributes to implementing AssocExtType (#31)
  • Loading branch information
bendbennett authored Aug 16, 2023
1 parent cdaaa8f commit 61b856c
Show file tree
Hide file tree
Showing 102 changed files with 14,056 additions and 1,172 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/google/go-cmp v0.5.9
github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230627062719-bd7e40ab90a0
github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230804072831-c6dffebf6781
github.com/hashicorp/terraform-plugin-framework v1.2.0
github.com/mattn/go-colorable v0.1.12
github.com/mitchellh/cli v1.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ github.com/hashicorp/go-hclog v1.4.0 h1:ctuWFGrhFha8BnnzxqeRGidlEcQkDyL5u8J8t5eA
github.com/hashicorp/go-hclog v1.4.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230627062719-bd7e40ab90a0 h1:XzAAD3+z0wE1YpYSn/6Pnf3spFTyguFSQG+rP2Ldmbo=
github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230627062719-bd7e40ab90a0/go.mod h1:4aZFKiOI2xiQFOpeQMMyDL8vRmKAZXHUY4kWol7Fdco=
github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230804072831-c6dffebf6781 h1:FvNFHIsSf/5Yd5DTsLXoMhKVx6pRdCdkwvEt/SmbUWg=
github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230804072831-c6dffebf6781/go.mod h1:4aZFKiOI2xiQFOpeQMMyDL8vRmKAZXHUY4kWol7Fdco=
github.com/hashicorp/terraform-plugin-framework v1.2.0 h1:MZjFFfULnFq8fh04FqrKPcJ/nGpHOvX4buIygT3MSNY=
github.com/hashicorp/terraform-plugin-framework v1.2.0/go.mod h1:nToI62JylqXDq84weLJ/U3umUsBhZAaTmU0HXIVUOcw=
github.com/hashicorp/terraform-plugin-go v0.14.3 h1:nlnJ1GXKdMwsC8g1Nh05tK2wsC3+3BL/DBBxFEki+j0=
Expand Down
14 changes: 13 additions & 1 deletion internal/cmd/generate_data_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func generateDataSourceCode(spec spec.Specification, outputPath, packageName, ge
log.Fatal(err)
}

// generate "expand" and "flatten" code
modelsToFromBytes, err := g.ModelsToFromBytes()
if err != nil {
log.Fatal(err)
}

// format schema code
formattedDataSourcesSchema, err := format.Format(schemaBytes)
if err != nil {
Expand All @@ -170,8 +176,14 @@ func generateDataSourceCode(spec spec.Specification, outputPath, packageName, ge
log.Fatal(err)
}

// format "expand" and "flatten" code
formattedDataSourcesToFrom, err := format.Format(modelsToFromBytes)
if err != nil {
log.Fatal(err)
}

// write code
err = output.WriteDataSources(formattedDataSourcesSchema, formattedDataSourcesModels, formattedDataSourcesModelObjectHelpers, outputPath)
err = output.WriteDataSources(formattedDataSourcesSchema, formattedDataSourcesModels, formattedDataSourcesModelObjectHelpers, formattedDataSourcesToFrom, outputPath)
if err != nil {
return fmt.Errorf("error writing Go code to output: %w", err)
}
Expand Down
14 changes: 13 additions & 1 deletion internal/cmd/generate_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func generateProviderCode(spec spec.Specification, outputPath, packageName, gene
log.Fatal(err)
}

// generate "expand" and "flatten" code
modelsToFromBytes, err := g.ModelsToFromBytes()
if err != nil {
log.Fatal(err)
}

// format schema code
formattedProvidersSchema, err := format.Format(schemaBytes)
if err != nil {
Expand All @@ -170,8 +176,14 @@ func generateProviderCode(spec spec.Specification, outputPath, packageName, gene
log.Fatal(err)
}

// format "expand" and "flatten" code
formattedProviderToFrom, err := format.Format(modelsToFromBytes)
if err != nil {
log.Fatal(err)
}

// write code
err = output.WriteProviders(formattedProvidersSchema, formattedProvidersModels, formattedProvidersModelObjectHelpers, outputPath)
err = output.WriteProviders(formattedProvidersSchema, formattedProvidersModels, formattedProvidersModelObjectHelpers, formattedProviderToFrom, outputPath)
if err != nil {
return fmt.Errorf("error writing Go code to output: %w", err)
}
Expand Down
14 changes: 13 additions & 1 deletion internal/cmd/generate_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func generateResourceCode(spec spec.Specification, outputPath, packageName, gene
log.Fatal(err)
}

// generate "expand" and "flatten" code
modelsToFromBytes, err := g.ModelsToFromBytes()
if err != nil {
log.Fatal(err)
}

// format schema code
formattedResourcesSchema, err := format.Format(schemaBytes)
if err != nil {
Expand All @@ -170,8 +176,14 @@ func generateResourceCode(spec spec.Specification, outputPath, packageName, gene
log.Fatal(err)
}

// format "expand" and "flatten" code
formattedResourcesToFrom, err := format.Format(modelsToFromBytes)
if err != nil {
log.Fatal(err)
}

// write code
err = output.WriteResources(formattedResourcesSchema, formattedResourcesModels, formattedResourcesModelObjectHelpers, outputPath)
err = output.WriteResources(formattedResourcesSchema, formattedResourcesModels, formattedResourcesModelObjectHelpers, formattedResourcesToFrom, outputPath)
if err != nil {
return fmt.Errorf("error writing Go code to output: %w", err)
}
Expand Down
Loading

0 comments on commit 61b856c

Please sign in to comment.