aidanmelen / terraform-provider-snowsql

Terraform SnowSQL provider
https://registry.terraform.io/providers/aidanmelen/snowsql/latest
Other
22 stars 10 forks source link

Warehouse declaration not supported in snowsql provider #44

Closed hongzed closed 2 years ago

hongzed commented 2 years ago

Hi @aidanmelen ,

I am encountering an issue when having multiple grant statements (more than one) defined in either the create or delete lifecycle. Given such a configuration the terraform apply always errors out complaining about no active warehouse selected. When attempting with the warehouse attribute in the snowsql provider configuration, an error is given stating the warehouse is not a supported argument.

Terraform Version

Terraform v1.0.11

Affected Resource(s)

Terraform Configuration Files

provider "snowsql" {
  account          = var.account
  region           = var.region
  username         = var.snowsql_username
  private_key_path = var.private_key_path

  warehouse = "compute_wh"
}

resource "snowsql_exec" "snowsql_exec_test" {
  name = "snowsql_exec_test"

  create {
    statements = <<-EOT
    grant select on view CITIBIKE.PUBLIC.TRIPS_V to role ${snowflake_role.role.name};
    grant select on view CITIBIKE.PUBLIC.TRIPS_V to role ${snowflake_role.role.name};
    EOT
  }

  delete {
    statements = <<-EOT
    revoke select on view CITIBIKE.PUBLIC.TRIPS_V from role ${snowflake_role.role.name};
    revoke select on view CITIBIKE.PUBLIC.TRIPS_V from role ${snowflake_role.role.name};
    EOT
  }

}

Expected Behavior

What should have happened?

Actual Behavior

What actually happened?

hongzhh commented 2 years ago

hi @aidanmelen
I just came across this PR #42 and hence cloned the repo and built/installed the snowsql provider locally for testing. Unfortunately, it is still not able to recognise the warehouse argument.

provider "snowsql" { account = var.account region = var.region username = var.snowsql_username private_key_path = var.private_key_path

warehouse = "compute_wh" }

- Executed `terraform init` 
```shell
$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding snowflake-labs/snowflake versions matching "~> 0.35"...
- Finding registry.example.io/local/snowsql versions matching "0.4.4"...
- Finding latest version of hashicorp/tls...
- Installing snowflake-labs/snowflake v0.40.0...
- Installed snowflake-labs/snowflake v0.40.0 (signed by a HashiCorp partner, key ID 5166D7352E69A585)
- Installing registry.example.io/local/snowsql v0.4.4...
- Installed registry.example.io/local/snowsql v0.4.4 (unauthenticated)
- Installing hashicorp/tls v4.0.1...
- Installed hashicorp/tls v4.0.1 (signed by HashiCorp)
aidanmelen commented 2 years ago

thanks for reporting the issue! I will look into this further. In the meantime, there is a work around described here.

Essentially, it means setting the DEFAULT_WAREHOUSE on the user that the snowsql provider is using to authenticate. I realize that is not ideal for users of this provider which is why I would like to fix this issue.

aidanmelen commented 2 years ago

it also looks like there is a second work around described here.

still I will look into fixing this issue

aidanmelen commented 2 years ago

another option is to use the environment variable.

SNOWFLAKE_WAREHOUSE='COMPUTE WH'

aidanmelen commented 2 years ago

please use the upcoming v1.0.0 v1.0.1 release to use the provider.warehouse feature.

hongzed commented 2 years ago

thank you @aidanmelen just did a terraform init -upgrade and everything works as expected on my end!