Search code examples
terraformterraform-provider

How to grant SELECT privilege to all views in snowflake with terraform?


Thanks for help in advance.

I started picking up a old terraform project from a friend, as well I am beginner too.

Unfortunately, I could not find how to grant SELECT privilege for all views in a schema

This is my code,

resource "snowflake_view_grant" "prod_view_select_grant" {
  provider      = snowflake.security_admin
  database_name = snowflake_database.prod_db.name
  schema_name   = "PRODUCTION"

  privilege = "SELECT"
  roles = [
    snowflake_role.role_1.name,
    snowflake_role.role_2.name,
    snowflake_role.role_3.name
  ]

  with_grant_option = false
}

There was no option mentioned in https://registry.terraform.io/providers/Snowflake-Labs/snowflake/0.58.2/docs/resources/view_grant

Any workaround?

╷
│ Error: view_name must be set unless on_future is true
│ 
│   with snowflake_view_grant.prod_view_select_grant,
│   on tf_snowflake_grants.tf line 460, in resource "snowflake_view_grant" "prod_view_select_grant":


Solution

  • You are using the Snowflake Terraform provider v0.58.2. If you upgrade to the latest version, you will have access to the on_all attribute. See here:

    on_all (Boolean) When this is set to true and a schema_name is provided, apply this grant on all views in the given schema. When this is true and no schema_name is provided apply this grant on all views in the given database. The view_name and shares fields must be unset in order to use on_all. Cannot be used together with on_future.