Skip to content

Commit

Permalink
Merge pull request #42 from rackspace-infrastructure-automation/jp/de…
Browse files Browse the repository at this point in the history
…leted_layers

ensure even deleted layers are applicable
  • Loading branch information
jpbochi authored Mar 11, 2019
2 parents 89c357a + 13bb930 commit 0c9c22c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rackspace-toolbox Changelog

## [1.7.4](https://github.com/rackspace-infrastructure-automation/rackspace-toolbox/releases/tag/1.7.4) (Mar 11, 2019)

Ensures both plan and apply succeed when working with deleted layer directories.

## [1.7.3](https://github.com/rackspace-infrastructure-automation/rackspace-toolbox/releases/tag/1.7.3) (Jan 30, 2019)

Ensures changed_layers is always created.
Expand Down
50 changes: 24 additions & 26 deletions tests/empty_layer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@ function teardown() {

@test "plan makes empty layer if layer does not exist" {
mkdir -p ./workspace
printf 'base_network\ndeleted_layer\n' > ./workspace/changed_layers
TEST_LOCAL_REPO=$(pwd)

# ensure base_network looks like a real layer already
mkdir -p layers/base_network

echo '
echo "$@"
if [ "$1" = "init" ]; then
mkdir -p ./.terraform
echo "$@" > ./.terraform/init
elif [ "$1" = "plan" ]; then
for arg in $@; do
if (echo $arg | grep -q "^-out="); then
output=$(echo $arg | sed "s/^-out=//")
pwd > "$output"
cat ./.terraform/init >> "$output"
echo $@ >> "$output"
fi
done
fi
' > $bin_terraform

TF_STATE_BUCKET='le-bucket'
TF_STATE_REGION='le-region'
plan.sh
printf 'deleted_layer\n' > ./workspace/changed_layers

TF_STATE_BUCKET='le-bucket' TF_STATE_REGION='le-region' plan.sh

# ensure the deleted layer was created
[ -d "layers/deleted_layer" ]
[ -d "layers/deleted_layer/.terraform" ]
[ -f "layers/deleted_layer/deleted.tf" ]

# ensure the existing layer didn't have special deleted.tf created
[ ! -f "layers/base_network/deleted.tf" ]
}

@test "apply makes empty layer if layer does not exist" {
mkdir -p ./workspace
printf 'deleted_layer\n' > ./workspace/changed_layers

mkdir .terraform
echo 'init-data' > .terraform/init
tar -czf ./workspace/.terraform.deleted_layer.tar.gz .terraform
rm -r .terraform
echo 'fake-plan' > workspace/terraform.deleted_layer.plan

TF_STATE_BUCKET='le-bucket' TF_STATE_REGION='le-region' apply.sh

# ensure the deleted layer was created
[ -d "layers/deleted_layer" ]
Expand Down
7 changes: 7 additions & 0 deletions toolbox/bin/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ for LAYER in $CHANGED_LAYERS; do
ls -la "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz"
ls -la "$WORKSPACE_DIR/terraform.$LAYER.plan"

# ensure even deleted layers are applyable
if [ ! -d "$LAYERS_DIR/$LAYER" ]; then
echo "> Layer directory $LAYERS_DIR/$LAYER was not found, creating an empty version."
mkdir -p "$LAYERS_DIR/$LAYER/.terraform"
touch "$LAYERS_DIR/$LAYER/deleted.tf"
fi

# uncache .terraform for the apply
cd "$LAYERS_DIR/$LAYER"
tar xzf "$WORKSPACE_DIR/.terraform.$LAYER.tar.gz"
Expand Down
2 changes: 1 addition & 1 deletion toolbox/bin/variables.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env sh
set -eu -o pipefail

echo "Rackspace Toolbox - 1.7.3"
echo "Rackspace Toolbox - 1.7.4"

check_old() {
local fake_hostname='github.com.original.invalid'
Expand Down

0 comments on commit 0c9c22c

Please sign in to comment.