From 34afdab0aae90fbe1b13718c11eef918ae9ed18d Mon Sep 17 00:00:00 2001 From: Steven Miller Date: Fri, 5 Jul 2019 15:27:05 +0000 Subject: [PATCH 1/4] debugging pipeline --- .drone.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.drone.yml b/.drone.yml index 2fc7864..8e08184 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,9 +39,9 @@ steps: - 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_BUILD_NUMBER/g" backend.tf + - sed -i "s/REPLACE/$DRONE_REPO_NAME$DRONE_BUILD_NUMBER/g" backend.tf - terraform init - - terraform apply --auto-approve -var "deployment_id=fromscratch$DRONE_BUILD_NUMBER" + - terraform apply --auto-approve -var "deployment_id=fromscratch$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" - terraform -v when: event: @@ -62,9 +62,9 @@ steps: - 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_BUILD_NUMBER/g" backend.tf + - sed -i "s/REPLACE/$DRONE_REPO_NAME$DRONE_BUILD_NUMBER/g" backend.tf - terraform init - - terraform destroy --auto-approve -var "deployment_id=fromscratch$DRONE_BUILD_NUMBER" -refresh=false + - terraform destroy --auto-approve -var "deployment_id=fromscratch$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" -refresh=false - terraform -v when: event: @@ -88,9 +88,10 @@ steps: - 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_BUILD_NUMBER/g" backend.tf + - 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_BUILD_NUMBER" + - 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: @@ -111,9 +112,9 @@ steps: - 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_BUILD_NUMBER/g" backend.tf + - 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_BUILD_NUMBER" -refresh=false + - terraform destroy --auto-approve -var "deployment_id=intosubnets$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" -refresh=false - terraform -v when: event: From 9cb3eb2307cebfdc4064215cb746916d2a034d85 Mon Sep 17 00:00:00 2001 From: Steven Miller Date: Fri, 5 Jul 2019 16:21:28 +0000 Subject: [PATCH 2/4] cleaning up pipeline --- .drone.yml | 66 ++------------------------------------- pipeline/run_terraform.sh | 19 +++++++++++ 2 files changed, 21 insertions(+), 64 deletions(-) create mode 100755 pipeline/run_terraform.sh diff --git a/.drone.yml b/.drone.yml index 8e08184..13dc040 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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 @@ -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 diff --git a/pipeline/run_terraform.sh b/pipeline/run_terraform.sh new file mode 100755 index 0000000..a611e95 --- /dev/null +++ b/pipeline/run_terraform.sh @@ -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 From 7c9dea56adb90b6e7be9f2088c13dac140fca2c8 Mon Sep 17 00:00:00 2001 From: Steven Miller Date: Fri, 5 Jul 2019 16:56:20 +0000 Subject: [PATCH 3/4] debugging deployment id --- pipeline/run_terraform.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pipeline/run_terraform.sh b/pipeline/run_terraform.sh index a611e95..0940302 100755 --- a/pipeline/run_terraform.sh +++ b/pipeline/run_terraform.sh @@ -3,7 +3,9 @@ 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}') +# needs to be 32 characters or less and start with letter +DEPLOYMENT_ID=ci$(echo "$DRONE_REPO_NAME$DRONE_BUILD_NUMBER" | md5sum | awk '{print substr($1,0,30)}') +echo $DEPLOYMENT_ID cp providers.tf.example examples/$EXAMPLE/providers.tf cp backend.tf.example examples/$EXAMPLE/backend.tf From 4f2cc9a1fa05026ea71222047d268959d413a54b Mon Sep 17 00:00:00 2001 From: Steven Miller Date: Fri, 5 Jul 2019 17:13:38 +0000 Subject: [PATCH 4/4] debugging pipeline --- eks.tf | 4 ---- examples/from_scratch/main.tf | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/eks.tf b/eks.tf index 8e64089..a224e41 100644 --- a/eks.tf +++ b/eks.tf @@ -29,10 +29,6 @@ module "eks" { worker_additional_security_group_ids = [aws_security_group.all_worker_mgmt.id] - map_roles = [] - map_accounts = [] - map_users = [] - cluster_endpoint_private_access = "true" cluster_endpoint_public_access = var.management_api == "public" ? true : false diff --git a/examples/from_scratch/main.tf b/examples/from_scratch/main.tf index bd3ab7d..3724339 100644 --- a/examples/from_scratch/main.tf +++ b/examples/from_scratch/main.tf @@ -13,4 +13,7 @@ module "astronomer_aws_with_vpc" { admin_email = "steven@astronomer.io" route53_domain = "astronomer-development.com" management_api = "public" + tags = { + "CI" = "true" + } }