Skip to content

Commit 43d647b

Browse files
init
1 parent e405e0a commit 43d647b

35 files changed

+5300
-1
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v3
18+
with:
19+
go-version: 1.18
20+
21+
- name: Install prerequisites
22+
run: make init
23+
24+
- name: Build
25+
run: make build
26+
27+
- name: Test
28+
run: make test

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
3+
# This GitHub action can publish assets for release when a tag is created.
4+
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
5+
#
6+
# This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your
7+
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
8+
# secret. If you would rather own your own GPG handling, please fork this action
9+
# or use an alternative one for key handling.
10+
#
11+
# You will need to pass the `--batch` flag to `gpg` in your signing step
12+
# in `goreleaser` to indicate this is being used in a non-interactive mode.
13+
#
14+
name: release
15+
on:
16+
push:
17+
tags:
18+
- 'v*'
19+
jobs:
20+
goreleaser:
21+
runs-on: ubuntu-latest
22+
steps:
23+
-
24+
name: Checkout
25+
uses: actions/checkout@v3
26+
-
27+
name: Unshallow
28+
run: git fetch --prune --unshallow
29+
-
30+
name: Set up Go
31+
uses: actions/setup-go@v3
32+
with:
33+
go-version-file: 'go.mod'
34+
cache: true
35+
-
36+
name: Import GPG key
37+
uses: crazy-max/ghaction-import-gpg@v5
38+
id: import_gpg
39+
with:
40+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
41+
passphrase: ${{ secrets.PASSPHRASE }}
42+
-
43+
name: Run GoReleaser
44+
uses: goreleaser/goreleaser-action@v3.0.0
45+
with:
46+
version: latest
47+
args: release --rm-dist
48+
env:
49+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
50+
# GitHub sets this automatically
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@
1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
1313

14+
bin
15+
1416
# Dependency directories (remove the comment below to include it)
1517
# vendor/
18+
19+
terraform.tfsta*
20+
crash.log
21+
.terraform
22+
test_output

