Skip to content

Commit

Permalink
Merge pull request #6 from fiveai/add-publising-to-tf-registry
Browse files Browse the repository at this point in the history
Add publising to tf registry
  • Loading branch information
graemedavidson authored Feb 3, 2021
2 parents 06b46d4 + f75375d commit 773e76d
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 203 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# EditorConfig is awesome: http://EditorConfig.org
# Uses editorconfig to maintain consistent coding styles

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[*.md]
trim_trailing_whitespace = false
indent_size = 4
max_line_length=120

[*.{tf,tfvars}]
indent_size = 2
indent_style = space
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# https://github.com/hashicorp/terraform-provider-scaffolding/blob/main/.github/workflows/release.yml
name: release
on:
push:
tags:
- 'v*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --parallelism 2 --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor
dist
51 changes: 51 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# https://github.com/hashicorp/terraform-provider-scaffolding/blob/main/.goreleaser.yml
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
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 Terraform Cloud 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
- 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:
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}"
changelog:
skip: true
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

84 changes: 0 additions & 84 deletions Makefile

This file was deleted.

120 changes: 66 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
# Kubernetes Terraform Provider

The k8s Terraform provider enables Terraform to deploy Kubernetes resources. Unlike the [official Kubernetes provider][kubernetes-provider] it handles raw manifests, leveraging `kubectl` directly to allow developers to work with any Kubernetes resource natively.
The k8s Terraform provider enables Terraform to deploy Kubernetes resources. Unlike the
[official Kubernetes provider][kubernetes-provider] it handles raw manifests, leveraging `kubectl` directly to allow
developers to work with any Kubernetes resource natively.

## Usage
This provider is published in the [Terraform Registry](https://registry.terraform.io/providers/fiveai/k8s)

Use `go get` to install the provider:
## ToC

```
go get -u github.com/ericchiang/terraform-provider-k8s
```
* [Usage](#usage)
* [Build](#build)
* [Publishing](#publishing)

## Usage

### Provider and Version control

Register the plugin in `~/.terraformrc`:
This provider is automatically pushed to the TF Registry. You can pull it into your project uses the standard provider
and versions notation.

```hcl
providers {
k8s = "/$GOPATH/bin/terraform-provider-k8s"
terraform {
required_providers {
kubernetes = {
source = "fiveai/k8s"
version = "0.2.1"
}
}
}
provider "kubernetes" {
# Configuration options
}
```

#### Provider Configuration options

The provider takes the following optional configuration parameters:

* If you have a kubeconfig available on the file system you can configure the provider as:
Expand All @@ -37,48 +55,48 @@ provider "k8s" {
```

**WARNING:** Configuration from the variable will be recorded into a temporary file and the file will be removed as
soon as call is completed. This may impact performance if the code runs on a shared system because
and the global tempdir is used.
soon as call is completed. This may impact performance if the code runs on a shared system because the global
tempdir is used.

The k8s Terraform provider introduces a single Terraform resource, a `k8s_manifest`. The resource contains a `content` field, which contains a raw manifest.
### Resource Definition

```hcl
variable "replicas" {
type = "string"
default = 3
}
An example of the k8s_manifest might look like.

data "template_file" "nginx-deployment" {
template = "${file("manifests/nginx-deployment.yaml")}"
The terraform resource definition should include:

vars {
replicas = "${var.replicas}"
}
}
* `name` of the resource
* `namespace` to be deployed to (namespaced resources only, not cluster level)
* `content` resource to be deployed
* `kind` of resource being deployed, e.g. `Deployment`, `ConfigMap`

resource "k8s_manifest" "nginx-deployment" {
content = "${data.template_file.nginx-deployment.rendered}"
```hcl
resource "k8s_manifest" "dummy-deployment" {
name = "dummyvalue"
namespace = "default"
kind = "Deployment"
content = templatefile("${path.module}/manifest/dummy-deployment.yml.tpl", {
app = "dummyvalue"
})
}
```

In this case `manifests/nginx-deployment.yaml` is a templated deployment manifest.
The templated resource definition should then resemble the following example.

```yaml
apiVersion: apps/v1beta2
kind: Deployment
apiVersion: apps/v1
metadata:
name: nginx-deployment
labels:
app: nginx
app: ${app}
spec:
replicas: ${replicas}
replicas: 1
selector:
matchLabels:
app: nginx
app: ${app}
template:
metadata:
labels:
app: nginx
app: ${app}
spec:
containers:
- name: nginx
Expand All @@ -87,26 +105,20 @@ spec:
- containerPort: 80
```
The Kubernetes resources can then be managed through Terraform.
```terminal
$ terraform apply
# ...
Apply complete! Resources: 1 added, 1 changed, 0 destroyed.
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-deployment 3 3 3 3 1m
$ terraform apply -var 'replicas=5'
# ...
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-deployment 5 5 5 3 3m
$ terraform destroy -force
# ...
Destroy complete! Resources: 2 destroyed.
$ kubectl get deployments
No resources found.
## Build
To build please use [goreleaser](https://goreleaser.com/intro/). You can edit the automated Github Actions by the
`./.goreleaser.yml` and `./github/workflows/release.yml` files.

To create a test build run the following command:

```
goreleaser build --snapshot
```

[kubernetes-provider]: https://www.terraform.io/docs/providers/kubernetes/index.html
To push up a new build add a tag based on [semantic versioning](https://semver.org/) with a `v` prefix.

## Publishing

The configuration is a terraform and github integration with manual configuration. The provider has been setup and will
automatically pickup new version releases in github.
Loading

0 comments on commit 773e76d

Please sign in to comment.