You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: Adds initial schema and config models for PoC - Model generation (#2638)
* update computability type (#2668)
* chore: PoC - Model generation - support primitive types at root level (#2673)
* chore: PoC - Schema code generation - Initial support of primitive types (#2682)
* initial commit with schema generation function and test fixture
* small changes wip
* include specific type generators
* handling element types and imports
* remove unrelated file
* extract template logic to separate file
* small revert change
* extract import to const
* follow up adjustments from PR comments and sync with Aastha
* chore: PoC - Schema code generation - Supporting nested attributes (#2689)
* support nested attribute types
* rebasing changes related to unit testing adjustment
* chore: PoC - Model generation - Supporting nested schema (List, ListNested, Set & SetNested) (#2693)
* chore: PoC - Model generation - Supporting nested schema (objects - Map, MapNested, SingleNested Attributes) (#2704)
* chore: PoC - Schema code generation - Supporting generation of typed model (#2703)
* support typed model generation inlcuding root and nested attributes
* minor fix for type of types map
* add clarifying comment
* improve name of generated object types, refactor function naming for readability
* fix list map and set nested attribute generation (#2708)
* chore: PoC - Model generation - support config aliases, ignores, and description overrides (#2712)
* chore: PoC - Define make command to call code generation logic (#2706)
* wip
* iterating over all resources
* add config for search deployment
* update golden file test with fix in package name
* use xstring implementation for pascal case
* simplify write file logic
* merge fixes
* chore: PoC - Support configuration of timeout in schema (#2717)
* wip
* rebase fixes
* fix logic avoiding adding timeout in nested schemas
* fix generation
* fix enum processing
* fix golden file in timeout test
* comment out unsupported config properties
* simplify interfaces for attribute generation leaving common code in a separate function
* chore: PoC - handle merging computability in nested attributes (#2722)
* adjusting contributing guide (#2732)
---------
Co-authored-by: maastha <[email protected]>
Co-authored-by: Aastha Mahendru <[email protected]>
Copy file name to clipboardExpand all lines: GNUmakefile
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -118,11 +118,17 @@ scaffold:
118
118
@echo "Reminder: configure the new $(type) in provider.go"
119
119
120
120
# e.g. run: make scaffold-schemas resource_name=streamInstance
121
-
# details on usage can be found in contributing/development-best-practices.md under "Scaffolding Schema and Model Definitions"
121
+
# details on usage can be found in contributing/development-best-practices.md under "Generating Schema and Model Definitions - Using schema generation HashiCorp tooling"
122
122
.PHONY: scaffold-schemas
123
123
scaffold-schemas:
124
124
@scripts/schema-scaffold.sh $(resource_name)
125
125
126
+
# e.g. run: make generate-schema resource_name=search_deployment
127
+
# resource_name is optional, if not provided all configured resources will be generated
128
+
# details on usage can be found in contributing/development-best-practices.md under "Generating Schema and Model Definitions - Using internal tool"
129
+
.PHONY: generate-schema
130
+
generate-schema:
131
+
@go run ./tools/codegen/main.go $(resource_name)
126
132
127
133
.PHONY: generate-doc
128
134
# e.g. run: make generate-doc resource_name=search_deployment
Copy file name to clipboardExpand all lines: contributing/development-best-practices.md
+23-4Lines changed: 23 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
## Table of Contents
5
5
-[Creating New Resource and Data Sources](#creating-new-resources-and-data-sources)
6
6
-[Scaffolding Initial Code and File Structure](#scaffolding-initial-code-and-file-structure)
7
-
-[Scaffolding Schema and Model Definitions](#scaffolding-schema-and-model-definitions)
7
+
-[Generating Schema and Model Definitions](#scaffolding-schema-and-model-definitions)
8
8
9
9
- Each resource (and associated data sources) is in a package in `internal/service`.
10
10
- There can be multiple helper files and they can also be used from other resources, e.g. `common_advanced_cluster.go` defines functions that are also used from other resources using `advancedcluster.FunctionName`.
@@ -26,11 +26,30 @@ This will generate resource/data source files and accompanying test files needed
26
26
27
27
As a follow up step, use [Scaffolding Schema and Model Definitions](#scaffolding-schema-and-model-definitions) to autogenerate the schema via the Open API specification. This will require making adjustments to the generated `./internal/service/<resource_name>/tfplugingen/generator_config.yml` file.
28
28
29
-
#### Scaffolding Schema and Model Definitions
29
+
#### Generating Schema and Model Definitions
30
+
31
+
##### (Recommended) Using internal tool
32
+
33
+
The generation command makes use of a configuration file defined under [`./tools/codegen/config.yml`](../tools/codegen/config.yml). The structure of this configuration file can be found under [`./tools/codegen/config/config_model.go`](../tools/codegen/config/config_model.go).
34
+
35
+
The generation command takes a single optional argument `resource_name`. If not provided, all resources defined in the configuration are generated.
36
+
37
+
```bash
38
+
make generate-schema resource_name=search_deployment
39
+
```
40
+
41
+
As a result, content of schemas will be written into the corresponding resource packages:
**Note**: Data source schema generation is currently not supported.
45
+
46
+
47
+
##### (Legacy) Using schema generation HashiCorp tooling
48
+
30
49
31
50
Complementary to the `scaffold` command, there is a command which generates the initial Terraform schema definition and associated Go types for a resource or data source. This processes leverages [Code Generation Tools](https://developer.hashicorp.com/terraform/plugin/code-generation) developed by HashiCorp, which in turn make use of the [Atlas Admin API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/) OpenAPI Specification.
32
51
33
-
##### Running the command
52
+
######Running the command
34
53
35
54
Both `tfplugingen-openapi` and `tfplugingen-framework` must be installed. This can be done by running `make tools`.
36
55
@@ -49,7 +68,7 @@ Note: if the resulting file paths already exist the content will be stored in fi
49
68
50
69
Note: you can override the Open API description of a field with a custom description via the [overrides](https://developer.hashicorp.com/terraform/plugin/code-generation/openapi-generator#overriding-attribute-descriptions) param. See this [example](internal/service/searchdeployment/tfplugingen/generator_config.yml).
51
70
52
-
##### Considerations over generated schema and types
71
+
######Considerations over generated schema and types
53
72
54
73
- Generated Go type should include a TF prefix to follow the convention in our codebase, this will not be present in generated code.
55
74
- Some attribute names may need to be adjusted if there is a difference in how they are named in Terraform vs the API. An examples of this is `group_id` → `project_id`.
0 commit comments