https://github.com/squat/terraform-provider-openapi-scaffolding
A Cookiecutter template for scaffolding new Terraform providers that are automatically generated from an OpenAPI specification
https://github.com/squat/terraform-provider-openapi-scaffolding
Last synced: 6 months ago
JSON representation
A Cookiecutter template for scaffolding new Terraform providers that are automatically generated from an OpenAPI specification
- Host: GitHub
- URL: https://github.com/squat/terraform-provider-openapi-scaffolding
- Owner: squat
- License: apache-2.0
- Created: 2023-11-13T18:12:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-12T06:27:05.000Z (over 1 year ago)
- Last Synced: 2025-02-08T16:44:34.173Z (over 1 year ago)
- Language: Makefile
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Terraform Provider OpenAPI Scaffolding
This is a [Cookiecutter](https://github.com/cookiecutter/cookiecutter) template for scaffolding new Terraform providers that are automatically generated from an OpenAPI specification.
[](https://github.com/squat/terraform-provider-openapi-scaffolding/actions?query=workflow%3ACI)
## Getting Started
In order to render a new provider from the template, `cookiecutter` must be installed.
Optionally, [`cruft`](https://github.com/cruft/cruft) can be installed to enable automatically updating the provider from the template.
Assuming, `cruft` is available, a new Terraform provider can be rendered with:
```sh
cruft create git@github.com:squat/terraform-provider-openapi-scaffolding.git << EOF
your_github_username
CloudProviderName
https://cloud.provider.website.example.com
https://cloud.provider.website.example.com/openapi-specification.yaml
EOF
```
Once the template has rendered, change into to the newly created directory:
```sh
cd terraform-provider-cloudprovidername
```
Next, edit the [OpenAPI Overlay](https://github.com/OAI/Overlay-Specification) `overlay.yaml` file to annotate the API operations with the necessary [Speakeasy tags](https://www.speakeasyapi.dev/docs/create-terraform#how-it-works-adding-annotations).
Finally, export the Speakeasy API key and generate the provider:
```sh
export SPEAKEASY_API_KEY=
make generate
```
That's it!
You now have a working Terraform provider.
## Testing
To test the newly generated provider, navigate to the root of the provider repository and run:
```sh
go run main.go --debug
```
This command will output a `TF_REATTACH_PROVIDERS` environment variable; copy it and navigate to a new directory containing Terraform configuration that leverages the provider.
Now, initialize and apply the Terraform configuration:
```sh
TF_REATTACH_PROVIDERS=... terraform init
TF_REATTACH_PROVIDERS=... terraform apply
```
## Publishing
The provider can now be tagged and pushed to a GitHub repository.
Releases are automated using GitHub actions: a new GitHub release will automatically be created for every Git tag that is found in the repository.
The following secrets must be set in the GitHub repository:
* `GPG_PRIVATE_KEY`;
* `PASSPHRASE`; and
* `SPEAKEASY_API_KEY`.
See the [Terraform providers documentation](https://developer.hashicorp.com/terraform/registry/providers/publishing) for instructions on generating a GPG key and passphrase and create a [Speakeasy](https://www.speakeasyapi.dev/) account in order to generate an API key.