Best practice on configuring role(s) that my Terraform user will use #1805
Replies: 1 comment 2 replies
-
Hi @louis-vines, I've set it up by creating 3 roles which align to the suggested hierarchy, allowing resource ownership to be rolled up to the top-level "admin" roles without "crossing the streams". That is, SECURITYADMIN owns all users and roles; SYSADMIN owns databases and warehouses; and ACCOUNTADMIN owns integrations. USE ROLE ACCOUNTADMIN;
CREATE USER TERRAFORMER <...>;
CREATE ROLE ACCOUNTTERRAFORMER;
GRANT ROLE ACCOUNTTERRAFORMER TO ROLE ACCOUNTADMIN;
GRANT ROLE ACCOUNTTERRAFORMER TO USER TERRAFORMER;
GRANT CREATE INTEGRATION ON ACCOUNT TO ACCOUNTTERRAFORMER;
GRANT CREATE NETWORK POLICY ON ACCOUNT TO ACCOUNTTERRAFORMER;
-- additional account grants
CREATE ROLE SECURITYTERRAFORMER;
GRANT ROLE SECURITYTERRAFORMER TO ROLE SECURITYADMIN;
GRANT ROLE SECURITYTERRAFORMER TO USER TERRAFORMER;
GRANT CREATE USER ON ACCOUNT TO ROLE SECURITYTERRAFORMER;
GRANT CREATE ROLE ON ACCOUNT TO ROLE SECURITYTERRAFORMER;
GRANT MANAGE GRANTS ON ACCOUNT TO ROLE SECURITYTERRAFORMER;
CREATE ROLE SYSTERRAFORMER;
GRANT ROLE SYSTERRAFORMER TO ROLE SYSADMIN;
GRANT ROLE SYSTERRAFORMER TO USER TERRAFORMER;
GRANT CREATE DATABASE ON ACCOUNT TO SYSTERRAFORMER;
GRANT CREATE WAREHOUSE ON ACCOUNT TO SYSTERRAFORMER; Then within the terraform module, I create 3 snowflake provider instances (same user, different role): provider "snowflake" {
alias = "accountterraformer"
username = local.snowflake.username
account = local.snowflake.account
role = "ACCOUNTERRAFORMER"
# auth attributes
}
provider "snowflake" {
alias = "securityterraformer"
username = local.snowflake.username
account = local.snowflake.account
role = "SECURITYTERRAFORMER"
# auth attributes
}
provider "snowflake" {
alias = "systerraformer"
username = local.snowflake.username
account = local.snowflake.account
role = "SYSTERRAFORMER"
# auth attributes
} Lastly, when creating resources, you need to specify the provider which aligns with the correct role for that resource: resource "snowflake_storage_integration" "s3" {
provider = snowflake.accountterraformer
# ... snip ...
}
resource "snowflake_user" "user" {
provider = snowflake.securityterraformer
# ... snip ...
}
resource "snowflake_database" "db" {
provider = snowflake.systerraformer
# ... snip ...
} A quality-of-life feature request would be to have an I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
I'm just wondering if there are any best practices for how I should configure the role(s) that Terraform will assume when administering snowflake. I've setup all of the Snowflake RBAC at a previous company in terraform and am just about to start from scratch at a new company and would like to get this nailed before I proceed.
I've noticed in the snowflake terraform tutorial (https://quickstarts.snowflake.com/guide/terraforming_snowflake) it just grants
SYSADMIN
andSECURITYADMIN
to snowflake, but it then states:So what are the best practices for this? How should I grant privileges to my Terraform user?
At my previous company I just did this:
But I think this also violates a best practice as I now have a role that both administers data base objects (i.e. like SYSADMIN) and users + roles (i.e. like SECURTYADMIN).
So what roles/priviliges should I grant to my terraform user and how???
(One final related question is how can I make terraform responsible for administering parameters on my account too? I think to do this then terraform has to be an ACCOUNTADMIN but again this doesn't sound like something I should be granting to my Terraform user)
Beta Was this translation helpful? Give feedback.
All reactions