-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (64 loc) · 3.03 KB
/
Copy pathMakefile
File metadata and controls
85 lines (64 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# SPDX-FileCopyrightText: 2026 Elio Severo Junior <elioseverojunior@gmail.com>
#
# SPDX-License-Identifier: MIT OR Apache-2.0
# Terraform provider for KinD.
#
# Run `make help` for the available targets.
HOSTNAME := registry.terraform.io
NAMESPACE := elioseverojunior
NAME := kind
BINARY := terraform-provider-$(NAME)
# Version for the local plugin install path. Derived from the most recent git
# tag so `make install` lands in the directory Terraform resolves for a released
# build of the same version. Hardcoding it drifts the moment a tag is pushed --
# it previously read 0.1.0 while the published tags were v0.0.x.
# Override for a one-off build: make install VERSION=1.2.3
GIT_TAG := $(shell git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//')
VERSION ?= $(if $(GIT_TAG),$(GIT_TAG),0.0.0)
OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH)
PLUGIN_DIR := $(HOME)/.terraform.d/plugins/$(HOSTNAME)/$(NAMESPACE)/$(NAME)/$(VERSION)/$(OS_ARCH)
# tfplugindocs and copywrite are pinned in tools/go.mod so contributors do not
# need them installed globally.
TOOLS := cd tools && go run
.DEFAULT_GOAL := help
.PHONY: help version build install clean fmt vet lint test test-coverage testacc generate docs tidy check all
help: ## Show this help.
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}'
version: ## Print the version used for the local install path.
@echo $(VERSION)
build: ## Compile the provider binary.
go build -o $(BINARY)
install: build ## Build and install into the local Terraform plugin directory.
mkdir -p $(PLUGIN_DIR)
cp $(BINARY) $(PLUGIN_DIR)/
clean: ## Remove build and coverage artefacts.
rm -f $(BINARY) coverage.out coverage.html
fmt: ## Format Go and Terraform sources.
gofmt -w .
@command -v terraform >/dev/null 2>&1 && terraform fmt -recursive examples/ || \
echo "terraform not found; skipped formatting examples/"
vet: ## Run go vet.
go vet ./...
lint: ## Run golangci-lint. Must report 0 issues.
golangci-lint run ./...
test: ## Run unit tests. No Docker required.
go test ./... -timeout 120s
test-coverage: ## Run unit tests and report total coverage.
go test ./... -timeout 120s -coverprofile=coverage.out
@go tool cover -func=coverage.out | tail -1
@go tool cover -html=coverage.out -o coverage.html
@echo "HTML report: coverage.html"
testacc: ## Run acceptance tests. Creates real clusters; needs Docker.
TF_ACC=1 go test ./... -v -timeout 120m
generate: ## Regenerate docs/. Run after any schema or example change.
@command -v terraform >/dev/null 2>&1 && terraform fmt -recursive examples/ || true
$(TOOLS) github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate \
--provider-dir .. -provider-name $(NAME)
docs: generate ## Alias for generate.
tidy: ## Tidy both Go modules.
go mod tidy
cd tools && go mod tidy
check: fmt vet lint test ## Everything a pull request must pass, except acceptance tests.
@echo "OK: formatted, vetted, linted, tested."
all: check generate build ## Full local build.