#!/usr/bin/env bash THISDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${THISDIR}/common.sh" # Default ECS cluster name DEFAULT_CLUSTER_NAME="ecs-updater-integ-cluster" # Default number of instances to launch in the cluster DEFAULT_INSTANCE_COUNT=10 # Default instance type for instances in the cluster DEFAULT_INSTANCE_TYPE="m5.xlarge" # Helper functions usage() { cat >&2 <&2 usage exit 2 ;; esac shift done INSTANCE_TYPE="${INSTANCE_TYPE:-$DEFAULT_INSTANCE_TYPE}" INSTANCE_COUNT="${INSTANCE_COUNT:-$DEFAULT_INSTANCE_COUNT}" CLUSTER_STACK_NAME="${CLUSTER_STACK_NAME:-$DEFAULT_CLUSTER_NAME}" # Required arguments required_arg "--ami-id" "${AMI_ID}" } # Initial setup and checks parse_args "${@}" # deploy stack to create integ resources log INFO "Deploying stack template '${INTEG_STACK_TEMPLATE}'" if ! aws cloudformation deploy \ --stack-name "${INTEG_STACK_NAME}" \ --template-file "${THISDIR}/stacks/${INTEG_STACK_TEMPLATE}" \ --capabilities CAPABILITY_NAMED_IAM; then log ERROR "Failed to deploy '${INTEG_STACK_TEMPLATE}' stack template" exit 1 fi log INFO "Stack template '${INTEG_STACK_TEMPLATE}' deployed with name '${INTEG_STACK_NAME}'" # deploy stack to start ecs cluster using auto-scaling group log INFO "Deploying stack template '${CLUSTER_STACK_TEMPLATE}' to set up an ECS cluster" if ! aws cloudformation deploy \ --stack-name "${CLUSTER_STACK_NAME}" \ --template-file "${THISDIR}/stacks/${CLUSTER_STACK_TEMPLATE}" \ --capabilities CAPABILITY_NAMED_IAM \ --parameter-overrides \ IntegSharedResourceStack="${INTEG_STACK_NAME}" \ InstanceCount="${INSTANCE_COUNT}" \ ImageID="${AMI_ID}" \ InstanceType="${INSTANCE_TYPE}"; then log ERROR "Failed to deploy stack '${CLUSTER_STACK_TEMPLATE}' stack template" exit 1 fi log INFO "ECS cluster '${CLUSTER_STACK_NAME}' with '${INSTANCE_COUNT}' instances and instance type '${INSTANCE_TYPE}' created!"