Skip to content

Commit

Permalink
cleaning up pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmiller609 committed Jul 5, 2019
1 parent 34afdab commit 9cb3eb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 64 deletions.
66 changes: 2 additions & 64 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ steps:
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- cp providers.tf.example examples/from_scratch/providers.tf
- cp backend.tf.example examples/from_scratch/backend.tf
- cd examples/from_scratch
- sed -i "s/REPLACE/$DRONE_REPO_NAME$DRONE_BUILD_NUMBER/g" backend.tf
- terraform init
- terraform apply --auto-approve -var "deployment_id=fromscratch$DRONE_REPO_NAME$DRONE_BUILD_NUMBER"
- terraform -v
- EXAMPLE=from_scratch pipeline/run_terraform.sh
when:
event:
- push
Expand All @@ -59,63 +53,7 @@ steps:
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- cp providers.tf.example examples/from_scratch/providers.tf
- cp backend.tf.example examples/from_scratch/backend.tf
- cd examples/from_scratch
- sed -i "s/REPLACE/$DRONE_REPO_NAME$DRONE_BUILD_NUMBER/g" backend.tf
- terraform init
- terraform destroy --auto-approve -var "deployment_id=fromscratch$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" -refresh=false
- terraform -v
when:
event:
- push
status:
- failure
- success
branch:
- master

- name: into_subnets
image: hashicorp/terraform:light
depends_on:
- lint
environment:
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- cp providers.tf.example examples/into_existing_subnets/providers.tf
- cp backend.tf.example examples/into_existing_subnets/backend.tf
- cd examples/into_existing_subnets
- sed -i "s/REPLACE/intosubnets$DRONE_REPO_NAME$DRONE_BUILD_NUMBER/g" backend.tf
- terraform init
- terraform apply --auto-approve -var "deployment_id=intosubnets$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" --target=module.vpc
- terraform apply --auto-approve -var "deployment_id=intosubnets$DRONE_REPO_NAME$DRONE_BUILD_NUMBER"
- terraform -v
when:
event:
- push
branch:
- master

- name: into_subnets_cleanup
depends_on:
- into_subnets
image: hashicorp/terraform:light
environment:
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- cp providers.tf.example examples/into_existing_subnets/providers.tf
- cp backend.tf.example examples/into_existing_subnets/backend.tf
- cd examples/into_existing_subnets
- sed -i "s/REPLACE/intosubnets$DRONE_REPO_NAME$DRONE_BUILD_NUMBER/g" backend.tf
- terraform init
- terraform destroy --auto-approve -var "deployment_id=intosubnets$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" -refresh=false
- terraform -v
- DESTROY=1 EXAMPLE=from_scratch pipeline/run_terraform.sh
when:
event:
- push
Expand Down
19 changes: 19 additions & 0 deletions pipeline/run_terraform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set -xe

terraform -v

# unique deployment ID to avoid collisions in CI
DEPLOYMENT_ID=$(echo "$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" | md5sum | awk '{print $1}')

cp providers.tf.example examples/$EXAMPLE/providers.tf
cp backend.tf.example examples/$EXAMPLE/backend.tf
cd examples/$EXAMPLE
sed -i "s/REPLACE/$DEPLOYMENT_ID/g" backend.tf

terraform init

if [ $DESTROY -eq 1 ]; then
terraform destroy --auto-approve -var "deployment_id=$DEPLOYMENT_ID"
else
terraform apply --auto-approve -var "deployment_id=$DEPLOYMENT_ID"
fi

0 comments on commit 9cb3eb2

Please sign in to comment.