Skip to content
This repository has been archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vandycknick committed Nov 16, 2020
0 parents commit 5c7bd1c
Show file tree
Hide file tree
Showing 14 changed files with 1,439 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.DS_Store

terraform-provider-kuma
bin

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
terraform
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
TEST?=$$(go list ./... | grep -v 'vendor')
HOSTNAME=hashicorp.com
NAMESPACE=edu
NAME=kuma
BINARY=terraform-provider-${NAME}
VERSION=0.1
OS_ARCH=linux_amd64

default: install

build:
go build -o ./bin/${BINARY}

release:
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64

install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

test:
go test -i $(TEST) || exit 1
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
7 changes: 7 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.7'
services:
cp:
image: kong-docker-kuma-docker.bintray.io/kuma-cp:0.7.3
command: run
ports:
- '5681:5681'
13 changes: 13 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
provider "kuma" {
host = "http://localhost:5681"
api_token = "test123"
}

resource "kuma_mesh" "yolo2" {
name = "yolo2"
}

resource "kuma_dataplane" "yolo_data" {
mesh = kuma_mesh.yolo2.name
name = "yolo_data"
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/nickvdyck/terraform-provider-kuma

go 1.15

require github.com/hashicorp/terraform-plugin-sdk/v2 v2.2.0
535 changes: 535 additions & 0 deletions go.sum

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions kuma/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package kuma

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/nickvdyck/terraform-provider-kuma/kumaclient"
)

// Provider -
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"host": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KUMA_HOST", nil),
},
"api_token": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KUMA_API_TOKEN", nil),
},
},
ResourcesMap: map[string]*schema.Resource{
"kuma_mesh": resourceMesh(),
"kuma_dataplane": resourceDataplane(),
},
DataSourcesMap: map[string]*schema.Resource{},
ConfigureContextFunc: providerConfigure,
}
}

func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
apiToken := d.Get("api_token").(string)

var host *string

hVal, ok := d.GetOk("host")
if ok {
tempHost := hVal.(string)
host = &tempHost
}

// Warning or errors can be collected in a slice type
var diags diag.Diagnostics

if apiToken != "" {
c, err := kumaclient.NewClient(*host, apiToken)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Unable to create Kuma client",
Detail: "Unable to authenticate user for authenticated Kuma client",
})

return nil, diags
}

return c, diags
}

diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Unable to create Kuma client",
Detail: "Unable to create anonymous Kuma client",
})
return nil, diags
}
Loading

0 comments on commit 5c7bd1c

Please sign in to comment.