From fff9b1cee4b1aaac7e87ce3358dd57d73a80c982 Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Wed, 25 May 2022 11:18:26 +0100 Subject: [PATCH] Utility Providers Upgrade (#136) * Update to Go 1.17 (#135) * Test all Terraform minor versions >=0.12 (#135) * Switch to using TestCheckFunc and ProviderFactories (#135) * Adding golangci-lint.yml and updating GNUmakefile and test.yml (#135) * Fix linting issues (#135) * Use terraform-plugin-docs (#135) * Adding DESIGN.md (#135) * Updating README.md (#135) * Updating CHANGELOG.md (#135) * Updating SUPPORT.md (#135) * Using TestCheck helper funcs and removing outputs from tests (#135) * Reinstating RFC link in response_headers doc (#135) * Update DESIGN.md to include relevant information and links on supported HTTP and TLS protocol versions (#135) * Suppress max issues per linter and max same issues for golangci-lint (#135) * Rewording DESIGN.md (#135) --- .github/CONTRIBUTING.md | 140 +++++++++++----- .github/SUPPORT.md | 7 +- .github/workflows/test.yml | 89 +++++----- .go-version | 2 +- .golangci.yml | 21 +++ DESIGN.md | 48 ++++++ GNUmakefile | 49 ++---- README.md | 125 ++++++++------ docs/data-sources/http.md | 44 +++-- docs/index.md | 4 +- examples/data-sources/http/data-source.tf | 10 ++ go.mod | 28 +++- go.sum | 47 +++++- internal/provider/data_source.go | 39 ++++- internal/provider/data_source_test.go | 193 +++++++--------------- internal/provider/provider_test.go | 7 +- main.go | 5 + scripts/errcheck.sh | 24 --- scripts/gofmtcheck.sh | 13 -- templates/index.md.tmpl | 15 ++ tools/tools.go | 9 + 21 files changed, 544 insertions(+), 375 deletions(-) create mode 100644 .golangci.yml create mode 100644 DESIGN.md create mode 100644 examples/data-sources/http/data-source.tf delete mode 100755 scripts/errcheck.sh delete mode 100755 scripts/gofmtcheck.sh create mode 100644 templates/index.md.tmpl create mode 100644 tools/tools.go diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 08dcd41c..9e5ab4ea 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,71 +1,129 @@ -# Contributing to `terraform-provider-http` +# Contributing -**First:** if you're unsure or afraid of _anything_, just ask or submit the issue describing the problem you're aiming to solve. +Thank you for investing your time and energy by contributing to our project: please ensure you are familiar +with the [HashiCorp Code of Conduct](https://github.com/hashicorp/.github/blob/master/CODE_OF_CONDUCT.md). -The `http` provider is a HashiCorp *standard library* provider, which means we consider it part of the core Terraform experience. Our priority is stability and correctness, and any bug fix or feature has to be considered in the context of this provider's many users and the wider Terraform ecosystem. -This is great as your contribution can have a big positive impact, but we have to assess potential negative impact too. +This provider is a HashiCorp **utility provider**, which means any bug fix and feature +has to be considered in the context of the thousands/millions of configurations in which this provider is used. +This is great as your contribution can have a big positive impact, but we have to assess potential negative impact too +(e.g. breaking existing configurations). _Stability over features_. -To provide some safety to the Terraform ecosystem, we strictly follow [semantic versioning](https://semver.org/) and any changes that could be considered as breaking will only be released as part of a major release. +To provide some safety to the wider provider ecosystem, we strictly follow +[semantic versioning](https://semver.org/) and HashiCorp's own +[versioning specification](https://www.terraform.io/plugin/sdkv2/best-practices/versioning#versioning-specification). +Any changes that could be considered as breaking will only be included as part of a major release. +In case multiple breaking changes need to happen, we will group them in the next upcoming major release. -## Table of Contents +## Asking Questions - - [I just have a question](#i-just-have-a-question) - - [I want to report a vulnerability](#i-want-to-report-a-vulnerability) - - [New Issue](#new-issue) - - [New Pull Request](#new-pull-request) +For questions, curiosity, or if still unsure what you are dealing with, +please see the HashiCorp [Terraform Providers Discuss](https://discuss.hashicorp.com/c/terraform-providers/31) +forum. -## I just have a question +## Reporting Vulnerabilities -> **Note:** We use GitHub for tracking bugs and feature requests only. +Please disclose security vulnerabilities responsibly by following the +[HashiCorp Vulnerability Reporting guidelines](https://www.hashicorp.com/security#vulnerability-reporting). -For questions, please see relevant channels at https://www.terraform.io/community.html +## Understanding the design -## I want to report a vulnerability +Before proceeding with raising issues or submitting pull requests, it will probably help to familiarise yourself with +the [design principles](../DESIGN.md) of this provider. This will aid your proposals, and help understand +why we took certain decisions during development. -Please disclose security vulnerabilities responsibly by following the procedure -described at https://www.hashicorp.com/security#vulnerability-reporting +## Raising Issues -## New Issue - -We welcome issues of all kinds including feature requests, bug reports or documentation suggestions. Below are guidelines for well-formed issues of each type. +We welcome issues of all kinds including feature requests, bug reports or documentation suggestions. +Below are guidelines for well-formed issues of each type. ### Bug Reports - - **Test against latest release**: Make sure you test against the latest avaiable version of both Terraform and the provider. -It is possible we already fixed the bug you're experiencing. - - - **Search for duplicates**: It's helpful to keep bug reports consolidated to one thread, so do a quick search on existing bug reports to check if anybody else has reported the same thing. You can scope searches by the label `bug` to help narrow things down. - - - **Include steps to reproduce**: Provide steps to reproduce the issue, along with code examples (both HCL and Go, where applicable) and/or real code, so we can try to reproduce it. Without this, it makes it much harder (sometimes impossible) to fix the issue. +* [ ] **Test against latest release**: Make sure you test against the latest available version of Terraform and the provider. + It is possible we may have already fixed the bug you're experiencing. +* [ ] **Search for duplicates**: It's helpful to keep bug reports consolidated to one thread, so do a quick search + on existing bug reports to check if anybody else has reported the same thing. + You can scope searches by the label `bug` to help narrow things down. +* [ ] **Include steps to reproduce**: Provide steps to reproduce the issue, along with code examples and/or real code, + so we can try to reproduce it. Without this, it makes it much harder (sometimes impossible) to fix the issue. ### Feature Requests - - **Search for possible duplicate requests**: It's helpful to keep requests consolidated to one thread, so do a quick search on existing requests to check if anybody else has reported the same thing. You can scope searches by the label `enhancement` to help narrow things down. - - - **Include a use case description**: In addition to describing the behavior of the feature you'd like to see added, it's helpful to also lay out the reason why the feature would be important and how it would benefit the wider Terraform ecosystem. Use case in context of 1 provider is good, wider context of more providers is better. +* [ ] **Search for possible duplicate requests**: It's helpful to keep requests consolidated to one thread, + so do a quick search on existing requests to check if anybody else has reported the same thing. + You can scope searches by the label `enhancement` to help narrow things down. +* [ ] **Include a use case description**: In addition to describing the behavior of the feature you'd like to see added, + it's helpful to also make a case for why the feature would be important and how it would benefit + the provider and, potentially, the wider Terraform ecosystem. ## New Pull Request Thank you for contributing! -We are happy to review pull requests without associated issues, but we highly recommend starting by describing and discussing your problem or feature and attaching use cases to an issue first before raising a pull request. +We are happy to review pull requests without associated issues, +but we **highly recommend** starting by describing and discussing +your problem or feature and attaching use cases to an issue first +before raising a pull request. + +* [ ] **Early validation of idea and implementation plan**: provider development is complicated enough that there + are often several ways to implement something, each of which has different implications and tradeoffs. + Working through a plan of attack with the team before you dive into implementation will help ensure that you're + working in the right direction. +* [ ] **Tests**: It may go without saying, but every new patch should be covered by tests wherever possible. + For bug-fixes, tests to prove the fix is valid. For features, tests to exercise the new code paths. +* [ ] **Go Modules**: We use [Go Modules](https://github.com/golang/go/wiki/Modules) to manage and version our dependencies. + Please make sure that you reflect dependency changes in your pull requests appropriately + (e.g. `go get`, `go mod tidy` or other commands). + Refer to the [dependency updates](#dependency-updates) section for more information about how + this project maintains existing dependencies. +* [ ] **Changelog**: Refer to the [changelog](#changelog) section for more information about how to create changelog entries. + +### Dependency Updates + +Dependency management is performed by [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates). +Where possible, dependency updates should occur through that system to ensure all Go module files are appropriately +updated and to prevent duplicated effort of concurrent update submissions. +Once available, updates are expected to be verified and merged to prevent latent technical debt. + +### Changelog + +HashiCorp’s open-source projects have always maintained user-friendly, readable `CHANGELOG`s that allow +practitioners and developers to tell at a glance whether a release should have any effect on them, +and to gauge the risk of an upgrade. + +We follow Terraform Plugin +[changelog specifications](https://www.terraform.io/plugin/sdkv2/best-practices/versioning#changelog-specification). + +#### Entry format + +Entries that are specific to _resources_ or _data sources_, they should look like: + +```markdown +* resource/RESOURCE_NAME: ENTRY DESCRIPTION ([#PR_NUMBER](PR_URL)). + +* data-source/DATA-SOURCE_NAME: ENTRY DESCRIPTION ([#PR_NUMBER](PR_URL)). +``` -- **Early validation of idea and implementation plan**: Terraform's SDK is complicated enough that there are often several ways to implement something, each of which has different implications and tradeoffs. Working through a plan of attack with the team before you dive into implementation will help ensure that you're working in the right direction. +#### Which changes should appear in the `CHANGELOG`? -- **Acceptance Tests**: It may go without saying, but every new patch should be covered by tests wherever possible. +The `CHANGELOG` is intended to show developer-impacting changes to the codebase for a particular version. +If every change or commit to the code resulted in an entry, the `CHANGELOG` would become less useful for developers. +The lists below are general guidelines to decide whether a change should have an entry. -- **Go Modules**: We use [Go Modules](https://github.com/golang/go/wiki/Modules) to manage and version all our dependencies. Please make sure that you reflect dependency changes in your pull requests appropriately (e.g. `go get`, `go mod tidy` or other commands). Where possible it is better to raise a separate pull request with just dependency changes as it's easier to review such PR(s). +##### Changes that _should not_ have a `CHANGELOG` entry -### Cosmetic changes, code formatting, and typos +* Documentation updates +* Testing updates +* Code refactoring -In general we do not accept PRs containing only the following changes: +##### Changes that _may_ have a `CHANGELOG` entry - - Correcting spelling or typos - - Code formatting, including whitespace - - Other cosmetic changes that do not affect functionality - -While we appreciate the effort that goes into preparing PRs, there is always a tradeoff between benefit and cost. The costs involved in accepting such contributions include the time taken for thorough review, the noise created in the git history, and the increased number of GitHub notifications that maintainers must attend to. +* Dependency updates: If the update contains relevant bug fixes or enhancements that affect developers, + those should be called out. -#### Exceptions +##### Changes that _should_ have a `CHANGELOG` entry -We belive that one should "leave the campsite cleaner than you found it", so you are welcome to clean up cosmetic issues in the neighbourhood when submitting a patch that makes functional changes or fixes. +* Major features +* Bug fixes +* Enhancements +* Deprecations +* Breaking changes and removals diff --git a/.github/SUPPORT.md b/.github/SUPPORT.md index 1d41099a..7adc20e6 100644 --- a/.github/SUPPORT.md +++ b/.github/SUPPORT.md @@ -1,5 +1,6 @@ # Support -Terraform is a mature project with a growing community. There are active, dedicated people willing to help you through various mediums. - -Take a look at those mediums listed at https://www.terraform.io/community.html +* Project [README](../README.md). +* Official [Documentation](https://registry.terraform.io/providers/hashicorp/http/latest/docs). +* Provider [Discussion forums](https://discuss.hashicorp.com/c/terraform-providers/31). +* Terraform [Community](https://www.terraform.io/community.html). diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0444ff5f..6282e995 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,5 @@ -name: Tests +name: Test + on: pull_request: branches: [ main ] @@ -12,6 +13,7 @@ on: - 'README.md' - 'CHANGELOG.md' - 'website/*' + jobs: build: name: Build @@ -19,59 +21,66 @@ jobs: timeout-minutes: 5 steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.17' - id: go + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.17' + id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + - name: Check out code into the Go module directory + uses: actions/checkout@v3 - - name: Go fmt - run: | - make fmt + - name: Run linters + uses: golangci/golangci-lint-action@v3 + with: + version: latest - - name: Go vet - run: | - make vet + - name: Generate + run: make generate - - name: Build - run: | - go build -v . + - name: Confirm no diff + run: | + git diff --compact-summary --exit-code || \ + (echo "*** Unexpected differences after code generation. Run 'make generate' and commit."; exit 1) + - name: Build + run: make build -# run acceptance tests in a matrix with Terraform core versions test: - name: Matrix Test + name: 'Acc. Tests (OS: ${{ matrix.os }} / TF: ${{ matrix.terraform }})' needs: build - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} timeout-minutes: 15 strategy: fail-fast: false matrix: + os: + - macos-latest + - windows-latest + - ubuntu-latest terraform: - - '0.12.31' - - '0.13.7' - - '0.14.11' - - '0.15.5' - - '1.0.1' - + - '0.12.*' + - '0.13.*' + - '0.14.*' + - '0.15.*' + - '1.0.*' + - '1.1.*' steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.17' - id: go + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.17' + check-latest: true + + - name: Check out code + uses: actions/checkout@v3 - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + - name: Setup Terraform ${{ matrix.terraform }} + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: ${{ matrix.terraform }} + terraform_wrapper: false - - name: TF acceptance tests - timeout-minutes: 10 - env: - TF_ACC: "1" - TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }} - run: | - go test -v -cover ./internal/provider/ + - name: Run acceptance test + run: make testacc diff --git a/.go-version b/.go-version index a23a1564..ada2e4fc 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.17.8 +1.17.10 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..9e785d9e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,21 @@ +linters: + # Default linters enabled + # See: https://golangci-lint.run/usage/linters/#enabled-by-default-linters + + # Additional linters enabled + enable: + - durationcheck + - exportloopref + - godot + - gofmt + - makezero + - misspell + - nilerr + - predeclared + - tenv + - unconvert + - unparam + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/DESIGN.md b/DESIGN.md new file mode 100644 index 00000000..a241ceb6 --- /dev/null +++ b/DESIGN.md @@ -0,0 +1,48 @@ +# HTTP Provider Design + +The HTTP Provider offers functionality for interacting with generic HTTP servers as part of terraform configuration. +Specifically, the provider issues an HTTP GET request to the defined URL on every Terraform run. + +Below we have a collection of _Goals_ and _Patterns_: they represent the guiding principles applied during the +development of this provider. Some are in place, others are ongoing processes, others are still just inspirational. + +## Goals + +* [_Stability over features_](.github/CONTRIBUTING.md) +* Provide managed data source to issue HTTP GET request. The underlying default +[transport](https://pkg.go.dev/net/http#Transport) uses [HTTP/1.1](https://datatracker.ietf.org/doc/html/rfc2616) for +HTTP URLs and either [HTTP/1.1](https://datatracker.ietf.org/doc/html/rfc2616) or +[HTTP/2.0](https://datatracker.ietf.org/doc/html/rfc7540) for HTTPS URLs depending on whether the server supports +[HTTP/2.0](https://datatracker.ietf.org/doc/html/rfc7540). Non-standard protocols (e.g., +[SPDY](https://tools.ietf.org/id/draft-ietf-httpbis-http2-00.html), +[QUIC](https://datatracker.ietf.org/doc/html/draft-ietf-quic-transport-34)) are not supported. +* Support usage of either `http` (plaintext) or `https` (secure) requests. The current version of this provider is +built with [Go 1.17](https://go.dev/doc/go1.17) which [supports](https://go.dev/doc/go1.17#minor_library_changes) +[TLS/1.0](https://www.ietf.org/rfc/rfc2246.txt) ([deprecated](https://datatracker.ietf.org/doc/rfc8996/)), +[TLS/1.1](https://datatracker.ietf.org/doc/html/rfc4346) ([deprecated](https://datatracker.ietf.org/doc/rfc8996/)), +[TLS/1.2](https://datatracker.ietf.org/doc/html/rfc5246) and +[TLS/1.3](https://datatracker.ietf.org/doc/html/rfc8446). TLS support will track the version of Go that the provider +is built with and will likely change over time. +* Support the supplying of request headers. +* Expose response headers returned from request. +* Expose response body as string where applicable. + +## Patterns + +Specific to this provider: + +* Only idempotent GET requests are supported. +* Only 200 status codes are considered successful. + +General to development: + +* **Avoid repetition**: the entities managed can sometimes require similar pieces of logic and/or schema to be realised. + When this happens it's important to keep the code shared in communal sections, so to avoid having to modify code in + multiple places when they start changing. +* **Test expectations as well as bugs**: While it's typical to write tests to exercise a new functionality, it's key to + also provide tests for issues that get identified and fixed, so to prove resolution as well as avoid regression. +* **Automate boring tasks**: Processes that are manual, repetitive and can be automated, should be. In addition to be a + time-saving practice, this ensures consistency and reduces human error (ex. static code analysis). +* **Semantic versioning**: Adhering to HashiCorp's own + [Versioning Specification](https://www.terraform.io/plugin/sdkv2/best-practices/versioning#versioning-specification) + ensures we provide a consistent practitioner experience, and a clear process to deprecation and decommission. diff --git a/GNUmakefile b/GNUmakefile index 455a8eed..70a92d1d 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,44 +1,25 @@ -TEST?=$$(go list ./...) -GOFMT_FILES?=$$(find . -name '*.go') -PKG_NAME=http - default: build -build: fmtcheck - go install +build: + go build -v ./... -test: fmtcheck - go test -i $(TEST) || exit 1 - echo $(TEST) | \ - xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4 +install: build + go install -v ./... -testacc: fmtcheck - TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m +# See https://golangci-lint.run/ +lint: + golangci-lint run -vet: - @echo "go vet ." - @go vet $$(go list ./...) ; if [ $$? -eq 1 ]; then \ - echo ""; \ - echo "Vet found suspicious constructs. Please check the reported constructs"; \ - echo "and fix them if necessary before submitting the code for review."; \ - exit 1; \ - fi +generate: + go generate ./... fmt: - gofmt -w $(GOFMT_FILES) - -fmtcheck: - @sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'" + gofmt -s -w -e . -errcheck: - @sh -c "'$(CURDIR)/scripts/errcheck.sh'" +test: + go test -v -cover -timeout=120s -parallel=4 ./... -test-compile: - @if [ "$(TEST)" = "./..." ]; then \ - echo "ERROR: Set TEST to a specific package. For example,"; \ - echo " make test-compile TEST=./$(PKG_NAME)"; \ - exit 1; \ - fi - go test -c $(TEST) $(TESTARGS) +testacc: + TF_ACC=1 go test -v -cover -timeout 120m ./... -.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile +.PHONY: build install lint generate fmt test testacc diff --git a/README.md b/README.md index df6b1019..a9545895 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,101 @@ -Terraform Provider -================== +# Terraform Provider: HTTP -- Website: https://www.terraform.io -- [![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby) -- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool) +The HTTP provider interacts with generic HTTP servers. +It provides a data source that issues an HTTP request exposing the response headers and body +for use within a Terraform deployment. - +## Documentation, questions and discussions -Maintainers ------------ +Official documentation on how to use this provider can be found on the +[Terraform Registry](https://registry.terraform.io/providers/hashicorp/http/latest/docs). +In case of specific questions or discussions, please use the +HashiCorp [Terraform Providers Discuss forums](https://discuss.hashicorp.com/c/terraform-providers/31), +in accordance with HashiCorp [Community Guidelines](https://www.hashicorp.com/community-guidelines). -This provider plugin is maintained by the Terraform team at [HashiCorp](https://www.hashicorp.com/). +We also provide: -Requirements ------------- +* [Support](.github/SUPPORT.md) page for help when using the provider +* [Contributing](.github/CONTRIBUTING.md) guidelines in case you want to help this project +* [Design](DESIGN.md) documentation to understand the scope and maintenance decisions -- [Terraform](https://www.terraform.io/downloads.html) 0.12.x -- [Go](https://golang.org/doc/install) 1.17 (to build the provider plugin) +The remainder of this document will focus on the development aspects of the provider. -Building The Provider ---------------------- +## Requirements -Clone repository to: `$GOPATH/src/github.com/terraform-providers/terraform-provider-http` +* [Terraform](https://www.terraform.io/downloads) (>= 0.12) +* [Go](https://go.dev/doc/install) (1.17) +* [GNU Make](https://www.gnu.org/software/make/) +* [golangci-lint](https://golangci-lint.run/usage/install/#local-installation) (optional) -```sh -$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers -$ git clone git@github.com:terraform-providers/terraform-provider-http -``` +## Development -Enter the provider directory and build the provider +### Building -```sh -$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-http -$ make build -``` +1. `git clone` this repository and `cd` into its directory +2. `make` will trigger the Golang build -Using the provider ----------------------- -see +The provided `GNUmakefile` defines additional commands generally useful during development, +like for running tests, generating documentation, code formatting and linting. +Taking a look at it's content is recommended. -Developing the Provider ---------------------------- +### Testing -If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.17+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. +In order to test the provider, you can run -To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. +* `make test` to run provider tests +* `make testacc` to run provider acceptance tests -```sh -$ make bin -... -$ $GOPATH/bin/terraform-provider-http -... -``` +It's important to note that acceptance tests (`testacc`) will actually spawn +`terraform` and the provider. Read more about they work on the +[official page](https://www.terraform.io/plugin/sdkv2/testing/acceptance-tests). -In order to test the provider, you can simply run `make test`. +### Generating documentation -```sh -$ make test -``` +This provider uses [terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs/) +to generate documentation and store it in the `docs/` directory. +Once a release is cut, the Terraform Registry will download the documentation from `docs/` +and associate it with the release version. Read more about how this works on the +[official page](https://www.terraform.io/registry/providers/docs). + +Use `make generate` to ensure the documentation is regenerated with any changes. + +### Using a development build + +If [running tests and acceptance tests](#testing) isn't enough, it's possible to set up a local terraform configuration +to use a development builds of the provider. This can be achieved by leveraging the Terraform CLI +[configuration file development overrides](https://www.terraform.io/cli/config/config-file#development-overrides-for-provider-developers). + +First, use `make install` to place a fresh development build of the provider in your +[`${GOBIN}`](https://pkg.go.dev/cmd/go#hdr-Compile_and_install_packages_and_dependencies) +(defaults to `${GOPATH}/bin` or `${HOME}/go/bin` if `${GOPATH}` is not set). Repeat +this every time you make changes to the provider locally. -In order to run the full suite of Acceptance tests, run `make testacc`. +Then, setup your environment following [these instructions](https://www.terraform.io/plugin/debugging#terraform-cli-development-overrides) +to make your local terraform use your local build. -*Note:* Acceptance tests create real resources, and often cost money to run. +### Testing GitHub Actions -```sh -$ make testacc +This project uses [GitHub Actions](https://docs.github.com/en/actions/automating-builds-and-tests) to realize its CI. + +Sometimes it might be helpful to locally reproduce the behaviour of those actions, +and for this we use [act](https://github.com/nektos/act). Once installed, you can _simulate_ the actions executed +when opening a PR with: + +```shell +# List of workflows for the 'pull_request' action +$ act -l pull_request + +# Execute the workflows associated with the `pull_request' action +$ act pull_request ``` + +## Releasing + +The release process is automated via GitHub Actions, and it's defined in the Workflow +[release.yml](./.github/workflows/release.yml). + +Each release is cut by pushing a [semantically versioned](https://semver.org/) tag to the default branch. + +## License + +[Mozilla Public License v2.0](./LICENSE) diff --git a/docs/data-sources/http.md b/docs/data-sources/http.md index fc697339..368af5e2 100644 --- a/docs/data-sources/http.md +++ b/docs/data-sources/http.md @@ -1,10 +1,21 @@ --- -page_title: "HTTP Data Source" +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "http Data Source - terraform-provider-http" +subcategory: "" description: |- - Retrieves the content at an HTTP or HTTPS URL. + The http data source makes an HTTP GET request to the given URL and exports + information about the response. + The given URL may be either an http or https URL. At present this resource + can only retrieve data from URLs that respond with text/* or + application/json content types, and expects the result to be UTF-8 encoded + regardless of the returned content type header. + ~> Important Although https URLs can be used, there is currently no + mechanism to authenticate the remote server except for general verification of + the server certificate's chain of trust. Data retrieved from servers not under + your control should be treated as untrustworthy. --- -# `http` Data Source +# http (Data Source) The `http` data source makes an HTTP GET request to the given URL and exports information about the response. @@ -21,7 +32,9 @@ your control should be treated as untrustworthy. ## Example Usage -```hcl +```terraform +# The following example shows how to issue an HTTP GET request supplying +# an optional request header. data "http" "example" { url = "https://checkpoint-api.hashicorp.com/v1/check/terraform" @@ -32,22 +45,21 @@ data "http" "example" { } ``` -## Argument Reference + +## Schema -The following arguments are supported: +### Required -* `url` - (Required) The URL to request data from. This URL must respond with - a `200 OK` response and a `text/*` or `application/json` Content-Type. +- `url` (String) The URL for the request. Supported schemes are `http` and `https`. -* `request_headers` - (Optional) A map of strings representing additional HTTP - headers to include in the request. +### Optional -## Attributes Reference +- `request_headers` (Map of String) A map of request header field names and values. -The following attributes are exported: +### Read-Only + +- `body` (String) The response body returned as a string. +- `id` (String) The ID of this resource. +- `response_headers` (Map of String) A map of response header field names and values. Duplicate headers are concatenated with according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2). -* `body` - The raw body of the HTTP response. -* `response_headers` - A map of strings representing the response HTTP headers. - Duplicate headers are contatenated with `, ` according to - [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2) diff --git a/docs/index.md b/docs/index.md index a02b6734..50774f1f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,5 @@ --- -page_title: "HTTP Provider" +page_title: "Provider: HTTP" description: |- The HTTP provider interacts with HTTP servers. --- @@ -10,4 +10,4 @@ The HTTP provider is a utility provider for interacting with generic HTTP servers as part of a Terraform configuration. This provider requires no configuration. For information on the resources -it provides, see the navigation bar. +it provides, see the navigation bar. \ No newline at end of file diff --git a/examples/data-sources/http/data-source.tf b/examples/data-sources/http/data-source.tf new file mode 100644 index 00000000..9a89f235 --- /dev/null +++ b/examples/data-sources/http/data-source.tf @@ -0,0 +1,10 @@ +# The following example shows how to issue an HTTP GET request supplying +# an optional request header. +data "http" "example" { + url = "https://checkpoint-api.hashicorp.com/v1/check/terraform" + + # Optional request headers + request_headers = { + Accept = "application/json" + } +} diff --git a/go.mod b/go.mod index e85efb7c..32362b3f 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,25 @@ module github.com/terraform-providers/terraform-provider-http -require github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0 +go 1.17 + +require ( + github.com/hashicorp/terraform-plugin-docs v0.8.1 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.16.0 +) require ( + github.com/Masterminds/goutils v1.1.0 // indirect + github.com/Masterminds/semver/v3 v3.1.1 // indirect + github.com/Masterminds/sprig/v3 v3.2.0 // indirect github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 // indirect + github.com/bgentry/speakeasy v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.7.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.8 // indirect + github.com/google/uuid v1.1.2 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -28,26 +39,31 @@ require ( github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect - github.com/mattn/go-colorable v0.1.4 // indirect - github.com/mattn/go-isatty v0.0.10 // indirect + github.com/huandu/xstrings v1.3.2 // indirect + github.com/imdario/mergo v0.3.12 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/cli v1.1.3 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.0.0 // indirect + github.com/posener/complete v1.1.1 // indirect + github.com/russross/blackfriday v1.6.0 // indirect + github.com/shopspring/decimal v1.2.0 // indirect + github.com/spf13/cast v1.3.1 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect github.com/vmihailenco/tagparser v0.1.1 // indirect github.com/zclconf/go-cty v1.10.0 // indirect golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect - golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect + golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect golang.org/x/text v0.3.5 // indirect google.golang.org/appengine v1.6.6 // indirect google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect google.golang.org/grpc v1.45.0 // indirect google.golang.org/protobuf v1.28.0 // indirect ) - -go 1.17 diff --git a/go.sum b/go.sum index 5ab442ae..5393c790 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,12 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= +github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/sprig/v3 v3.2.0 h1:P1ekkbuU73Ui/wS0nK1HOM37hh4xdfZo485UPf8rc+Y= +github.com/Masterminds/sprig/v3 v3.2.0/go.mod h1:tWhwTbUTndesPNeF0C900vKoq283u6zp4APT9vaF3SI= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= @@ -22,7 +28,11 @@ github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -88,6 +98,8 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= @@ -103,6 +115,7 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBM github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v6UZM= @@ -125,6 +138,8 @@ github.com/hashicorp/terraform-exec v0.16.1 h1:NAwZFJW2L2SaCBVZoVaH8LPImLOGbPLkS github.com/hashicorp/terraform-exec v0.16.1/go.mod h1:aj0lVshy8l+MHhFNoijNHtqTJQI3Xlowv5EOsEaGO7M= github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY= github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk= +github.com/hashicorp/terraform-plugin-docs v0.8.1 h1:XJC/cDvmE7zJfDFCtOI1bURaencBQC0xYx3DZ5cWbhE= +github.com/hashicorp/terraform-plugin-docs v0.8.1/go.mod h1:p40z/69HYNUN/G2RDYp8XUCA5B1VzGTZl7/N9V+BWXU= github.com/hashicorp/terraform-plugin-go v0.9.0 h1:FvLY/3z4SNVatPZdoFcyrlNbCar+WyyOTv5X4Tp+WZc= github.com/hashicorp/terraform-plugin-go v0.9.0/go.mod h1:EawBkgjBWNf7jiKnVoyDyF39OSV+u6KUX+Y73EPj3oM= github.com/hashicorp/terraform-plugin-log v0.3.0/go.mod h1:EjueSP/HjlyFAsDqt+okpCPjkT4NDynAe32AeDC4vps= @@ -139,6 +154,10 @@ github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= +github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= @@ -160,11 +179,18 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LE github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mitchellh/cli v1.1.3 h1:xrX6lWnp1wgXZ65TGY2SB5URdQYcXu6VILdxDf5NttQ= +github.com/mitchellh/cli v1.1.3/go.mod h1:vTLESy5mRhKOs9KDp0/RATawxP1UqBmdrpVRMnpcvKQ= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -177,6 +203,7 @@ github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9 github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -188,14 +215,22 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= +github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -203,6 +238,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -227,7 +263,9 @@ golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= @@ -278,8 +316,10 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -346,6 +386,7 @@ gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRN gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/provider/data_source.go b/internal/provider/data_source.go index a1c43ff1..c11e54b9 100644 --- a/internal/provider/data_source.go +++ b/internal/provider/data_source.go @@ -15,34 +15,52 @@ import ( func dataSource() *schema.Resource { return &schema.Resource{ + Description: ` +The ` + "`http`" + ` data source makes an HTTP GET request to the given URL and exports +information about the response. + +The given URL may be either an ` + "`http`" + ` or ` + "`https`" + ` URL. At present this resource +can only retrieve data from URLs that respond with ` + "`text/*`" + ` or +` + "`application/json`" + ` content types, and expects the result to be UTF-8 encoded +regardless of the returned content type header. + +~> **Important** Although ` + "`https`" + ` URLs can be used, there is currently no +mechanism to authenticate the remote server except for general verification of +the server certificate's chain of trust. Data retrieved from servers not under +your control should be treated as untrustworthy.`, ReadContext: dataSourceRead, Schema: map[string]*schema.Schema{ "url": { - Type: schema.TypeString, - Required: true, + Description: "The URL for the request. Supported schemes are `http` and `https`.", + Type: schema.TypeString, + Required: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, "request_headers": { - Type: schema.TypeMap, - Optional: true, + Description: "A map of request header field names and values.", + Type: schema.TypeMap, + Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, "body": { - Type: schema.TypeString, - Computed: true, + Description: "The response body returned as a string.", + Type: schema.TypeString, + Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, "response_headers": { + Description: `A map of response header field names and values.` + + ` Duplicate headers are concatenated with according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).`, Type: schema.TypeMap, Computed: true, Elem: &schema.Schema{ @@ -80,7 +98,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{ } contentType := resp.Header.Get("Content-Type") - if contentType == "" || isContentTypeText(contentType) == false { + if !isContentTypeText(contentType) { diags = append(diags, diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf("Content-Type is not recognized as a text type, got %q", contentType), @@ -100,7 +118,10 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{ responseHeaders[k] = strings.Join(v, ", ") } - d.Set("body", string(bytes)) + if err = d.Set("body", string(bytes)); err != nil { + return append(diags, diag.Errorf("Error setting HTTP response body: %s", err)...) + } + if err = d.Set("response_headers", responseHeaders); err != nil { return append(diags, diag.Errorf("Error setting HTTP response headers: %s", err)...) } @@ -124,7 +145,7 @@ func isContentTypeText(contentType string) bool { allowedContentTypes := []*regexp.Regexp{ regexp.MustCompile("^text/.+"), regexp.MustCompile("^application/json$"), - regexp.MustCompile("^application/samlmetadata\\+xml"), + regexp.MustCompile(`^application/samlmetadata\+xml`), } for _, r := range allowedContentTypes { diff --git a/internal/provider/data_source_test.go b/internal/provider/data_source_test.go index cdad29ce..26a12111 100644 --- a/internal/provider/data_source_test.go +++ b/internal/provider/data_source_test.go @@ -8,70 +8,23 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -type TestHttpMock struct { - server *httptest.Server -} - -const testDataSourceConfig_basic = ` -data "http" "http_test" { - url = "%s/meta_%d.txt" -} - -output "body" { - value = data.http.http_test.body -} - -output "response_headers" { - value = data.http.http_test.response_headers -} -` - func TestDataSource_http200(t *testing.T) { testHttpMock := setUpMockHttpServer() defer testHttpMock.server.Close() resource.UnitTest(t, resource.TestCase{ - Providers: testProviders, + ProviderFactories: testProviders(), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testDataSourceConfig_basic, testHttpMock.server.URL, 200), - Check: func(s *terraform.State) error { - _, ok := s.RootModule().Resources["data.http.http_test"] - if !ok { - return fmt.Errorf("missing data resource") - } - - outputs := s.RootModule().Outputs - - if outputs["body"].Value != "1.0.0" { - return fmt.Errorf( - `'body' output is %s; want '1.0.0'`, - outputs["body"].Value, - ) - } - - response_headers := outputs["response_headers"].Value.(map[string]interface{}) - - if response_headers["X-Single"].(string) != "foobar" { - return fmt.Errorf( - `'X-Single' response header is %s; want 'foobar'`, - response_headers["X-Single"].(string), - ) - } - - if response_headers["X-Double"].(string) != "1, 2" { - return fmt.Errorf( - `'X-Double' response header is %s; want '1, 2'`, - response_headers["X-Double"].(string), - ) - } - - return nil - }, + Config: fmt.Sprintf(testDataSourceConfigBasic, testHttpMock.server.URL, 200), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.http.http_test", "body", "1.0.0"), + resource.TestCheckResourceAttr("data.http.http_test", "response_headers.X-Single", "foobar"), + resource.TestCheckResourceAttr("data.http.http_test", "response_headers.X-Double", "1, 2"), + ), }, }, }) @@ -83,124 +36,62 @@ func TestDataSource_http404(t *testing.T) { defer testHttpMock.server.Close() resource.UnitTest(t, resource.TestCase{ - Providers: testProviders, + ProviderFactories: testProviders(), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testDataSourceConfig_basic, testHttpMock.server.URL, 404), + Config: fmt.Sprintf(testDataSourceConfigBasic, testHttpMock.server.URL, 404), ExpectError: regexp.MustCompile("HTTP request error. Response code: 404"), }, }, }) } -const testDataSourceConfig_withHeaders = ` -data "http" "http_test" { - url = "%s/restricted/meta_%d.txt" - - request_headers = { - "Authorization" = "Zm9vOmJhcg==" - } -} - -output "body" { - value = data.http.http_test.body -} -` - func TestDataSource_withHeaders200(t *testing.T) { testHttpMock := setUpMockHttpServer() defer testHttpMock.server.Close() resource.UnitTest(t, resource.TestCase{ - Providers: testProviders, + ProviderFactories: testProviders(), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testDataSourceConfig_withHeaders, testHttpMock.server.URL, 200), - Check: func(s *terraform.State) error { - _, ok := s.RootModule().Resources["data.http.http_test"] - if !ok { - return fmt.Errorf("missing data resource") - } - - outputs := s.RootModule().Outputs - - if outputs["body"].Value != "1.0.0" { - return fmt.Errorf( - `'body' output is %s; want '1.0.0'`, - outputs["body"].Value, - ) - } - - return nil - }, + Config: fmt.Sprintf(testDataSourceConfigWithHeaders, testHttpMock.server.URL, 200), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.http.http_test", "body", "1.0.0"), + ), }, }, }) } -const testDataSourceConfig_utf8 = ` -data "http" "http_test" { - url = "%s/utf-8/meta_%d.txt" -} - -output "body" { - value = "${data.http.http_test.body}" -} -` - func TestDataSource_utf8(t *testing.T) { testHttpMock := setUpMockHttpServer() defer testHttpMock.server.Close() resource.UnitTest(t, resource.TestCase{ - Providers: testProviders, + ProviderFactories: testProviders(), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testDataSourceConfig_utf8, testHttpMock.server.URL, 200), - Check: func(s *terraform.State) error { - _, ok := s.RootModule().Resources["data.http.http_test"] - if !ok { - return fmt.Errorf("missing data resource") - } - - outputs := s.RootModule().Outputs - - if outputs["body"].Value != "1.0.0" { - return fmt.Errorf( - `'body' output is %s; want '1.0.0'`, - outputs["body"].Value, - ) - } - - return nil - }, + Config: fmt.Sprintf(testDataSourceConfigUTF8, testHttpMock.server.URL, 200), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.http.http_test", "body", "1.0.0"), + ), }, }, }) } -const testDataSourceConfig_utf16 = ` -data "http" "http_test" { - url = "%s/utf-16/meta_%d.txt" -} - -output "body" { - value = "${data.http.http_test.body}" -} -` - func TestDataSource_utf16(t *testing.T) { testHttpMock := setUpMockHttpServer() defer testHttpMock.server.Close() resource.UnitTest(t, resource.TestCase{ - Providers: testProviders, + ProviderFactories: testProviders(), Steps: []resource.TestStep{ { - Config: fmt.Sprintf(testDataSourceConfig_utf16, testHttpMock.server.URL, 200), + Config: fmt.Sprintf(testDataSourceConfigUTF16, testHttpMock.server.URL, 200), // This should now be a warning, but unsure how to test for it... //ExpectWarning: regexp.MustCompile("Content-Type is not a text type. Got: application/json; charset=UTF-16"), }, @@ -255,6 +146,38 @@ func TestDataSource_utf16(t *testing.T) { // }) // } +const testDataSourceConfigBasic = ` +data "http" "http_test" { + url = "%s/meta_%d.txt" +} +` + +const testDataSourceConfigWithHeaders = ` +data "http" "http_test" { + url = "%s/restricted/meta_%d.txt" + + request_headers = { + "Authorization" = "Zm9vOmJhcg==" + } +} +` + +const testDataSourceConfigUTF8 = ` +data "http" "http_test" { + url = "%s/utf-8/meta_%d.txt" +} +` + +const testDataSourceConfigUTF16 = ` +data "http" "http_test" { + url = "%s/utf-16/meta_%d.txt" +} +` + +type TestHttpMock struct { + server *httptest.Server +} + func setUpMockHttpServer() *TestHttpMock { Server := httptest.NewServer( http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -265,26 +188,26 @@ func setUpMockHttpServer() *TestHttpMock { w.Header().Add("X-Double", "2") if r.URL.Path == "/meta_200.txt" { w.WriteHeader(http.StatusOK) - w.Write([]byte("1.0.0")) + _, _ = w.Write([]byte("1.0.0")) } else if r.URL.Path == "/restricted/meta_200.txt" { if r.Header.Get("Authorization") == "Zm9vOmJhcg==" { w.WriteHeader(http.StatusOK) - w.Write([]byte("1.0.0")) + _, _ = w.Write([]byte("1.0.0")) } else { w.WriteHeader(http.StatusForbidden) } } else if r.URL.Path == "/utf-8/meta_200.txt" { w.Header().Set("Content-Type", "text/plain; charset=UTF-8") w.WriteHeader(http.StatusOK) - w.Write([]byte("1.0.0")) + _, _ = w.Write([]byte("1.0.0")) } else if r.URL.Path == "/utf-16/meta_200.txt" { w.Header().Set("Content-Type", "application/json; charset=UTF-16") w.WriteHeader(http.StatusOK) - w.Write([]byte("\"1.0.0\"")) + _, _ = w.Write([]byte("\"1.0.0\"")) } else if r.URL.Path == "/x509/cert.pem" { w.Header().Set("Content-Type", "application/x-x509-ca-cert") w.WriteHeader(http.StatusOK) - w.Write([]byte("pem")) + _, _ = w.Write([]byte("pem")) } else if r.URL.Path == "/meta_404.txt" { w.WriteHeader(http.StatusNotFound) } else { diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 9818d4c1..8d591fda 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -6,8 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -var testProviders = map[string]*schema.Provider{ - "http": New(), +//nolint:unparam // error is always nil +func testProviders() map[string]func() (*schema.Provider, error) { + return map[string]func() (*schema.Provider, error){ + "http": func() (*schema.Provider, error) { return New(), nil }, + } } func TestProvider(t *testing.T) { diff --git a/main.go b/main.go index cddf0e38..22da7b58 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,14 @@ package main import ( "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" + "github.com/terraform-providers/terraform-provider-http/internal/provider" ) +// Run the docs generation tool, check its repository for more information on how it works and how docs +// can be customized. +//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs + func main() { plugin.Serve(&plugin.ServeOpts{ ProviderFunc: provider.New}) diff --git a/scripts/errcheck.sh b/scripts/errcheck.sh deleted file mode 100755 index de1be362..00000000 --- a/scripts/errcheck.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking for unchecked errors..." - -if ! which errcheck > /dev/null; then - echo "==> Installing errcheck..." - go get -u github.com/kisielk/errcheck -fi - -err_files=$(errcheck -ignoretests \ - -ignore 'github.com/hashicorp/terraform/helper/schema:Set' \ - -ignore 'bytes:.*' \ - -ignore 'io:Close|Write' \ - $(go list ./...)) - -if [[ -n ${err_files} ]]; then - echo 'Unchecked errors found in the following places:' - echo "${err_files}" - echo "Please handle returned errors. You can check directly with \`make errcheck\`" - exit 1 -fi - -exit 0 diff --git a/scripts/gofmtcheck.sh b/scripts/gofmtcheck.sh deleted file mode 100755 index 408835d5..00000000 --- a/scripts/gofmtcheck.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -# Check gofmt -echo "==> Checking that code complies with gofmt requirements..." -gofmt_files=$(gofmt -l `find . -name '*.go'`) -if [[ -n ${gofmt_files} ]]; then - echo 'gofmt needs running on the following files:' - echo "${gofmt_files}" - echo "You can use the command: \`make fmt\` to reformat code." - exit 1 -fi - -exit 0 diff --git a/templates/index.md.tmpl b/templates/index.md.tmpl new file mode 100644 index 00000000..c0fff439 --- /dev/null +++ b/templates/index.md.tmpl @@ -0,0 +1,15 @@ +--- +page_title: "Provider: HTTP" +description: |- + The HTTP provider interacts with HTTP servers. +--- + +# HTTP Provider + +The HTTP provider is a utility provider for interacting with generic HTTP +servers as part of a Terraform configuration. + +This provider requires no configuration. For information on the resources +it provides, see the navigation bar. + +{{- /* No schema in this provider, so no need for this: .SchemaMarkdown | trimspace */ -}} \ No newline at end of file diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 00000000..8abc7c8d --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,9 @@ +//go:build tools +// +build tools + +package tools + +import ( + // document generation + _ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" +)