Skip to content

Commit

Permalink
upgrade terraform version to 1.4.5 and refactored kitchen test (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
babuharidass authored Jun 20, 2023
1 parent 02e26ee commit 7d2e7ec
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.4.5
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,58 @@ git-hooks: ## Set up hooks in .githooks

.PHONY: test
test: ## Build, test, and destroy default scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "test default --destroy=always"
@ci/scripts/run-kitchen.sh --action test --args "default --destroy=always"

.PHONY: test-hybrid-external-database
test-hybrid-external-database: ## Build, test, and destroy hybrid-external-database scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "test hybrid-external-database --destroy=always"
@ci/scripts/run-kitchen.sh --action test --args "hybrid-external-database --destroy=always"

.PHONY: build
build: ## Build default scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "test default converge"
@ci/scripts/run-kitchen.sh --action test --args "default converge"

.PHONY: build-al
build-al: ## Build hybrid_amazon_linux scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "converge hybrid-amazon-linux"
@ci/scripts/run-kitchen.sh --action converge --args "hybrid-amazon-linux"

.PHONY: verify-al
verify-al: ## Verify hybrid_amazon_linux scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "verify hybrid-amazon-linux"
@ci/scripts/run-kitchen.sh --action verify --args "hybrid-amazon-linux"

.PHONY: destroy-al
destroy-al: ## Destroy hybrid_amazon_linux scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "destroy hybrid-amazon-linux"
@ci/scripts/run-kitchen.sh --action destroy --args "hybrid-amazon-linux"

.PHONY: test-al
test-al: ## Test hybrid_amazon_linux scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "test hybrid-amazon-linux --destroy=always"
@ci/scripts/run-kitchen.sh --action test --args "hybrid-amazon-linux --destroy=always"

.PHONY: build-ecs
build-ecs: ## Build hybrid_ecs scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "converge hybrid-ecs"
@ci/scripts/run-kitchen.sh --action converge --args "hybrid-ecs"

.PHONY: verify-ecs
verify-ecs: ## Verify hybrid_ecs scenario with Kitchen Terraform
@if [ -z '${KONG_EE_LICENSE}' ]; then echo "You must set the KONG_EE_LICENSE variable with a valid license before running this step." ; exit 1 ; fi
@docker run --rm -e AWS_PROFILE=default -e KONG_EE_LICENSE='${KONG_EE_LICENSE}' -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "verify hybrid-ecs"
@ci/scripts/run-kitchen.sh --action verify --args "hybrid-ecs"

.PHONY: destroy-ecs
destroy-ecs: ## Destroy hybrid_ecs scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "destroy hybrid-ecs"
@ci/scripts/run-kitchen.sh --action destroy --args "hybrid-ecs"

.PHONY: test-ecs
test-ecs: ## Test hybrid_ecs scenario with Kitchen Terraform
@if [ -z '${KONG_EE_LICENSE}' ]; then echo "You must set the KONG_EE_LICENSE variable with a valid license before running this step." ; exit 1 ; fi
@docker run --rm -e AWS_PROFILE=default -e KONG_EE_LICENSE='${KONG_EE_LICENSE}' -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "test hybrid-ecs --destroy=always"
@ci/scripts/run-kitchen.sh --action test --args "hybrid-ecs --destroy=always"

.PHONY: build-hybrid-external-database
build-hybrid-external-database: ## Test hybrid-external-database scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "converge hybrid-external-database"
@ci/scripts/run-kitchen.sh --action converge --args "hybrid-external-database"

.PHONY: destroy
destroy: ## Build default scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "test default destroy"
@ci/scripts/run-kitchen.sh --action test --args "default destroy"

.PHONY: destroy-hybrid-external-database
destroy-hybrid-external-database: ## Destroy hybrid-external-database scenario with Kitchen Terraform
docker run --rm -e AWS_PROFILE=default -v $(shell pwd):/usr/action -v ~/.aws:/root/.aws -v /etc/ssl/certs/:/usr/local/share/ca-certificates/ quay.io/dwp/kitchen-terraform:0.14.7 "destroy hybrid-external-database"
@ci/scripts/run-kitchen.sh --action destroy --args "hybrid-external-database"
55 changes: 55 additions & 0 deletions ci/scripts/run-kitchen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
DEFAULT_KITCHEN_TERRAFORM_TAG=2.0.1

# Parse parameters
while [[ "$#" > 0 ]]; do case $1 in
--tag) TAG="$2"; shift; shift;;
--aws-profile) AWS_PROFILE="$2"; shift; shift;;
--action) ACTION="$2"; shift; shift;;
--args) ARGS="$2"; shift; shift;;
*) usage "Unknown parameter passed: $1"; shift; shift;;
esac; done

# Default version of Terraform when not specified a tag
TAG="${TAG:-$DEFAULT_KITCHEN_TERRAFORM_TAG}"
IMAGE="quay.io/dwp/kitchen-terraform:${TAG}"

# Default AWS Profile
AWS_PROFILE="${AWS_PROFILE:-"default"}"

printf "\n*************************************************************\n"
printf " Running Kitchen Terraform using the following parameters:\n"
printf " %-22s %s\n" "- Terraform version:" $TAG
printf " %-22s %s\n" "- AWS Profile:" $AWS_PROFILE
printf " %-22s %s\n" "- Kitchen action:" ${ACTION:-"(not set)"}
printf " %-22s %s\n" "- Kitchen arguments:" ${ARGS:-"(not set)"}
printf "*************************************************************\n\n"

if [[ -n "$ACTION" ]]; then

if [[ ${ACTION} == "debug" ]]; then
docker run -ti --rm \
--env AWS_PROFILE=$AWS_PROFILE \
--env CUSTOM_CA_DIR=/usr/share/ca-certificates/custom \
--volume /etc/ssl/certs/:/usr/share/ca-certificates/custom \
--volume $(pwd):/usr/action \
--volume ~/.aws:/root/.aws \
--user root \
--workdir /usr/action/ \
--entrypoint bash \
${IMAGE}
else
docker run --rm \
--env AWS_PROFILE=$AWS_PROFILE \
$(if [[ ${ARGS} == *"ecs"* && -n ${KONG_EE_LICENSE} && ${ACTION} == "verify" || ${ACTION} == "test" ]]; then echo "--env KONG_EE_LICENSE=${KONG_EE_LICENSE}"; fi) \
--env CUSTOM_CA_DIR=/usr/share/ca-certificates/custom \
--volume /etc/ssl/certs/:/usr/share/ca-certificates/custom \
--volume $(pwd):/usr/action \
--volume ~/.aws:/root/.aws \
--user root \
--workdir /usr/action/ \
${IMAGE} "${ACTION} ${ARGS}"
fi

else
echo "The following arguments are required: \`--action\`."
fi
Empty file removed scripts/run-kitchen.sh
Empty file.

0 comments on commit 7d2e7ec

Please sign in to comment.