From ad2500cfc51db75b079ffab8e81829aa060fcd23 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 5 Aug 2020 09:17:29 -0700 Subject: [PATCH] Adding docs folder and acceptance tests (#18) * release binaries in commit script * rewrite of resource, adding acceptance tests * add make target for acceptance tests * make targets * remove import block, as update resource is not implemented yet * add documentation and more tests * update docs * proper check destroy method * make for ci --- Makefile | 12 +- README.md | 77 +---- before-commit.sh | 53 +++- docs/DEVELOPMENT.md | 25 ++ docs/FAQ.md | 3 + docs/USAGE.md | 64 ++++ example/main.tf | 2 +- go.mod | 8 +- go.sum | 153 ++-------- kind/provider.go | 6 +- kind/provider_test.go | 42 ++- .../{resource_kind.go => resource_cluster.go} | 48 ++- kind/resource_cluster_test.go | 276 ++++++++++++++++++ main.go | 8 +- 14 files changed, 536 insertions(+), 241 deletions(-) create mode 100644 docs/DEVELOPMENT.md create mode 100644 docs/FAQ.md create mode 100644 docs/USAGE.md rename kind/{resource_kind.go => resource_cluster.go} (83%) create mode 100644 kind/resource_cluster_test.go diff --git a/Makefile b/Makefile index 1d23811..0b64f92 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ .PHONY: build build: + ./before-commit.sh + +.PHONY: ci-build +ci-build: ./before-commit.sh ci .PHONY: ci-pr @@ -13,4 +17,10 @@ ci-release: build .PHONY: clean clean: - rm -rf bin \ No newline at end of file + rm -rf bin + +ci-testacc: + ./before-commit.sh ci testacc + +testacc: + ./before-commit.sh testacc diff --git a/README.md b/README.md index e2aeac9..243076f 100644 --- a/README.md +++ b/README.md @@ -6,82 +6,19 @@ The Terraform Provider for kind enables [Terraform](https://www.terraform.io) to provision local [Kubernetes](https://kubernetes.io) clusters on base of [Kubernetes IN Docker (kind)](https://github.com/kubernetes-sigs/kind). -## Prerequisites +## Quick Starts +- [Using the provider](./docs/USAGE.md) +- [Provider development](./docs/DEVELOPMENT.md) -- [Terraform](https://www.terraform.io/downloads.html) 0.12+ -- [Go](https://golang.org/doc/install) 1.13 or higher - -## Development - -Perform the following steps to build the providers: - -1. Build the provider: - ```bash - go build -o terraform-provider-kind - ``` -2. Move the provider binary into the terraform plugins folder. - - >**NOTE**: For details on Terraform plugins see [this](https://www.terraform.io/docs/plugins/basics.html#installing-plugins) document. - -## Usage - -Perform the following steps to use the provider: - -1. Go to the provider [example](https://github.com/kyma-incubator/terraform-provider-kind/tree/master/example) folder: - ```bash - cd example - ``` -2. Edit the `main.tf` file and provide the following kind configuration: - -```hcl -provider "kind" {} - -# creating a cluster with kind of the name "test-cluster" with kubernetes version hardcoded in kind defaults https://github.com/kubernetes-sigs/kind/blob/master/pkg/apis/config/defaults/image.go#L21 -resource "kind" "my-cluster" { - name = "test-cluster" -} -``` - -To override the node image used, you can specify the `node_image` like so: - -```hcl -provider "kind" {} - -# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.16.1 -resource "kind" "my-cluster" { - name = "test-cluster" - node_image = "kindest/node:v1.16.1" -} -``` - -To override the default kind config, you can specify the `kind_config` with HEREDOC: +## Example Usage +Copy the following code into a file with the extension `.tf` to create a kind cluster with only default values. ```hcl provider "kind" {} -# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.18.4 and two nodes -resource "kind" "my-cluster" { +resource "kind_cluster" "default" { name = "test-cluster" - node_image = "kindest/node:v1.18.4" - kind_config =<**NOTE**: For details on Terraform plugins see [this](https://www.terraform.io/docs/plugins/basics.html#installing-plugins) document. + +## Testing + +In order to test the provider you can run `go test ./...` for the unit tests as well as `make testacc` for the Acceptance Tests. If you prefer to only run tests and skip linting and formatting when running Acceptance Tests start them by running `TF_ACC=1 go test ./kind -v -count 1 -parallel 20 -timeout 120m`. + +*Note:* Acceptance tests create real resources, and will consume significant resources on the machine they run on. \ No newline at end of file diff --git a/docs/FAQ.md b/docs/FAQ.md new file mode 100644 index 0000000..46f99ad --- /dev/null +++ b/docs/FAQ.md @@ -0,0 +1,3 @@ +# Frequently Asked Questions + +Add questions as they arise... \ No newline at end of file diff --git a/docs/USAGE.md b/docs/USAGE.md new file mode 100644 index 0000000..69c8d8c --- /dev/null +++ b/docs/USAGE.md @@ -0,0 +1,64 @@ +# Using The Provider + +## Usage + +Perform the following steps to use the provider: + +1. Go to the provider [example](https://github.com/kyma-incubator/terraform-provider-kind/tree/master/example) folder: + ```bash + cd example + ``` +2. Edit the `main.tf` file and provide the following kind configuration: + +```hcl +provider "kind" {} + +# creating a cluster with kind of the name "test-cluster" with kubernetes version hardcoded in kind defaults https://github.com/kubernetes-sigs/kind/blob/master/pkg/apis/config/defaults/image.go#L21 +resource "kind_cluster" "default" { + name = "test-cluster" +} +``` + +To override the node image used, you can specify the `node_image` like so: + +```hcl +provider "kind" {} + +# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.16.1 +resource "kind_cluster" "default" { + name = "test-cluster" + node_image = "kindest/node:v1.16.1" +} +``` + +To override the default kind config, you can specify the `kind_config` with HEREDOC: + +```hcl +provider "kind" {} + +# creating a cluster with kind of the name "test-cluster" with kubernetes version v1.18.4 and two nodes +resource "kind_cluster" "default" { + name = "test-cluster" + node_image = "kindest/node:v1.18.4" + kind_config =<