.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug Create Cluster",
6+
"type": "go",
7+
"request": "launch",
8+
"mode": "debug",
9+
"program": "${workspaceRoot}/hack/main.go",
10+
"args": [
11+
"docker",
12+
]
13+
},
14+
{
15+
"name": "Debug Terraform Provider",
16+
"type": "go",
17+
"request": "launch",
18+
"mode": "debug",
19+
"program": "${workspaceFolder}",
20+
"env": {},
21+
"args": [
22+
"-debug",
23+
]
24+
}
25+
]
26+
}

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.PHONY: init
2+
init:
3+
go mod tidy
4+
5+
.PHONY: configure
6+
configure: build set-rc
7+
go generate ./...
8+
9+
.PHONY: clean
10+
clean:
11+
rm bin/* || true
12+
rm tests/terraform.tfstate || true
13+
rm tests/terraform.tfstate.backup || true
14+
minikube delete -p terraform-provider-minikube
15+
minikube delete -p terraform-provider-minikube-acc
16+
17+
.PHONY: test
18+
test:
19+
go clean -testcache
20+
go test ./...
21+
22+
.PHONY: acceptance
23+
acceptance:
24+
TF_ACC=true go test ./minikube -run "TestClusterCreation" -v -p 1 --timeout 10m
25+
26+
.PHONY: test-stack
27+
test-stack: set-rc
28+
terraform -chdir=examples/resource/minikube_cluster init || true
29+
terraform -chdir=examples/resource/minikube_cluster apply --auto-approve
30+
terraform -chdir=tests destroy --auto-approve
31+
32+
.PHONY: build
33+
build:
34+
go build -o bin/terraform-provider-minikube
35+
36+
.PHONY: set-rc
37+
set-rc: build
38+
touch ~/.terraformrc
39+
echo "provider_installation { dev_overrides { \"hashicorp/minikube\" = \"$$(pwd)/bin\" } direct {}}" > ~/.terraformrc
40+
41+
SED_FLAGS := -i
42+
UNAME_S := $(shell uname -s)
43+
ifeq ($(UNAME_S),Linux)
44+
SED_FLAGS += -e
45+
endif
46+
ifeq ($(UNAME_S),Darwin)
47+
SED_FLAGS += ''
48+
endif
49+
.PHONY: set-version
50+
set-version:
51+
$(eval VERSION := $(shell cat minikube/version/version.go | grep Version | tr -d "[:space:]" | sed 's/Version\="//g' | sed 's/"\/\/.*//g'))
52+
sed $(SED_FLAGS) 's/VERSION=".*"/VERSION="$(VERSION)"/g' bootstrap/install-driver.sh

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
1-
# terraform-provider-minikube
1+
# terraform-provider-minikube
2+
3+
*CURRENTLY IN PROGRESS*
4+
5+
A terraform provider for [minikube!](https://minikube.sigs.k8s.io/docs/)
6+
7+
## Installing your preferred driver
8+
9+
If you don't have minikube installed, or have never run minikube before, you'll need to install your corresponding driver first
10+
11+
This requires _admin_ permissions
12+
13+
### Minikube
14+
15+
```bash
16+
minikube --vm=true --driver=hyperkit --download-only
17+
minikube --driver=docker --download-only
18+
```
19+
20+
### Manual
21+
22+
You can find the drivers published in the [minikube releases section](https://github.com/kubernetes/minikube/releases). Simply download the
23+
preferred driver and copy it to your .minikube/bin folder and ensure the current user has sufficient access
24+
25+
### Living dangeriously
26+
27+
```bash
28+
#x86_64
29+
curl https://raw.githubusercontent.com/scott-the-programmer/terraform-provider-minikube/main/bootstrap/install-driver.sh | sudo bash -s "kvm2"
30+
31+
#arm64
32+
curl https://raw.githubusercontent.com/scott-the-programmer/terraform-provider-minikube/main/bootstrap/install-driver.sh | sudo bash -s "kvm2" "arm64"
33+
```
34+
35+
## Usage
36+
37+
```terraform
38+
provider minikube {}
39+
40+
resource "minikube_cluster" "cluster" {
41+
vm = true
42+
driver = "hyperkit"
43+
kubernetes_version = "v1.23.3"
44+
addons = [
45+
"dashboard",
46+
"default-storageclass",
47+
"ingress"
48+
]
49+
}
50+
```
51+
52+
You can use `minikube` to verify the cluster is up & running
53+
54+
```console
55+
> minikube profile list
56+
57+
|----------------------------------------|-----------|---------|---------------|------|---------|---------|-------|
58+
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes |
59+
|----------------------------------------|-----------|---------|---------------|------|---------|---------|-------|
60+
| terraform-provider-minikube | hyperkit | docker | 192.168.64.42 | 8443 | v1.23.3 | Running | 1 |
61+
|----------------------------------------|-----------|---------|---------------|------|---------|---------|-------|
62+
```
63+
64+
## Want to help out?
65+
66+
See [the contributing](./docs/contributing.md) if you wish to get into the details of this terraform minikube provider!

bootstrap/install-driver.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
VERSION="v1.25.2"
6+
7+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
8+
9+
driver=$1
10+
arch=$2
11+
12+
if [ -z $arch ]; then
13+
driver+=$arch
14+
fi;
15+
16+
url="https://github.com/kubernetes/minikube/releases/download/$VERSION/docker-machine-driver-$driver"
17+
echo "Downloading $url"
18+
19+
mkdir -p $HOME/.minikube/bin
20+
21+
chown -R $SUDO_USER $HOME/.minikube
22+
chmod -R u+wrx $HOME/.minikube
23+
24+
curl $url -o "/tmp/docker-machine-driver-$driver" -L
25+
mv "/tmp/docker-machine-driver-$driver" $HOME/.minikube/bin
26+
27+
chown root:wheel $HOME/.minikube/bin/"docker-machine-driver-$driver"
28+
chmod 4755 $HOME/.minikube/bin/"docker-machine-driver-$driver"

docs/contributing.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# contributing
2+
3+
Raising bugs, feature requests and PRs is more than welcome!
4+
5+
If you want to jump in and help out, here's the best way to get started
6+
7+
## Prerequisites
8+
9+
* [docker](https://www.docker.com/get-started/)
10+
* [golang](https://go.dev/)
11+
* [terraform 1.* and onwards](https://www.terraform.io/)
12+
* make
13+
* Windows: http://gnuwin32.sourceforge.net/packages/make.htm
14+
* OSX: `brew install make`
15+
* Debian/Ubuntu: `apt-get make`
16+
* [minikube](https://minikube.sigs.k8s.io/docs/start/) (for testing)
17+
18+
## Package dependencies
19+
20+
```console
21+
make init
22+
```
23+
24+
## Building the binary
25+
26+
```console
27+
make build
28+
```
29+
30+
## Tests
31+
32+
### Unit Tests
33+
34+
35+
```console
36+
make test
37+
```
38+
39+
### Acceptance Tests
40+
41+
To spin up actual clusters on your machine
42+
43+
```console
44+
make acceptance
45+
```
46+
47+
## Test stack
48+
49+
```console
50+
make set-rc
51+
make test-stack
52+
```
53+
54+
or
55+
56+
```console
57+
make set-rc
58+
make build
59+
terraform -chdir=examples/resources/minikube_cluster apply
60+
```
61+
62+
## Debugging via vscode
63+
64+
### Attaching to the terraform provider binary
65+
66+
To debug your terraform provider, run the `Debug Terraform Provider` vscode task. This will then output an environment variable that you will need to set in a new shell like so
67+
68+
69+
```console
70+
export TF_REATTACH_PROVIDERS='*output from vscode debug session'
71+
make set-rc
72+
make test-stack
73+
```
74+
75+
## Debugging via go entrypoint
76+
77+
You can run a self-contained cluster spin up and teardown via
78+
79+
```console
80+
go run ./hack/main.go *drivername*
81+
```
82+
83+
## Regenerating terradocs / mocks
84+
85+
Any changes to mocked interfaces and schema resources need to be
86+
reflected in their generated counter parts
87+
88+
```console
89+
make configure
90+
```

docs/index.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "minikube Provider"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# minikube Provider
10+
11+
A terraform provider for [minikube!](https://minikube.sigs.k8s.io/docs/)
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "minikube" {}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema

0 commit comments

Comments
 (0)