Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace null_resource for executing snowsql with the terraform-provider-snowsql #74

Open
aidanmelen opened this issue Aug 30, 2021 · 0 comments

Comments

@aidanmelen
Copy link

aidanmelen commented Aug 30, 2021

I just recently released terraform-provider-snowsql. This project seemed like it could benefit from this new provider!

For example, the snowpipe-base sub-module uses on the null_resource to execute snowsql statements.

resource "null_resource" "create_snowflake_table" {

  provisioner "local-exec" {
    command = <<EOT
{
      snowsql --accountname $SNOWFLAKE_ACCOUNT.$SNOWFLAKE_REGION --username $SNOWFLAKE_USER --query 'CREATE TABLE IF NOT EXISTS ${var.database}.${var.schema}.${local.formatted_s3_path} ${local.formatted_rows}' || \
      (echo 'Make sure $SNOWFLAKE_ACCOUNT, $SNOWFLAKE_REGION and $SNOWFLAKE_USER env vars are set and the snowsql tool is on the path'; exit 1;)
}
EOT
  }
}

which can be declare with:

terraform {
  required_version = ">= 0.13.0"

  required_providers {
    snowflake = {
      source  = "chanzuckerberg/snowflake"
      version = ">= v0.25.18"
    }
    snowsql = {
      source  = "aidanmelen/snowsql"
      version = ">= 0.1.0"
    }
    random = ">= 2.1"
  }
}

# both providers use the same code to authenticate with snowflake
provider "snowflake" {}
provider "snowsql" {}

# ...

resource "snowsql_exec" "dcl" {
  name = local.name

  create {
    statements = "CREATE TABLE IF NOT EXISTS ${var.database}.${var.schema}.${local.formatted_s3_path} ${local.formatted_rows}${snowflake_role.role.name};"
  }

  delete {
    statements = "DROP TABLE IF EXISTS ${var.database}.${var.schema}.${local.formatted_s3_path} ${local.formatted_rows}"
  }

  delete_on_create = true
}
@aidanmelen aidanmelen changed the title replace local_exec resource for executing snowsql with the terraform-provider-snowsql replace null_resource for executing snowsql with the terraform-provider-snowsql Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant