From 2366a8aa7ebac84a048fc43c4e6740cb54f00b6c Mon Sep 17 00:00:00 2001 From: Grzegorz Huber Date: Tue, 25 Jun 2024 17:58:33 +0200 Subject: [PATCH] [DOC-535] Snowsql test --- bitbucket-pipelines.yml | 42 +++++++++++++------------------------- snowsql-cicd.sh | 45 ----------------------------------------- snowsql-query.sql | 1 - 3 files changed, 14 insertions(+), 74 deletions(-) delete mode 100755 snowsql-cicd.sh delete mode 100644 snowsql-query.sql diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index fc0e6e8..4e1aad3 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -287,32 +287,18 @@ pipelines: feature/DOC-535-snowsql-in-cicd: - parallel: - - step: - image: hugree/terraform-with-snowsql:latest - name: Run Snowsql on DEV - oidc: true - script: - - *aws-context-dev -# - export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO:role/$OIDC_ROLE -# - export STS_OUTPUT=$(aws sts assume-role-with-web-identity --role-arn $AWS_ROLE_ARN --role-session-name BitbucketPipeline --web-identity-token "$BITBUCKET_STEP_OIDC_TOKEN" --duration-seconds 3600) -# - export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId') -# - export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey') -# - export AWS_SESSION_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken') -# - aws sts get-caller-identity --output text -# - bash snowsql-cicd.sh dev - - IS_DEPLOY_ALL=true python terraform.py apply --environment=dev --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create" + - step: + image: hugree/terraform-with-snowsql:latest + name: Run Snowsql on DEV + oidc: true + script: + - *aws-context-dev + - IS_DEPLOY_ALL=true python terraform.py apply --environment=dev --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create" - - step: - image: hugree/terraform-with-snowsql:latest - name: Run Snowsql on UAT - oidc: true - script: - # - *aws-context-uat - - export AWS_ROLE_ARN=arn:aws:iam::$AWS_ACCOUNT_NO_UAT:role/$OIDC_ROLE_UAT - - export STS_OUTPUT=$(aws sts assume-role-with-web-identity --role-arn $AWS_ROLE_ARN --role-session-name BitbucketPipeline --web-identity-token "$BITBUCKET_STEP_OIDC_TOKEN" --duration-seconds 3600) - - export AWS_ACCESS_KEY_ID=$(echo $STS_OUTPUT | jq -r '.Credentials.AccessKeyId') - - export AWS_SECRET_ACCESS_KEY=$(echo $STS_OUTPUT | jq -r '.Credentials.SecretAccessKey') - - export AWS_SESSION_TOKEN=$(echo $STS_OUTPUT | jq -r '.Credentials.SessionToken') - - aws sts get-caller-identity --output text - # - bash snowsql-cicd.sh dev - - IS_DEPLOY_ALL=true python terraform.py apply --environment=uat --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create" + - step: + image: hugree/terraform-with-snowsql:latest + name: Run Snowsql on UAT + oidc: true + script: + - *aws-context-uat + - IS_DEPLOY_ALL=true python terraform.py apply --environment=uat --module=textract-pipeline/terraform --apply-extra-args="-target=null_resource.snowsql_client_create" diff --git a/snowsql-cicd.sh b/snowsql-cicd.sh deleted file mode 100755 index 4af0186..0000000 --- a/snowsql-cicd.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -ENV_GROUP=$1 - -readonly SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" - -#echo "SNOWFLAKE_ACCOUNT=${SNOWFLAKE_ACCOUNT}, SNOWFLAKE_DATABASE=${SNOWFLAKE_DATABASE}, SNOWFLAKE_ROLE=${SNOWFLAKE_ROLE}" -# -#export GIT_ROOT=$(git rev-parse --show-toplevel) -#if [ "$(type -t changes)" != 'function' ]; then -# source "${GIT_ROOT}/infra/scripts/bootstrap-diff-changes.sh" -#fi -# -#if is_deploy_module "streamlit"; then -# echo -e "${GREEN}# Streamlit module changes have been detected. Executing the upload command...${NC}" -#else -# echo -e "${YELLOW}# There are no Streamlit module changes. Skipping the upload command...${NC}" -# exit 0 -#fi - -echo "# Getting snowflake creds from AWS Secret Manager..." -snowflake_secret_name="doczy-${ENV_GROUP}-db-svc-acc" -snowflake_secret_value=$(aws secretsmanager get-secret-value --secret-id "$snowflake_secret_name" --query 'SecretString' --output text) - -SNOWFLAKE_ACCOUNT=$(echo $snowflake_secret_value | jq -r '.account_locator') -SNOWFLAKE_DATABASE=$(echo $snowflake_secret_value | jq -r '.database') -SNOWFLAKE_USER=$(echo $snowflake_secret_value | jq -r '.user') -SNOWFLAKE_ROLE=$(echo $snowflake_secret_value | jq -r '.role') - -SNOWFLAKE_PASSWORD=$(echo $snowflake_secret_value | jq -r '.password') - -#SNOWFLAKE_ACCOUNT=OQ11564.us-east-2.aws -#SNOWFLAKE_DATABASE=DOCZY_DEV -#SNOWFLAKE_USER=aws_svc_account -#SNOWFLAKE_ROLE=DEVADMIN - -echo "SNOWFLAKE_ACCOUNT=${SNOWFLAKE_ACCOUNT}" -echo "SNOWFLAKE_DATABASE=${SNOWFLAKE_DATABASE}" -echo "SNOWFLAKE_USER=${SNOWFLAKE_USER}" -echo "SNOWFLAKE_ROLE=${SNOWFLAKE_ROLE}" -export SNOWSQL_PWD=${SNOWFLAKE_PASSWORD} - -snowsql -a "${SNOWFLAKE_ACCOUNT}" -u "${SNOWFLAKE_USER}" -d "${SNOWFLAKE_DATABASE}" -r "${SNOWFLAKE_ROLE}" -o exit_on_error=true -f "${SCRIPT_DIR}/snowsql-query.sql" diff --git a/snowsql-query.sql b/snowsql-query.sql deleted file mode 100644 index 60d93f3..0000000 --- a/snowsql-query.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT DISTINCT client_name, bucket_name FROM STG.CLIENT_LOGS \ No newline at end of file