Skip to content

Commit

Permalink
Merge pull request #274 from dikhan/feature/bump-to-terraform-sdk-2.0
Browse files Browse the repository at this point in the history
[FeatureRequest: Issue #268] Major upgrade to Terraform SDK 2.0
  • Loading branch information
dikhan authored Feb 19, 2021
2 parents 5d335a8 + 2f1f61a commit 19a0c8f
Show file tree
Hide file tree
Showing 127 changed files with 2,969 additions and 7,557 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
.glide/

.terraform/*
.terraform.*
examples/*/.terraform/*
examples/*/terraform.tfstate*
.idea/*
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ builds:
- -a
- -tags="netgo"
ldflags:
- -s -w -extldflags "-static" -X "github.com/dikhan/terraform-provider-openapi/openapi/version.Version={{.Version}}" -X "github.com/dikhan/terraform-provider-openapi/openapi/version.Commit={{.Commit}}" -X "github.com/dikhan/terraform-provider-openapi/openapi/version.Date={{.Date}}"
- -s -w -extldflags "-static" -X "github.com/dikhan/terraform-provider-openapi/openapi/v2/version.Version={{.Version}}" -X "github.com/dikhan/terraform-provider-openapi/openapi/v2/version.Commit={{.Commit}}" -X "github.com/dikhan/terraform-provider-openapi/openapi/v2/version.Date={{.Date}}"

release:
name_template: "v{{.Version}}"
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dist: trusty

language: go
go:
- 1.12.4
- "1.14.x"

services:
- docker
Expand Down
21 changes: 7 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ NEW_RELEASE_VERSION_VALIDATION?=$(shell ./scripts/semver.sh $(RELEASE_TAG) $(CUR

COMMIT :=$(shell git rev-parse --verify --short HEAD)
DATE :=$(shell date +'%FT%TZ%z')
REPO=github.com/dikhan/terraform-provider-openapi
REPO=github.com/dikhan/terraform-provider-openapi/v2
LDFLAGS = '-s -w -extldflags "-static" -X "$(REPO)/openapi/version.Version=$(VERSION)" -X "$(REPO)/openapi/version.Commit=$(COMMIT)" -X "$(REPO)/openapi/version.Date=$(DATE)"'

PROVIDER_NAME?=""
TF_CMD?="plan"

TF_INSTALLED_PLUGINS_PATH="$(HOME)/.terraform.d/plugins"

TEST_PACKAGES?=$$(go list ./... | grep -v "examples\|vendor\|integration")
INT_TEST_PACKAGES?=$$(go list ./... | grep "/tests/integration")
GOFMT_FILES?=$$(find . -name '*.go' | grep -v 'examples\|vendor')
Expand Down Expand Up @@ -81,10 +79,6 @@ integration-test: local-env-down local-env

test-all: test integration-test

pre-requirements:
@echo "[INFO] Creating $(TF_INSTALLED_PLUGINS_PATH) if it does not exist"
@[ -d $(TF_INSTALLED_PLUGINS_PATH) ] || mkdir -p $(TF_INSTALLED_PLUGINS_PATH)

release-pre-requirements:
ifeq (, $(shell which github-release-notes))
@echo "[INFO] No github-release-notes in $(PATH), installing github-release-notes"
Expand All @@ -96,7 +90,7 @@ ifeq (, $(shell which goreleaser))
endif

# PROVIDER_NAME="goa" make install
install: build pre-requirements
install: build
$(call install_plugin,$(PROVIDER_NAME))

# make local-env-down
Expand All @@ -116,11 +110,11 @@ examples-container: local-env
@docker-compose -f ./build/docker-compose.yml run terraform-provider-openapi-examples

# [TF_CMD=apply] make run-terraform-example-swaggercodegen
run-terraform-example-swaggercodegen: build pre-requirements
run-terraform-example-swaggercodegen: build
$(call run_terraform_example,"https://localhost:8443/swagger.yaml",swaggercodegen)

# [TF_CMD=apply] make run-terraform-example-goa
run-terraform-example-goa: build pre-requirements
run-terraform-example-goa: build
$(call run_terraform_example,"http://localhost:9090/swagger/swagger.yaml",goa)

# make latest-tag
Expand All @@ -145,10 +139,8 @@ else
endif

define install_plugin
@$(eval TF_PROVIDER_PLUGIN_NAME := $(TF_PROVIDER_NAMING_CONVENTION)$(1))

@echo "[INFO] Installing $(TF_PROVIDER_PLUGIN_NAME) binary in -> $(TF_INSTALLED_PLUGINS_PATH)/$(TF_PROVIDER_PLUGIN_NAME)"
@mv ./$(TF_OPENAPI_PROVIDER_PLUGIN_NAME) $(TF_INSTALLED_PLUGINS_PATH)/$(TF_PROVIDER_PLUGIN_NAME)
@$(eval PROVIDER_NAME := $(1))
@./scripts/install.sh --provider-name $(PROVIDER_NAME) --provider-source-address "terraform.example.com/examplecorp" --compiled-plugin-path $(TF_OPENAPI_PROVIDER_PLUGIN_NAME) --debug
endef

define run_terraform_example
Expand All @@ -158,6 +150,7 @@ define run_terraform_example
$(call install_plugin,$(PROVIDER_NAME))

@$(eval TF_EXAMPLE_FOLDER := ./examples/$(PROVIDER_NAME))
@rm -rf $(TF_EXAMPLE_FOLDER)/.terraform $(TF_EXAMPLE_FOLDER)/.terraform.lock.hcl

@echo "[INFO] Performing sanity check against the service provider's swagger endpoint '$(OTF_VAR_SWAGGER_URL)'"
@$(eval SWAGGER_HTTP_STATUS := $(shell curl -s -o /dev/null -w '%{http_code}' $(OTF_VAR_SWAGGER_URL) -k))
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ rather than the tooling around it.

### Pre-requirements

- The service provider hosts APIs compliant with OpenApi and swagger spec file is available via a discovery endpoint.
- The service provider hosts APIs documented using [OpenApi 2.0 specification](https://swagger.io/specification/v2/) and the APIs
comply with the OpenAPI Terraform Provider [How to](docs/how_to.md) guidelines. The service provider API's OpenAPI document must also
be available via a discovery endpoint served through HTTP/s or the file system.

### Requirements

- [Terraform](https://www.terraform.io/downloads.html) v0.12.0 (to execute the terraform provider plugin)
- [Go](https://golang.org/doc/install) 1.12.4 (to build the provider plugin)
- [Terraform](https://www.terraform.io/downloads.html) >= v0.12.0 (to execute the terraform provider plugin)
- If you are using Terraform 0.11, refer to the latest [OpenAPI Terraform provider v0.13.1 released](https://github.com/dikhan/terraform-provider-openapi/releases/tag/v0.31.1) compatible with Terraform 0.11.
- [Go](https://golang.org/doc/install) >=1.14 (to build the provider plugin)
- This project uses [go modules](https://github.com/golang/go/wiki/Modules) for dependency management
- [Docker](https://www.docker.com/) 17.09.0-ce (to run service provider example)
- [Docker-compose](https://docs.docker.com/compose/) 1.16.1 (to run service provider example)
Expand All @@ -51,16 +54,16 @@ rather than the tooling around it.

### Things to know regarding custom terraform providers

- Terraform expects third party providers to be manually installed in the '.terraform.d/plugins' sub-path in your user's home directory.
- Terraform expects third party (in-house) providers to be manually installed in a specific directory. Refer to the [OpenAPI Terraform provider installation instructions](#openapi-terraform-provider-installation) to
learn more about this.
- Terraform expects terraform provider names to follow a specific naming scheme. The naming scheme for plugins is
``terraform-<type>-NAME_vX.Y.Z``, where type is either provider or provisioner.
``terraform-<type>-<name>_vX.Y.Z``, where `<type>` is either provider or provisioner, `<name>` is the provider's name and `X.Y.Z` is the version of the plugin.

More information about how terraform discovers third party terraform providers and naming conventions [here](https://www.terraform.io/docs/extend/how-terraform-works.html#discovery).

### OpenAPI Terraform provider installation

There are multiple ways how the OpenAPI Terraform provider can be installed. Please
refer to the [OpenAPI Terraform provider installation document](https://github.com/dikhan/terraform-provider-openapi/blob/master/docs/installing_openapi_provider.md)
There are multiple ways how the OpenAPI Terraform provider can be installed. Please refer to the [OpenAPI Terraform provider installation document](https://github.com/dikhan/terraform-provider-openapi/blob/master/docs/installing_openapi_provider.md)
to learn more about it.

### OpenAPI Terraform provider in action
Expand All @@ -77,13 +80,14 @@ library. The OpenAPI document is the source of truth for both the OpenAPI Terraf

Additionally, the following documents provide deep insight regarding OpenAPI and Terraform as well as frequently asked questions:

- [How to](docs/how_to.md) document contains information about how to define a swagger file following good practises that
- [How to](docs/how_to.md) document contains information about how to define a OpenAPI document following good practises that
make it work seamlessly with this terraform provider. Additionally, learn more about what is currently supported.
- [Migrating to Terraform 0.12](./docs/terraform_version_upgrades/upgrading_to_terraform_0.12.md). This document describes
how to update configuration created using Terraform v0.11 to v0.12.
- [FAQ](./docs/faq.md) document answers for the most frequently asked questions.

## Contributing

Please follow the guidelines from:

- [Contributor Guidelines](.github/CONTRIBUTING.md)
Expand Down
Loading

0 comments on commit 19a0c8f

Please sign in to comment.