-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
94 lines (79 loc) · 4.18 KB
/
Makefile
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
86
87
88
89
90
91
92
93
94
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOFMT=gofmt
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOINSTALL=$(GOCMD) install
PROTOC=protoc
# Get latest version (tag). It is important to notice that the following
# commands restricts the build to those git-initialized folders. Thus,
# git clone the provider and run make on the same directory and avoid
# copying the source files to directories not initialized by git.
vVERSION:=$(shell git tag --sort v:refname | tail -n1)
VERSION:=$(shell git tag --sort v:refname | tail -n1 | sed 's/v//g')
VERSION+sha:=$(VERSION)+$(shell git rev-parse --short HEAD)
HOSTNAME=local
NAMESPACE=terraform
NAME=cyral
BINARY=terraform-provider-$(NAME)_$(vVERSION)
SWEEPDIR=./cyral
all: local/clean local/install local/test
notest: local/clean local/install
local/build:
$(GOFMT) -w .
mkdir -p out/
# Build for both MacOS and Linux
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o out/darwin_amd64/$(BINARY) .
GOOS=darwin GOARCH=arm64 $(GOBUILD) -o out/darwin_arm64/$(BINARY) .
GOOS=linux GOARCH=amd64 $(GOBUILD) -o out/linux_amd64/$(BINARY) .
local/install: local/build
# Store in local registry to be used by Terraform 13 and 14
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_arm64
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
cp out/darwin_arm64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_arm64
cp out/linux_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
cp out/darwin_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
docker/test:
docker-compose run -e CYRAL_TF_CONTROL_PLANE=$$CYRAL_TF_CONTROL_PLANE -e CYRAL_TF_CLIENT_ID=$$CYRAL_TF_CLIENT_ID \
-e CYRAL_TF_CLIENT_SECRET=$$CYRAL_TF_CLIENT_SECRET -e TF_ACC=true \
app $(GOTEST) github.com/cyralinc/terraform-provider-cyral/... -v -race
docker/build:
docker-compose run app $(GOFMT) -w .
docker-compose run -e GOOS=darwin -e GOARCH=amd64 app $(GOBUILD) -o out/darwin_amd64/terraform-provider-cyral_v$(VERSION) .
docker-compose run -e GOOS=darwin -e GOARCH=arm64 app $(GOBUILD) -o out/darwin_arm64/terraform-provider-cyral_v$(VERSION) .
docker-compose run -e GOOS=linux -e GOARCH=amd64 app $(GOBUILD) -o out/linux_amd64/terraform-provider-cyral_v$(VERSION) .
# Store in local registry to be used by Terraform 13 and 14
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_arm64
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
cp out/darwin_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_amd64
cp out/darwin_arm64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/darwin_arm64
cp out/linux_amd64/$(BINARY) ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/linux_amd64
clean: local/clean
local/clean:
$(GOCLEAN) -i github.com/cyralinc/terraform-provider-cyral/...
rm -f $(BINARY)
rm -rf ./out
rm -rf ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}
docker/clean:
docker-compose run app $(GOCLEAN) -i github.com/cyralinc/terraform-provider-cyral/...
rm -rf ./out
rm -rf ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}
local/test:
$(GOTEST) github.com/cyralinc/terraform-provider-cyral/... -v -race -timeout 20m
docker-compose/build: docker-compose/lint
docker-compose build --build-arg VERSION="$(VERSION+sha)" build
docker-compose/lint:
docker-compose run lint
docker-compose/docs:
docker-compose run app go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate
#docker-compose run build pre-commit run --show-diff-on-failure --color=always --all-files
sweep:
@echo "WARNING: This will destroy infrastructure. Use only for development control planes."
go test $(SWEEPDIR) -v -sweep=dummy-region $(SWEEPARGS) -timeout 15m
# update module and test dependencies to latest minor and patch level
up-deps:
$(GOGET) -u ./...
$(GOGET) -t ./...