This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathMakefile
77 lines (61 loc) · 2.76 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
.PHONY: all checkout docs examples tag test update
TF_DOCS := $(shell which terraform-docs 2> /dev/null)
TF_EXAMPLES := $(shell which terraform-examples 2> /dev/null)
TF_CMD := terraform
PLATFORM := AWS
PROVIDER := aws
LATEST_REF := $(shell curl --silent https://api.github.com/repos/coreos/tectonic-installer/git/refs/heads/master | jq -r '.object.sha')
TAG ?= $(shell curl --silent https://api.github.com/repos/coreos/tectonic-installer/git/refs/tags | jq -r '.[-1].ref' | sed 's|refs/tags/||')
all: update
define terraform-docs
$(if $(TF_DOCS),,$(error "terraform-docs revision >= a8b59f8 is required (https://github.com/segmentio/terraform-docs)"))
@echo '<!-- DO NOT EDIT. THIS FILE IS GENERATED BY THE MAKEFILE. -->' > $1
@echo '# Terraform variables' >> $1
@echo $2 >> $1
terraform-docs --no-required markdown $3 $4 $5 $6 >> $1
endef
define terraform-examples
$(if $(TF_EXAMPLES),,$(error "terraform-examples revision >= 83d7ad6 is required (https://github.com/s-urbaniak/terraform-examples)"))
@echo '# DO NOT EDIT. THIS FILE IS GENERATED BY THE MAKEFILE.' > $1
@echo 'module "kubernetes" {' >> $1
@echo ' source = "coreos/kubernetes/$(PROVIDER)"' >> $1
terraform-examples $2 $3 $4 $5 >> $1
@echo '}' >> $1
@terraform fmt $1
endef
docs:
$(call terraform-docs, variables.md, \
'This document gives an overview of variables used in the $(PLATFORM) platform of the Tectonic SDK.', \
config.tf, variables.tf)
examples:
@mkdir -p examples
$(call terraform-examples, \
examples/kubernetes.tf, \
config.tf, \
variables.tf)
# This target is used by the GitHub PR checker to validate canonical syntax on all files.
test:
$(eval FMT_ERR := $(shell terraform fmt -list -write=false .))
@if [ "$(FMT_ERR)" != "" ]; then echo "misformatted files (run 'terraform fmt .' to fix):" $(FMT_ERR); exit 1; fi
@if $(MAKE) docs && ! git diff --exit-code; then echo "outdated docs (run 'make docs' to fix)"; exit 1; fi
@if $(MAKE) examples && ! git diff --exit-code; then echo "outdated examples (run 'make examples' to fix)"; exit 1; fi
build/%:
@rm -f *.tf
@curl -L https://github.com/coreos/tectonic-installer/archive/$(@F).tar.gz -O
@tar -xzf $(@F).tar.gz --strip=3 tectonic-installer-$(@F)/platforms/$(shell echo $(PLATFORM) | tr A-Z a-z)
@tar -xzf $(@F).tar.gz --strip=1 tectonic-installer-$(@F)/config.tf
@rm $(@F).tar.gz
@sed -i 's|source\s\+=\s"[\./]\+\(/modules/.\+\)"|source = "github.com/coreos/tectonic-installer/\1?ref=$(@F)"|' *.tf
@terraform fmt .
orphan/%:
@git checkout --orphan $(@F)
checkout:
@git checkout master
ref/%: | checkout orphan/% build/%;
update: | checkout build/$(LATEST_REF) docs examples
@git add .
@git commit -m "bump master to: $(LATEST_REF)"
tag: | ref/$(TAG) docs examples
@git add .
@git commit -m "$(TAG)"
@git tag -s -m "$(TAG)" "$(TAG)"