-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nirdosh17/release_v1.0.0
- Allow `MAX_DELETE_RETRY_COUNT` and `STACK_WAIT_TIME_SECONDS` to be configurable - Add Integration tests
- Loading branch information
Showing
19 changed files
with
580 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
stack_teardown_details.json | ||
cfn-teardown | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
.DEFAULT_GOAL=help | ||
|
||
build: ## Download packages and build binary | ||
build: ## install deps and build binary | ||
go mod download && \ | ||
go build -o cfn-teardown . | ||
|
||
run: build ## Build and run binary | ||
run: build ## build and run binary | ||
./cfn-teardown | ||
|
||
# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | ||
test.start: test.stop ## start integration test | ||
docker build --platform linux/amd64 -t cfn-teardown-test -f test/Dockerfile . | ||
docker compose -f test/docker-compose.yaml up --abort-on-container-exit --remove-orphans | ||
|
||
test.stop: ## stop integration test | ||
docker compose -f test/docker-compose.yaml down | ||
|
||
help: | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
@sed -ne '/@sed/!s/## //p' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ": "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM ubuntu | ||
|
||
ARG GO_VERSION=1.22.0 | ||
|
||
RUN set -ex \ | ||
&& apt-get update \ | ||
&& apt-get install wget git python3 python3-pip unzip jq -y | ||
|
||
RUN wget -q -o /dev/null "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" \ | ||
&& unzip awscli-exe-linux-x86_64.zip -d /awscli > /dev/null \ | ||
&& ./awscli/aws/install | ||
|
||
WORKDIR /usr/local | ||
RUN wget -q -o /dev/null https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz | ||
RUN tar -xzf go$GO_VERSION.linux-amd64.tar.gz | ||
ENV GOROOT=/usr/local/go | ||
ENV GOPATH=/root/go | ||
ENV PATH=${GOROOT}/bin:${GOPATH}/bin:${PATH} | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
CMD ["sh", "-c", "/app/test/test_runner.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
LOCALSTACK_ENDPOINT="${LOCALSTACK_ENDPOINT:-'http://localhost:4566'}" | ||
|
||
ARGS="--endpoint-url $LOCALSTACK_ENDPOINT --region us-east-1" | ||
ENV_NAME="test" | ||
VPC_STACK_NAME=$ENV_NAME-vpc | ||
DDB_STACK_NAME=$ENV_NAME-dynamodb | ||
LAMBDA_STACK_NAME=$ENV_NAME-lambda | ||
|
||
TEMPLATES_FOLDER="test/templates" | ||
|
||
echo "--- test stacks creation started ---" | ||
|
||
aws cloudformation create-stack --stack-name $VPC_STACK_NAME --template-body file://$TEMPLATES_FOLDER/vpc.yaml $ARGS > /dev/null | ||
aws cloudformation wait stack-create-complete --stack-name $VPC_STACK_NAME $ARGS | ||
echo "vpc created!" | ||
|
||
aws cloudformation create-stack --stack-name $DDB_STACK_NAME --template-body file://$TEMPLATES_FOLDER/dynamodb.yaml $ARGS > /dev/null | ||
aws cloudformation wait stack-create-complete --stack-name $DDB_STACK_NAME $ARGS | ||
echo "dynamodb created!" | ||
|
||
aws cloudformation create-stack --stack-name $LAMBDA_STACK_NAME --template-body file://$TEMPLATES_FOLDER/lambda.yaml $ARGS > /dev/null | ||
aws cloudformation wait stack-create-complete --stack-name $LAMBDA_STACK_NAME $ARGS | ||
echo "lambda created!" | ||
|
||
echo "--- test stacks created! ---" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
services: | ||
cfn-teardown-test: | ||
container_name: cfn-teardown-test | ||
image: cfn-teardown-test | ||
depends_on: | ||
- localstack | ||
environment: | ||
- LOCALSTACK_ENDPOINT=http://localstack:4566 | ||
|
||
localstack: | ||
container_name: localstack-main | ||
image: localstack/localstack | ||
# ports: | ||
# - "127.0.0.1:4566:4566" # LocalStack Gateway | ||
# - "127.0.0.1:4510-4559:4510-4559" # external services port range | ||
environment: | ||
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/ | ||
- DEBUG=${DEBUG:-0} | ||
volumes: | ||
# - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" | ||
# Mounting the Docker socket /var/run/docker.sock as a volume is required | ||
# for some services that use Docker to provide the emulation, such as AWS Lambda. | ||
- "/var/run/docker.sock:/var/run/docker.sock" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo "setting up aws configs.." | ||
mkdir -p ~/.aws | ||
|
||
echo "[default] | ||
region = us-east-1" > ~/.aws/config | ||
|
||
echo "[default] | ||
aws_access_key_id = randomstringforlocalstack | ||
aws_secret_access_key = randomstringforlocalstack" > ~/.aws/credentials | ||
echo "aws configs written!" | ||
|
||
echo "creating test config for cli..." | ||
echo "AWS_REGION: us-east-1 | ||
AWS_PROFILE: default | ||
STACK_PATTERN: test- | ||
ENDPOINT_URL: http://localstack:4566 | ||
ABORT_WAIT_TIME_MINUTES: 0 | ||
STACK_WAIT_TIME_SECONDS: 2" > ~/.cfn-teardown.yaml | ||
echo "configs written at: ~/.cfn-teardown.yaml" | ||
|
||
echo "building binary..." | ||
make build | ||
echo "binary built!" | ||
|
||
echo "creating test stacks..." | ||
./test/create_test_stacks.sh | ||
echo "stacks created!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Description: Dynamodb table | ||
Parameters: | ||
EnvironmentName: | ||
Type: String | ||
Description: Environment label e.g. dev, test, prod | ||
Default: test | ||
DynamoDBTableName: | ||
Type: String | ||
Description: The name of the DynamoDB table to be deployed | ||
Default: DynamoDB-Table-CFNExample | ||
DynamoDBPKName: | ||
Type: String | ||
Description: The name of the primary key that will exist in the DynamoDB table | ||
Default: itemId | ||
|
||
Resources: | ||
DynamoDBTable: | ||
Type: AWS::DynamoDB::Table | ||
Properties: | ||
BillingMode: PROVISIONED | ||
ProvisionedThroughput: | ||
ReadCapacityUnits: 5 | ||
WriteCapacityUnits: 5 | ||
AttributeDefinitions: | ||
- | ||
AttributeName: !Ref DynamoDBPKName | ||
AttributeType: "S" | ||
KeySchema: | ||
- | ||
AttributeName: !Ref DynamoDBPKName | ||
KeyType: HASH | ||
TableName: !Ref DynamoDBTableName | ||
Tags: | ||
- Key: cfnteardown | ||
Value: true | ||
|
||
Outputs: | ||
DynamoDBTableName: | ||
Description: Dynamodb table name | ||
Value: !Ref DynamoDBTable | ||
Export: | ||
Name: !Join [ ':', [ !Ref EnvironmentName, DynamoDBTableName ] ] | ||
DynamoDBPKName: | ||
Description: Dynamodb table Primary Key | ||
Value: !Ref DynamoDBPKName | ||
Export: | ||
Name: !Join [ ':', [ !Ref EnvironmentName, DynamoDBPKName ] ] |
Oops, something went wrong.