Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jar-b/req2schema
Generate a terraform provider resource schema from an AWS request schema.
https://github.com/jar-b/req2schema
aws code-generation terraform terraform-provider
Last synced: 10 days ago
JSON representation
Generate a terraform provider resource schema from an AWS request schema.
- Host: GitHub
- URL: https://github.com/jar-b/req2schema
- Owner: jar-b
- License: mit
- Created: 2022-11-03T20:47:51.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T20:32:23.000Z (about 1 year ago)
- Last Synced: 2024-10-12T20:59:48.286Z (24 days ago)
- Topics: aws, code-generation, terraform, terraform-provider
- Language: Go
- Homepage:
- Size: 86.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# req2schema
[![build](https://github.com/jar-b/req2schema/actions/workflows/build.yml/badge.svg)](https://github.com/jar-b/req2schema/actions/workflows/build.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/jar-b/req2schema)](https://goreportcard.com/report/github.com/jar-b/req2schema)Generate a terraform provider resource [`Schema`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#Schema)
from an AWS request schema.This tool is intended to supplement the Terraform AWS provider's
[`skaff`](https://github.com/hashicorp/terraform-provider-aws/tree/main/skaff) tool,
focusing specifically on a resource's `Schema`. `skaff` does not use any external
data to generate its source files, and instead populates a
[placeholder `Schema`](https://github.com/hashicorp/terraform-provider-aws/blob/v4.38.0/skaff/resource/resource.tmpl#L119-L191).
`req2schema` uses AWS HTTP request schemas to provide a stubbed out terraform resource
schema with the appropriate key names and data types (including nested objects). This
can be helpful for large resources which are time consuming to write by hand.## Installation
```console
$ go install github.com/jar-b/req2schema@latest
```## Usage
```
Usage: req2schema [flags] [filename]Flags:
-out string
output file (optional, prints to stdout if omitted)
```### Examples
The following is an example of the AWS request schema syntax:
```
{
"thing": "string",
"second": number,
"another": boolean,
"nested": [
{
"value": "string"
}
]
}
````req2schema` will infer data types from the field values and generate go source code with a
terraform resource schema definition:```console
$ req2schema testdata/simple.json
``````go
package someserviceimport (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
)func ResourceSomeThing() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"another": {
Type: schema.TypeBool,
},
"nested": {
Type: schema.TypeList,
Elems: &schema.Resource{
Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeString,
},
},
},
},
"second": {
Type: schema.TypeFloat,
},
"thing": {
Type: schema.TypeString,
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
},
}
}```
The [`testdata`](testdata/) subfolder contains additional requests directly from the
AWS documentation.## Additional Considerations
- The resulting source code will be framed out, but incomplete.
- All items will need one of `Required`, `Optional`, or `Computed` set (this cannot be
inferred from the HTTP request schema alone).
- `enum` types will need validation added.
- If unable to determine the type from the incoming request, a `TODO` comment is added
after the type definition as a reminder to determine the appropriate type.
- Not all AWS services include JSON request schemas in the documentation. Some services
use XML examples, which this tool does not support.