From d8832910a0cb3cc719387b07caa788d573f6a24c Mon Sep 17 00:00:00 2001 From: Dzmitry Kishylau Date: Wed, 14 Aug 2024 12:46:34 -0700 Subject: [PATCH] [chore] Prepare the repo for publishing to the Terraform Registry (#28) --- .github/workflows/release.yaml | 41 +++++++++++++++++++++ .goreleaser.yml | 61 +++++++++++++++++++++++++++++++ CONTRIBUTING.md | 56 ++++++++++++++++++++++++++++ LICENSE | 21 +++++++++++ README.md | 63 ++++---------------------------- main.go | 2 - terraform-registry-manifest.json | 6 +++ 7 files changed, 192 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yml create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 terraform-registry-manifest.json diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..d38fd88 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,41 @@ +# Terraform Provider release workflow. +name: Release + +# This GitHub action creates a release when a tag that matches the pattern +# "v*" (e.g. v0.1.0) is created. +on: + push: + tags: + - 'v*' + +# Releases need permissions to read and write the repository contents. +# GitHub considers creating releases and uploading assets as writing contents. +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + # Allow goreleaser to access older tag information. + fetch-depth: 0 + - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 + with: + go-version-file: 'go.mod' + cache: true + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 + id: import_gpg + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.PASSPHRASE }} + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0 + with: + args: release --clean + env: + # GitHub sets the GITHUB_TOKEN secret automatically. + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..150ddfa --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,61 @@ +# Visit https://goreleaser.com for documentation on how to customize this +# behavior. +version: 2 +before: + hooks: + # this is just an example and not a requirement for provider building/publishing + - go mod tidy +builds: +- env: + # goreleaser does not work with CGO, it could also complicate + # usage by users in CI/CD systems like HCP Terraform where + # they are unable to install libraries. + - CGO_ENABLED=0 + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + goos: + - freebsd + - windows + - linux + - darwin + goarch: + - amd64 + - '386' + - arm + - arm64 + ignore: + - goos: darwin + goarch: '386' + binary: '{{ .ProjectName }}_v{{ .Version }}' +archives: +- format: zip + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' +checksum: + extra_files: + - glob: 'terraform-registry-manifest.json' + name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json' + name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' + algorithm: sha256 +signs: + - artifacts: checksum + args: + # if you are using this in a GitHub action or some other automated pipeline, you + # need to pass the batch flag to indicate its not interactive. + - "--batch" + - "--local-user" + - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key + - "--output" + - "${signature}" + - "--detach-sign" + - "${artifact}" +release: + extra_files: + - glob: 'terraform-registry-manifest.json' + name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json' + # If you want to manually examine the release before its live, uncomment this line: + # draft: true +changelog: + disable: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9735735 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,56 @@ +# Development +Install Go, make sure `GOPATH` variable is set and `$GOPATH/bin` is in the `PATH`. + +Follow the [instructions](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-provider#prepare-terraform-for-local-provider-install) to use local version of Retool provider. + +## Updating Retool API client library +The repository contains code-generated API client library for Retool API - see more details in [internal/sdk/README.md](/internal/sdk/README.md) + +# Testing +You can test the provider, resources and data sources against your local dev: +``` +cd examples/provider-initialization +RETOOL_HOST=localhost:3000 RETOOL_SCHEME=http RETOOL_ACCESS_TOKEN= terraform plan +``` + +To run unit tests, run the following command from the root folder: +``` +make test-unit +``` + +You can run specific tests by setting `FILTER` env var: +``` +FILTER=TestNewProvider make test-unit +``` + +To run acceptance tests, set `RETOOL_HOST`, `RETOOL_SCHEME` and `RETOOL_ACCESS_TOKEN` env vars, then run +``` +make test-acc +``` +Note that the acceptance tests will create, modify and delete resources in the Retool org. +You can run specific tests by setting `FILTER` env var as well. + +If acceptance tests fail and leave some undeleted resources on the Retool instance, you can delete them using "sweepers": +``` +make test-acc-sweep +``` + +## Recording and replaying HTTP requests for acceptance tests +It's hard to run acceptance tests on CI hitting a live Retool instance. Instead, we have a way to record and store HTTP responses during acceptance test run, then use canned responses to avoid hitting Retool instance. +Recorded responses are stored in `test/data/recordings/.yaml` files. + +To record responses for an acceptance test TestAccFoo: +- Delete `test/data/recordings/TestAccFoo.yaml` if it already exists +- Set `RETOOL_HOST`, `RETOOL_SCHEME` and `RETOOL_ACCESS_TOKEN` env vars to appropriate values for the Retool instance you're going to use. +- Run `FILTER=TestAccFoo make test-acc-record` . This will run the acceptance test and store HTTP responses. + +To run acceptance test using pre-recorded responses, do +``` +FILTER=TestAccFoo make test-acc-replay +``` + + +See `internal/acctest` for implementation details. The implementation was mostly copied from Auth0's Terraform provider: https://github.com/auth0/terraform-provider-auth0/tree/main/internal/acctest + +# Documentation +Run `go generate` in the root of this repository to generate provider docs. See https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-documentation-generation for more details on how to add new examples. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..78be994 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Retool + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 8ec811e..ffea898 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,9 @@ -# Retool Terraform Provider -Work in progress, more docs to come later - -The repository contains code-generated API client library for Retool API - see more details in [internal/sdk/README.md](/internal/sdk/README.md) - -## Development -Install Go, make sure `GOPATH` variable is set and `$GOPATH/bin` is in the `PATH`. - -Follow the [instructions](https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-provider#prepare-terraform-for-local-provider-install) to use local version of Retool provider. - -## Testing -You can test the provider, resources and data sources against your local dev: -``` -cd examples/provider-initialization -RETOOL_HOST=localhost:3000 RETOOL_SCHEME=http RETOOL_ACCESS_TOKEN= terraform plan -``` - -To run unit tests, run the following command from the root folder: -``` -make test-unit -``` - -You can run specific tests by setting `FILTER` env var: -``` -FILTER=TestNewProvider make test-unit -``` +

+ Retool logo
+ Build internal tools, remarkably fast. +


-To run acceptance tests, set `RETOOL_HOST`, `RETOOL_SCHEME` and `RETOOL_ACCESS_TOKEN` env vars, then run -``` -make test-acc -``` -Note that the acceptance tests will create, modify and delete resources in the Retool org. -You can run specific tests by setting `FILTER` env var as well. - -If acceptance tests fail and leave some undeleted resources on the Retool instance, you can delete them using "sweepers": -``` -make test-acc-sweep -``` - -### Recording and replaying HTTP requests for acceptance tests -It's hard to run acceptance tests on CI hitting a live Retool instance. Instead, we have a way to record and store HTTP responses during acceptance test run, then use canned responses to avoid hitting Retool instance. -Recorded responses are stored in `test/data/recordings/.yaml` files. - -To record responses for an acceptance test TestAccFoo: -- Delete `test/data/recordings/TestAccFoo.yaml` if it already exists -- Set `RETOOL_HOST`, `RETOOL_SCHEME` and `RETOOL_ACCESS_TOKEN` env vars to appropriate values for the Retool instance you're going to use. -- Run `FILTER=TestAccFoo make test-acc-record` . This will run the acceptance test and store HTTP responses. - -To run acceptance test using pre-recorded responses, do -``` -FILTER=TestAccFoo make test-acc-replay -``` - - -See `internal/acctest` for implementation details. The implementation was mostly copied from Auth0's Terraform provider: https://github.com/auth0/terraform-provider-auth0/tree/main/internal/acctest +# Retool Terraform Provider +Official plugin for managing Retool configuration via [Terraform](https://www.terraform.io/). -## Documentation -Run `go generate` in the root of this repository to generate provider docs. See https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework/providers-plugin-framework-documentation-generation for more details on how to add new examples. +TODO: add links to Terraform Registry, provider docs and "getting started" section. diff --git a/main.go b/main.go index f57bc60..cd19989 100644 --- a/main.go +++ b/main.go @@ -38,8 +38,6 @@ func main() { opts := providerserver.ServeOpts{ // TODO(dzmitry.kishylau): Update this string with the published name of Retool provider. - // Also update the tfplugindocs generate command to either remove the - // -provider-name flag or set its value to the updated provider name. Address: "registry.terraform.io/retool/retool", Debug: debug, } diff --git a/terraform-registry-manifest.json b/terraform-registry-manifest.json new file mode 100644 index 0000000..39fe9b8 --- /dev/null +++ b/terraform-registry-manifest.json @@ -0,0 +1,6 @@ +{ + "version": 1, + "metadata": { + "protocol_versions": ["5.0"] + } +}