Categorygithub.com/MehdiAtBud/terraform-provider-kubernetes-wait

# README

Terraform Provider: Kubernetes Wait

The Kubernetes provider interacts with a Kubernetes Cluster. It provides a data source that issues a request to the cluster waiting for a resource to be available or to exceed the timeout and return an error.

Requirements

Example Usage

Note the environment variable KUBERNETES_URL must be set.

terraform {
  required_providers {
    kubernetes-wait = {
      source  = "MehdiAtBud/kubernetes-wait"
      version = "0.1.14"
    }
  }
}

provider "kubernetes-wait" {
  host  = "https://${data.google_container_cluster.my_cluster.endpoint}"
  token = data.google_client_config.default.access_token
  cluster_ca_certificate = base64decode(
    data.google_container_cluster.my_cluster.master_auth[0].cluster_ca_certificate,
  )
}

data "google_client_config" "default" {}

data "google_container_cluster" "my_cluster" {
  name     = "liam-app"
  location = "europe-west2"
  project  = "experimental-project-191516"
}


data "kubernetes-wait" "example" {
  resource_name    = "diode"
  namespace        = "infra"
  max_elapsed_time = 10
  initial_interval = 100
  multiplier       = "1.2"
  max_interval     = 5000
}

  • resource_name : The name of the resource to wait for. Only Service resources are currently supported.
  • namespace : Kubernetes namespace in which the resource is residing.
  • max_elapsed_time : Maximum seconds to wait for in total.
  • initial_interval : Duration of initial interval in milliseconds.
  • multiplier : Decimal number representing the multiplication factor for exponential backoff logic.
  • max_interval : Maximum interval in milliseconds after multiplier has been applied.

Development

Building

  1. git clone this repository and cd into its directory
  2. make will trigger the Golang build

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.

Testing

In order to test the provider, you can run

  • make test to run provider tests
  • make testacc to run provider acceptance tests

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.

Generating documentation

This provider uses 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.

Use make generate to ensure the documentation is regenerated with any changes.

Using a development build

If running tests and acceptance tests 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.

First, use make install to place a fresh development build of the provider in your ${GOBIN} (defaults to ${GOPATH}/bin or ${HOME}/go/bin if ${GOPATH} is not set). Repeat this every time you make changes to the provider locally.

Then, setup your environment following these instructions to make your local terraform use your local build.

Testing GitHub Actions

This project uses GitHub Actions to realize its CI.

Sometimes it might be helpful to locally reproduce the behaviour of those actions, and for this we use act. Once installed, you can simulate the actions executed when opening a PR with:

# 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.

Each release is cut by pushing a semantically versioned tag to the default branch.

License

Mozilla Public License v2.0