diff --git a/CHANGELOG.md b/CHANGELOG.md index 5631059..711ba35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/tests/empty_layer.bats b/tests/empty_layer.bats index 72c9d9e..e15266b 100644 --- a/tests/empty_layer.bats +++ b/tests/empty_layer.bats @@ -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" ] diff --git a/toolbox/bin/apply.sh b/toolbox/bin/apply.sh index e967858..3832d44 100755 --- a/toolbox/bin/apply.sh +++ b/toolbox/bin/apply.sh @@ -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" diff --git a/toolbox/bin/variables.sh b/toolbox/bin/variables.sh index 1176240..cb9f47e 100755 --- a/toolbox/bin/variables.sh +++ b/toolbox/bin/variables.sh @@ -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'