From 31e76f0c121a3a318a07af9374198b524b12c8f6 Mon Sep 17 00:00:00 2001 From: Umang Mistry Date: Tue, 6 Feb 2024 16:29:58 -0600 Subject: [PATCH] Initial commit + bitbucket pipeline Added steps for snowflake schemachange deployment using definition to be reused depending on the branch name --- bitbucket-pipelines.yml | 66 ++++++++++++++++++++++++++++++ terraform/modules/iam/backend.tf | 0 terraform/modules/iam/main.tf | 0 terraform/modules/iam/variables.tf | 0 4 files changed, 66 insertions(+) create mode 100644 bitbucket-pipelines.yml create mode 100644 terraform/modules/iam/backend.tf create mode 100644 terraform/modules/iam/main.tf create mode 100644 terraform/modules/iam/variables.tf diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml new file mode 100644 index 0000000..e57f3ac --- /dev/null +++ b/bitbucket-pipelines.yml @@ -0,0 +1,66 @@ +definitions: + steps: + - step: &terraform_plan_apply + name: "Plan and Apply Terraform" + image: zenika/terraform-aws-cli:latest + script: + - terraform --version + # terraform steps here + # trigger: automatic # uncomment after testing + trigger: manual + caches: + - terraform + - step: &snowflake_deploy + name: "Deploy Snowflake Changes" + image: python:3.7 + size: 2x + script: + - python -m pip install --upgrade pip + - pip install snowflake-connector-python + - pip install schemachange --upgrade + # Setting the database name dynamically based on the branch name + - if [ "$BITBUCKET_BRANCH" == "DEV" ]; then export SNOWFLAKE_DATABASE=$DEV_SNOWFLAKE_DATABASE; fi + - if [ "$BITBUCKET_BRANCH" == "UAT" ]; then export SNOWFLAKE_DATABASE=$UAT_SNOWFLAKE_DATABASE; fi + - if [ "$BITBUCKET_BRANCH" == "PROD" ]; then export SNOWFLAKE_DATABASE=$PROD_SNOWFLAKE_DATABASE; fi + - schemachange -a $SNOWFLAKE_ACCOUNT -u $SNOWFLAKE_USER -r $SNOWFLAKE_ROLE -w $SNOWFLAKE_WAREHOUSE -d $SNOWFLAKE_DATABASE -c $SNOWFLAKE_DATABASE.SCHEMACHANGE.CHANGE_HISTORY --create-change-history-table -v + # trigger: automatic # uncomment after testing + trigger: manual + caches: + - pip + +pipelines: + branches: + dev: + - step: + <<: *terraform_plan_apply + condition: + changesets: + includePaths: + - terraform/dev/**/* + - step: + <<: *snowflake_deploy + condition: + paths: + - snowflake/**/*.sql + uat: + - step: + <<: *terraform_plan_apply + condition: + paths: + - terraform/uat/**/* + - step: + <<: *snowflake_deploy + condition: + paths: + - snowflake/**/*.sql + prod: + - step: + <<: *terraform_plan_apply + condition: + paths: + - terraform/prod//**/* + - step: + <<: *snowflake_deploy + condition: + paths: + - snowflake/**/*.sql diff --git a/terraform/modules/iam/backend.tf b/terraform/modules/iam/backend.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/iam/main.tf b/terraform/modules/iam/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/iam/variables.tf b/terraform/modules/iam/variables.tf new file mode 100644 index 0000000..e69de29