-
Notifications
You must be signed in to change notification settings - Fork 13
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 #1 from rackspace-infrastructure-automation/circleci
Adding CircleCI.
- Loading branch information
Showing
10 changed files
with
267 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
WORKING_DIR=$(pwd) | ||
WORKSPACE_DIR="$WORKING_DIR/workspace" | ||
LAYERS_DIR="$WORKING_DIR/layers" | ||
|
||
if [ -f "$WORKSPACE_DIR/changed_layers" ]; then | ||
LAYERS=$(cat "$WORKSPACE_DIR/changed_layers" | sort -n) | ||
else | ||
LAYERS=$(find "$LAYERS_DIR"/* -type d -maxdepth 0 -exec basename '{}' \; | sort -n) | ||
fi | ||
|
||
for LAYER in $LAYERS; do | ||
# for debugging, show that these files exist | ||
ls -la "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz" | ||
ls -la "$WORKSPACE_DIR/terraform.$LAYER.plan" | ||
|
||
# uncache .terraform for the apply | ||
(cd "$LAYERS_DIR/$LAYER" && tar xzf "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz") | ||
|
||
echo "terraform apply $LAYER" | ||
(cd "$LAYERS_DIR/$LAYER" && terraform apply -input=false -no-color "$WORKSPACE_DIR/terraform.$LAYER.plan") | ||
done |
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,32 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# standard paths | ||
WORKING_DIR=$(pwd) | ||
WORKSPACE_DIR="$WORKING_DIR/workspace" | ||
LAYERS_DIR="$WORKING_DIR/layers" | ||
LAYERS=$(find "$LAYERS_DIR"/* -type d -maxdepth 0 -exec basename '{}' \; | sort -n) | ||
|
||
# be sure we know about the latest remote refs | ||
git fetch origin | ||
MASTER_REF=$(git rev-parse remotes/origin/master) | ||
|
||
# in the last hundred commits, is one of the parents in the current master? | ||
git log --pretty=format:'%H' -n 100 | grep -q "$MASTER_REF" | ||
UPTODATE=$? | ||
|
||
if [ $UPTODATE -ne 0 ] | ||
then | ||
echo "Your branch is not up to date. Exiting." | ||
fi | ||
|
||
if [ -f "$WORKSPACE_DIR/changed_layers" ]; then | ||
CHANGED_LAYERS=$(cat "$WORKSPACE_DIR/changed_layers") | ||
else | ||
CHANGED_LAYERS=$(git diff --name-only "$MASTER_REF" -- "$LAYERS_DIR" | awk -F "/" '{print $2}' | sort -n | uniq) | ||
echo $CHANGED_LAYERS > "$WORKSPACE_DIR/changed_layers" | ||
fi | ||
|
||
echo "Changed layers: " | ||
echo $CHANGED_LAYERS |
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 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
WORKING_DIR=$(pwd) | ||
WORKSPACE_DIR="$WORKING_DIR/workspace" | ||
LAYERS_DIR="$WORKING_DIR/layers" | ||
|
||
if [ -f "$WORKSPACE_DIR/changed_layers" ]; then | ||
LAYERS=$(cat "$WORKSPACE_DIR/changed_layers" | sort -nr) | ||
else | ||
LAYERS=$(find "$LAYERS_DIR"/* -type d -maxdepth 0 -exec basename '{}' \; | sort -nr) | ||
fi | ||
|
||
for LAYER in $LAYERS; do | ||
# for debugging, show that these files exist | ||
ls -la "$LAYERS_DIR/$LAYER/terraform.tfstate" | ||
|
||
# uncache .terraform for the destroy | ||
(cd "$LAYERS_DIR/$LAYER" && tar xzf "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz" || echo "Did not find a cached .terraform directory") | ||
|
||
echo "terraform destroy $LAYER" | ||
(cd "$LAYERS_DIR/$LAYER" && terraform destroy -refresh=false -auto-approve) | ||
done |
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,27 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
WORKING_DIR=$(pwd) | ||
LAYERS_DIR="$WORKING_DIR/layers" | ||
LAYERS=$(find "$LAYERS_DIR"/* -type d -maxdepth 0 -exec basename '{}' \; | sort -n) | ||
|
||
OVERALL_RETURN=0 | ||
for LAYER in $LAYERS; do | ||
echo "terraform fmt $LAYER" | ||
|
||
LINT_OUTPUT=$(cd "$LAYERS_DIR/$LAYER" && terraform fmt -check=true -write=false -diff=false -list=true) | ||
LINT_RETURN=$? | ||
|
||
if [ $LINT_RETURN -ne 0 ] | ||
then | ||
echo "Linting failed in $LAYER, please run terraform fmt" | ||
echo $LINT_OUTPUT | ||
OVERALL_RETURN=1 | ||
fi | ||
done | ||
|
||
if [ $OVERALL_RETURN -ne 0 ] | ||
then | ||
exit $OVERALL_RETURN | ||
fi |
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,28 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
WORKING_DIR=$(pwd) | ||
WORKSPACE_DIR="$WORKING_DIR/workspace" | ||
LAYERS_DIR="$WORKING_DIR/layers" | ||
|
||
if [ -f "$WORKSPACE_DIR/changed_layers" ]; then | ||
LAYERS=$(cat "$WORKSPACE_DIR/changed_layers") | ||
else | ||
LAYERS=$(find "$LAYERS_DIR"/* -type d -maxdepth 0 -exec basename '{}' \; | sort -n) | ||
fi | ||
|
||
for LAYER in $LAYERS; do | ||
echo "terraform init $LAYER" | ||
(cd "$LAYERS_DIR/$LAYER" && terraform init -input=false -no-color) | ||
|
||
# cache .terraform during the plan | ||
(cd "$LAYERS_DIR/$LAYER" && tar -czf "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz" .terraform) | ||
|
||
echo "terraform plan $LAYER" | ||
(cd "$LAYERS_DIR/$LAYER" && terraform plan -no-color -input=false -out="$WORKSPACE_DIR/terraform.$LAYER.plan" | tee "$WORKSPACE_DIR/full_plan_output.log" | grep -v "Refreshing state" ) | ||
|
||
# for debugging, show these files exist | ||
ls -la "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz" | ||
ls -la "$WORKSPACE_DIR/terraform.$LAYER.plan" | ||
done |
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,28 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
WORKING_DIR=$(pwd) | ||
WORKSPACE_DIR="$WORKING_DIR/workspace" | ||
LAYERS_DIR="$WORKING_DIR/layers" | ||
LAYERS=$(find "$LAYERS_DIR"/* -type d -maxdepth 0 -exec basename '{}' \; | sort -n) | ||
|
||
OVERALL_RETURN=0 | ||
for LAYER in $LAYERS; do | ||
echo "terraform validate $LAYER" | ||
|
||
VALIDATE_OUTPUT=$(cd "$LAYERS_DIR/$LAYER" && terraform validate -input=false -check-variables=false -no-color .) | ||
VALIDATE_RETURN=$? | ||
|
||
if [ $VALIDATE_RETURN -ne 0 ] | ||
then | ||
echo "Validate failed in $LAYER, please run terraform validate" | ||
echo $VALIDATE_OUTPUT | ||
OVERALL_RETURN=1 | ||
fi | ||
done | ||
|
||
if [ $OVERALL_RETURN -ne 0 ] | ||
then | ||
exit $OVERALL_RETURN | ||
fi |
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,40 @@ | ||
version: 2 | ||
jobs: | ||
test: | ||
docker: | ||
- image: hashicorp/terraform:0.11.7 | ||
steps: | ||
- checkout: | ||
path: ~/module | ||
- run: mkdir -p ~/workspace | ||
- run: cp -pr ~/module/.circleci/bin ~/bin | ||
- run: mv ~/module/tests/ ~/layers/ # Move tests into layers directory | ||
- run: | ||
name: lint tests | ||
command: cd ~ && ~/bin/lint.sh | ||
- run: mkdir -p ~/example_lint/layers/ && mv ~/module/examples/ ~/example_lint/layers/ | ||
- run: | ||
name: lint examples | ||
command: cd ~/example_lint && ~/bin/lint.sh | ||
- run: mkdir -p ~/module_lint/layers/ && cp -pr ~/module/ ~/module_lint/layers/module/ | ||
- run: | ||
name: lint module | ||
command: cd ~/module_lint && ~/bin/lint.sh | ||
- run: | ||
name: plan | ||
command: cd ~ && ~/bin/plan.sh | ||
- run: | ||
name: apply | ||
command: cd ~ && ~/bin/apply.sh | ||
- run: | ||
name: destroy | ||
command: cd ~ && ~/bin/destroy.sh # must succeed or we have something to clean up manually | ||
|
||
workflows: | ||
version: 2 | ||
build_and_test: | ||
jobs: | ||
- test: | ||
filters: | ||
branches: | ||
ignore: master |
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,7 +1,18 @@ | ||
provider "aws" { | ||
version = "~> 1.2" | ||
region = "us-west-2" | ||
} | ||
|
||
resource "random_string" "s3_rstring" { | ||
length = 18 | ||
upper = false | ||
special = false | ||
} | ||
|
||
module "s3" { | ||
source = "path/to/module" | ||
source = "[email protected]:rackspace-infrastructure-automation/aws-terraform-s3//?ref=v0.0.1" | ||
|
||
bucket_name = "<bucket_name>" | ||
bucket_name = "${random_string.s3_rstring.result}-example-s3-bucket" | ||
|
||
bucket_acl = "bucket-owner-full-control" | ||
|
||
|
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,49 @@ | ||
provider "aws" { | ||
version = "~> 1.2" | ||
region = "us-west-2" | ||
} | ||
|
||
resource "random_string" "s3_rstring" { | ||
length = 18 | ||
upper = false | ||
special = false | ||
} | ||
|
||
module "s3" { | ||
source = "../../module" | ||
|
||
bucket_name = "${random_string.s3_rstring.result}-example-s3-bucket" | ||
|
||
bucket_acl = "bucket-owner-full-control" | ||
|
||
bucket_logging = false | ||
|
||
bucket_tags = { | ||
RightSaid = "Fred" | ||
LeftSaid = "George" | ||
} | ||
|
||
environment = "Development" | ||
|
||
lifecycle_enabled = true | ||
|
||
noncurrent_version_expiration_days = "425" | ||
|
||
noncurrent_version_transition_glacier_days = "60" | ||
|
||
noncurrent_version_transition_ia_days = "30" | ||
|
||
object_expiration_days = "425" | ||
|
||
transition_to_glacier_days = "60" | ||
|
||
transition_to_ia_days = "30" | ||
|
||
versioning = true | ||
|
||
website = true | ||
|
||
website_error = "error.html" | ||
|
||
website_index = "index.html" | ||
} |