#!/bin/bats # Run: bats ./terraform-modules/terraform-test.bats --timing # Debug: bats ./terraform-modules/terraform-test.bats --timing --show-output-of-passing-tests # Testing happy path of creating/deleting stack # prereqs: # 1. Quicksight Enterprise edition # 2. Quicksight has rights to read all s3 buckets in the account (not managable today) # 3. At least 1 CUR created setup_file() { # Vars export stackname="tfstack$(date +%Y%m%d%H%M)" export cur_prefix="cid$(date +%Y%m%d%H%M)" export account_id=$(aws sts get-caller-identity --query Account --output text) export quicksight_user=$(aws quicksight list-users --aws-account-id $account_id --namespace default --query 'UserList[0].UserName' --output text) export template_bucket=test-cid-tf-template-$account_id aws quicksight describe-user --aws-account-id $account_id --user-name $quicksight_user --namespace default if [[ "$?" != "0" ]]; then echo "Missing QS User '$quicksight_user'" return 1 fi export qs_edition=$(aws quicksight describe-account-settings --aws-account-id $account_id --query 'AccountSettings.Edition' --output text) if [[ "$qs_edition" != "ENTERPRISE" ]]; then echo "Missing ENTERPRISE edition in QuickSight" return 1 fi # Create a tmp bucket to store CFN template if aws s3api head-bucket --bucket "$template_bucket" 2>/dev/null; then echo 'Template Bucket exist' else echo 'Creating bucket for template' aws s3api create-bucket --bucket $template_bucket fi # Create workspace export tf_workspace=$(mktemp -d .tftest.XXXXXX) } @test "generate terraform manifest" { # Create a TF configuration git_base_dir=$(git rev-parse --show-toplevel) cp -r "$(git rev-parse --show-toplevel)/terraform-modules" "${tf_workspace}" cp -r "$(git rev-parse --show-toplevel)/cfn-templates" "${tf_workspace}" cat > "$tf_workspace/main.tf" <