Skip to content

Commit

Permalink
Add 'make dev-aws-nuke' target, add support for nuking AWS resources …
Browse files Browse the repository at this point in the history
…in test

Instead of using cloud-nuke as a library, add a cloud-nuke Makefile
target so users can take advantage of cloud-nuke filtering for dev work
outside of test.

Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Aug 22, 2024
1 parent dd23dfc commit ed5c462
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 10 deletions.
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ KIND_NETWORK ?= kind
REGISTRY_NAME ?= hmc-local-registry
REGISTRY_PORT ?= 5001
REGISTRY_REPO ?= oci://127.0.0.1:$(REGISTRY_PORT)/charts
CLUSTER_NAME ?= $(shell $(YQ) '.metadata.name' ./config/dev/deployment.yaml)

AWS_CREDENTIALS=${AWS_B64ENCODED_CREDENTIALS}

Expand Down Expand Up @@ -275,15 +276,21 @@ dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-aws
dev-destroy: kind-undeploy registry-undeploy

.PHONY: dev-aws-apply
dev-aws-apply:
dev-aws-apply: ## Apply the AWS deployment
$(KUBECTL) -n $(NAMESPACE) apply -f config/dev/deployment.yaml

.PHONY: dev-aws-destroy
dev-aws-destroy:
dev-aws-destroy: ## Delete the AWS deployment
$(KUBECTL) -n $(NAMESPACE) delete -f config/dev/deployment.yaml

.PHONY: dev-aws-nuke
dev-aws-nuke: ## Warning: Destructive! Nuke all AWS resources deployed by 'dev-aws-apply', prefix with CLUSTER_NAME to nuke a specific cluster.
@CLUSTER_NAME=$(CLUSTER_NAME) envsubst < config/dev/cloud_nuke.yaml.tpl > config/dev/cloud_nuke.yaml
$(CLOUDNUKE) aws --region us-west-2 --force --config config/dev/cloud_nuke.yaml --resource-type vpc,eip,nat-gateway,ec2-subnet,internet-gateway,network-interface,security-group
@rm config/dev/cloud_nuke.yaml

.PHONY: cli-install
cli-install: clusterawsadm clusterctl
cli-install: clusterawsadm clusterctl cloud-nuke

##@ Dependencies

Expand Down Expand Up @@ -312,6 +319,7 @@ KIND ?= $(LOCALBIN)/kind-$(KIND_VERSION)
YQ ?= $(LOCALBIN)/yq-$(YQ_VERSION)
CLUSTERAWSADM ?= $(LOCALBIN)/clusterawsadm
CLUSTERCTL ?= $(LOCALBIN)/clusterctl
CLOUDNUKE ?= $(LOCALBIN)/cloud-nuke
ADDLICENSE ?= $(LOCALBIN)/addlicense-$(ADDLICENSE_VERSION)

## Tool Versions
Expand All @@ -321,6 +329,7 @@ GOLANGCI_LINT_VERSION ?= v1.60.1
HELM_VERSION ?= v3.15.1
KIND_VERSION ?= v0.23.0
YQ_VERSION ?= v4.44.2
CLOUDNUKE_VERSION = v0.37.1
CLUSTERAWSADM_VERSION ?= v2.5.2
CLUSTERCTL_VERSION ?= v1.7.3
ADDLICENSE_VERSION ?= v1.1.1
Expand Down Expand Up @@ -372,6 +381,12 @@ yq: $(YQ) ## Download yq locally if necessary.
$(YQ): | $(LOCALBIN)
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,${YQ_VERSION})

.PHONY: cloud-nuke
cloud-nuke: $(CLOUDNUKE) ## Download cloud-nuke locally if necessary.
$(CLOUDNUKE): | $(LOCALBIN)
curl -sL https://github.com/gruntwork-io/cloud-nuke/releases/download/$(CLOUDNUKE_VERSION)/cloud-nuke_$(OS)_$(ARCH) -o $(CLOUDNUKE)
chmod +x $(CLOUDNUKE)

.PHONY: clusterawsadm
clusterawsadm: $(CLUSTERAWSADM) ## Download clusterawsadm locally if necessary.
$(CLUSTERAWSADM): | $(LOCALBIN)
Expand Down
Loading

0 comments on commit ed5c462

Please sign in to comment.