-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.cloudformation.mk
108 lines (88 loc) · 3.09 KB
/
Makefile.cloudformation.mk
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Makefile.cloudformation.mk:
#
# DESCRIPTION:
# A makefile suitable for including in a parent makefile, smoothing various
# Cloudformation workflows and usage patterns. This automation makes
# extensive use of [iidy](https://github.com/unbounce/iidy)
#
# REQUIRES: (system tools)
# * iidy, awscli
#
# DEPENDS: (other makefiles)
# * Makefile.base.mk
#
# INTERFACE: (primary targets intended for export; see usage examples)
# STANDARD TARGETS: (communicate with env-vars or make-vars)
# * `placeholder`: placeholder description
# PIPED TARGETS: (stdin->stdout)
# * `placeholder`: placeholder description
# * `placeholder`: placeholder description
# * `placeholder`: placeholder description
# MAKE-FUNCTIONS:
# * `placeholder`: placeholder description
DEFAULT_CHANGE_SET_NAME := changeSetOut
AWS_DEFAULT_REGION ?= us-east-1
# we use iidy directly and assume it's
# on the $PATH already if nothing is set
IIDY_EXEC ?= AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} iidy
# static-analysis: show usage of `ImportValue`
cf-describe-imports: require-ack assert-path
ack "Fn::ImportValue" $$path
cf-validate: assert-path
$(call _announce_target, $@)
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} \
aws cloudformation validate-template --template-body=file://$$path
cf-exports:
$(call _announce_target, $@)
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} \
aws cloudformation list-exports
require-iidy:
@${IIDY_EXEC} --version
##
# iidy-.* targets.
##
iidy-history: iidy-events
iidy-events: require-iidy assert-stack
${IIDY_EXEC} watch-stack $${stack}
iidy-init: assert-argfile
ls $(value argfile)
$(eval STACK_ARGFILE := $(value argfile))
$(eval STACK_NAME := $(shell cat ${STACK_ARGFILE}|shyaml get-value StackName))
export STACK_ARGFILE STACK_NAME
iidy-cs: iidy-init
${IIDY_EXEC} create-changeset ${STACK_ARGFILE} ${DEFAULT_CHANGE_SET_NAME}
iidy-create: iidy-init
$(call _announce_target, $@)
${IIDY_EXEC} create-stack ${STACK_ARGFILE}
iidy-update: iidy-init
$(call _announce_target, $@)
${IIDY_EXEC} update-stack ${STACK_ARGFILE}
iidy-delete: iidy-init require-shyaml
$(call _announce_target, $@)
stack=`cat ${STACK_ARGFILE}|shyaml get-value StackName` \
make cf-delete-stack
iidy-cs-apply: iidy-init
${IIDY_EXEC} exec-changeset ${STACK_ARGFILE} ${DEFAULT_CHANGE_SET_NAME}
iidy-list-stacks: require-iidy
${IIDY_EXEC} list-stacks
iidy-describe-stack: require-iidy assert-stack
${IIDY_EXEC} describe-stack $$stack
##
# cf-.* targets chaining to iidy for now for improved UX,
# unless there's a real reason to implement them with aws-cli
##
# Operations on change-sets
cf-cs: iidy-cs
cf-cs-apply: iidy-cs-apply
cf-cs-delete: iidy-init
$(call _announce_target, $@)
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} aws cloudformation delete-change-set \
--change-set-name ${DEFAULT_CHANGE_SET_NAME} \
--stack-name ${STACK_NAME} || echo "Could not delete changeset.. maybe does not exist"
# CRUD operations
cf-create: iidy-create
cf-update: iidy-update
cf-delete-stack: assert-stack
aws cloudformation delete-stack --stack-name $(value stack)
cf-list-stacks: iidy-list-stacks
cf-describe-stack: iidy-describe-stack