diff --git a/.vscode/settings.json b/.vscode/settings.json index 1a3a040..76997d5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -297,6 +297,7 @@ "roboto", "rocm", "roff", + "roleout", "rootlv", "rootvg", "routable", diff --git a/knowledge base/data warehouse.md b/knowledge base/data warehouse.md new file mode 100644 index 0000000..e213b2a --- /dev/null +++ b/knowledge base/data warehouse.md @@ -0,0 +1,65 @@ +# Data warehouse + +Centralized repository that stores large amounts of data from various sources.
+It possibly stores the data in structured and organized ways that are optimized for data analysis and generation of +reports and insights. + +1. [TL;DR](#tldr) +1. [Further readings](#further-readings) + +## TL;DR + +Operational systems upload the data, which may require cleansing. + +The two main workflows for data warehouse systems are: + +- _Extract, Transform, Load_ (ETL). +- _Extract, Load, Transform_ (ELT). + + + + + + + +## Further readings + +- [What is a data warehouse?] +- [Snowflake] + + + + + +[snowflake]: snowflake/README.md + + + +[What is a data warehouse?]: https://www.ibm.com/think/topics/data-warehouse diff --git a/knowledge base/snowflake.md b/knowledge base/snowflake.md deleted file mode 100644 index 9fc0a1c..0000000 --- a/knowledge base/snowflake.md +++ /dev/null @@ -1,186 +0,0 @@ -# Snowflake - -> TODO - -Intro - - - -1. [TL;DR](#tldr) -1. [Snowflake CLI](#snowflake-cli) -1. [RoleOut](#roleout) -1. [Further readings](#further-readings) - 1. [Sources](#sources) - -## TL;DR - -
- Setup - -
- Linux (DEB) - -```sh -# Install Snowflake's CLI. -# Get it from the [Snowflake CLI repository]. -curl --continue-at '-' --location --fail --show-error --remote-name \ - --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.deb' \ -&& sudo dpkg -i 'snowflake-cli-3.7.2.aarch64.deb' -``` - -
- -
- Linux (RPM) - -```sh -# Install Snowflake's CLI. -# Get it from the [Snowflake CLI repository]. -curl --continue-at '-' --location --fail --show-error --remote-name \ - --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.rpm' \ -&& sudo rpm -i 'snowflake-cli-3.7.2.rpm' -``` - -
- -
- Mac OS X - -```sh -# Install Snowflake's CLI. -brew install 'snowflake-cli' - -# Install RoleOut's UI and CLI. -curl -C '-' -LfSO --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/Roleout-2.0.1-arm64.dmg' \ -&& sudo installer -pkg 'Roleout-2.0.1-arm64.dmg' -target '/' \ -&& curl -C '-' -LfS --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/roleout-cli-macos' \ - --output "$HOME/bin/roleout-cli" \ -&& chmod 'u+x' "$HOME/bin/roleout-cli" \ -&& xattr -d 'com.apple.quarantine' "$HOME/bin/roleout-cli" -``` - -
- -
- -
- Usage - -```sh -# Check it works. -snow --version - -# Get help. -snow --help -snow helpers -h - -# List configured connections to Snowflake. -snow connection list - -# Add connections. -snow connection add - -# Test connections. -snow connection test -snow connection test -c 'connection-name' - -# Executes Snowflake queries. -snow sql -``` - -```sql -SHOW USERS; -SHOW USERS LIKE '%john%'; -DESC USER zoe; - -CREATE USER alice; -CREATE USER IF NOT EXISTS bob; -CREATE OR REPLACE USER claude - PASSWORD='somePassword' DISPLAY_NAME='Claude' EMAIL='claude@example.org' - LOGIN_NAME='CLAUDE@EXAMPLE.ORG' MUST_CHANGE_PASSWORD=TRUE; - -GRANT ROLE someRole TO USER diane; - -ALTER USER IF EXISTS elijah RESET PASSWORD; -ALTER USER fred SET DISABLE_MFA=TRUE; -ALTER USER greg SET MINS_TO_UNLOCK=0; -``` - -
- - - -## Snowflake CLI - -Refer [Snowflake CLI]. - -Meant to replace the SnowSQL tool. - -Download from the [Snowflake CLI repository]. - -```sh -# Linux (DEB). -curl --continue-at '-' --location --fail --show-error --remote-name \ - --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.deb' \ -&& sudo dpkg -i 'snowflake-cli-3.7.2.aarch64.deb' - -# Linux (RPM). -curl --continue-at '-' --location --fail --show-error --remote-name \ - --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.rpm' \ -&& sudo rpm -i 'snowflake-cli-3.7.2.rpm' - -# Mac OS X. -# Via Homebrew. -brew install 'snowflake-cli' -# Via the [Snowflake CLI repository]. -curl --continue-at '-' --location --fail --show-error --remote-name \ - --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/darwin_arm64/3.7.2/snowflake-cli-3.7.2-darwin-arm64.pkg' \ -&& sudo installer -pkg 'snowflake-cli-3.7.2-darwin-arm64.pkg' -target '/' \ -&& ln -swiv '/Applications/SnowflakeCLI.app/Contents/MacOS/snow' "$HOME/bin/snow" -``` - -## RoleOut - -```sh -# Mac OS X. -curl -C '-' -LfSO --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/Roleout-2.0.1-arm64.dmg' \ -&& sudo installer -pkg 'Roleout-2.0.1-arm64.dmg' -target '/' \ -&& curl -C '-' -LfS --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/roleout-cli-macos' \ - --output "$HOME/bin/roleout-cli" \ -&& chmod 'u+x' "$HOME/bin/roleout-cli" \ -&& xattr -d 'com.apple.quarantine' "$HOME/bin/roleout-cli" -``` - -## Further readings - -- [Website] - -### Sources - -- [Documentation] -- [Snowflake CLI] - - - - - - - -[documentation]: https://docs.snowflake.com/en/ -[website]: https://www.snowflake.com/en/ -[snowflake cli]: https://docs.snowflake.com/en/developer-guide/snowflake-cli/index -[snowflake cli repository]: https://sfc-repo.snowflakecomputing.com/snowflake-cli/index.html - - diff --git a/knowledge base/snowflake/README.md b/knowledge base/snowflake/README.md new file mode 100644 index 0000000..a1c028a --- /dev/null +++ b/knowledge base/snowflake/README.md @@ -0,0 +1,315 @@ +# Snowflake + +Cloud-based [data warehousing][data warehouse] platform. + +1. [TL;DR](#tldr) +1. [Roles](#roles) +1. [Users](#users) +1. [Virtual warehouses](#virtual-warehouses) +1. [Access with private keys](#access-with-private-keys) +1. [Snowflake CLI](#snowflake-cli) +1. [RoleOut](#roleout) +1. [Further readings](#further-readings) + 1. [Sources](#sources) + +## TL;DR + +Snowflake separates storage, compute and cloud services in different layers. + +It: + +- Runs completely on cloud infrastructure. +- Handles semi-structured data like JSON and Parquet. +- Stores persistent data in columnar format in cloud storage.
+ Customers cannot see nor access the data objects directly; they can only access them through SQL query operations. +- Copies data as Copy-on-Write virtual clones. +- Stores tables in memory in small chunks to enhance parallelization. + +Each virtual warehouse is a dedicated MPP compute clusters. Each member handles a different part of a query.
+Snowflake offers Virtual warehouses in different sizes at different prices (XS, S, M, L, XL, …, 6XL). + +Billing depends on how long a warehouse runs continuously.
+The total cost is the aggregate of the cost of using data transfer, storage, and compute resources. + +Snowflake's system analyzes queries and identifies patterns to optimize using historical data. The results of frequently +executed queries is cached. + +Administrators use Role-Based Access Control (RBAC) to define and manage user roles and permissions. + +Accounts can connect to Snowflake via: + +- Web UI. +- Command line clients. +- ODBC and JDBC drivers. +- Native connectors (e.g., Python or Spark). +- Third-party connectors. + +
+ Setup + +
+ Mac OS X + +```sh +# Install RoleOut's UI and CLI. +curl -C '-' -LfSO --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/Roleout-2.0.1-arm64.dmg' \ +&& sudo installer -pkg 'Roleout-2.0.1-arm64.dmg' -target '/' \ +&& curl -C '-' -LfS --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/roleout-cli-macos' \ + --output "$HOME/bin/roleout-cli" \ +&& chmod 'u+x' "$HOME/bin/roleout-cli" \ +&& xattr -d 'com.apple.quarantine' "$HOME/bin/roleout-cli" +``` + +
+ +
+ +
+ Usage + +```sql +-- List users +SHOW USERS; +SHOW USERS LIKE '%john%'; + +-- Get information about users +DESC USER zoe; + +-- Create users +CREATE USER alice; +CREATE USER IF NOT EXISTS bob; +CREATE OR REPLACE USER claude + PASSWORD='somePassword' DISPLAY_NAME='Claude' EMAIL='claude@example.org' + LOGIN_NAME='CLAUDE@EXAMPLE.ORG' MUST_CHANGE_PASSWORD=TRUE; + +-- Make changes to users +ALTER USER IF EXISTS elijah RESET PASSWORD; +ALTER USER fred SET DISABLE_MFA=TRUE; +ALTER USER greg SET MINS_TO_UNLOCK=0; + +-- Delete users +DROP USER snowman; + + +-- List roles +SHOW ROLES; +SHOW ROLES LIKE '%DATA%'; + +-- Grant permissions +GRANT ROLE someRole TO USER diane; +GRANT USAGE ON WAREHOUSE COMPUTE_WH TO ROLE SYSADMIN; + +-- Show permissions resources have +SHOW GRANTS TO USER CLAUDE; +-- Show permissions the current user has on resources +SHOW GRANTS ON USER CLAUDE; + + +-- FIXME +DROP DATABASE IF EXISTS sf_tuts; +DROP WAREHOUSE IF EXISTS sf_tuts_wh; +``` + +
+ + + +## Roles + +Entities to which privileges on securable objects can be granted and revoked.
+They are assigned to [users] to allow them to perform actions required for business functions in their organization + +Snowflake accounts come with a set of system-defined roles: + +- `GLOBALORGADMIN`: the organization administrator.
+ Manages the lifecycle of accounts and views organization-level usage information.
+ This role exists only in the organization account. Replaces `ORGADMIN`. +- `ACCOUNTADMIN`: the account administrator.
+ Encapsulates the `SYSADMIN` and `SECURITYADMIN` roles.
+ Top-level role in the system with access to every component. It should be granted only to a limited and controlled + number of users in the account. +- `SECURITYADMIN`: the security administrator.
+ Manages any object grant globally. Creates, monitors, and manages users and roles. + +
+ + This role is granted `MANAGE GRANTS` privilege to be able to modify any grant, including revoking it.
+ It does **not**, though, give the `SECURITYADMIN` the ability to perform **other** actions like creating objects. To + do so, the role must **also** be granted the privileges needed for those actions. + + It is also granted the `USERADMIN` role. + +
+ +- `USERADMIN`: the user and role administrator.
+ Can create users and roles in the account. It also manages users and roles that it owns. + +
+ + This role is granted the `CREATE USER` and `CREATE ROLE` privileges. + + Only roles with the `OWNERSHIP` privilege on an object (user or role in this case), or a higher role, can modify an + object's properties. + +
+ +- `SYSADMIN`: the system Administrator.
+ It has privileges to create warehouses, databases, and other objects in an account. +- `PUBLIC`: pseudo-role automatically granted by default to every user and every role in an account.
+ Can own securable objects, but they are, by definition, available to every other user and role in the account.
+ Typically used in cases where explicit access control is not needed. + +```sql +-- List roles +SHOW ROLES; +SHOW ROLES LIKE '%DATA%'; + +-- Assume roles +USE ROLE SECURITYADMIN; + +-- Grant permissions +GRANT ROLE FINANCIAL_CHIEF TO USER CLAUDE; +GRANT USAGE ON WAREHOUSE COMPUTE_WH TO ROLE SYSADMIN; + +-- Show permissions users have +SHOW GRANTS TO USER CLAUDE; +-- Show permissions the current user has on other users +SHOW GRANTS ON USER CLAUDE; +``` + +## Users + +Users can only be created by those with (or): + +- The `USERADMIN` role or higher. +- Roles granting them the CREATE USER capability on the account. + +Add users to the account executing a SQL Query by means of Snowflake's web UI found in the `Account` section. + +```sql +-- List users +SHOW USERS; +SHOW USERS LIKE '%john%'; + +-- Get information about users +DESC USER zoe; + +-- Create users +CREATE USER alice; +CREATE USER IF NOT EXISTS bob; +CREATE OR REPLACE USER claude + LOGIN_NAME='CLAUDE@EXAMPLE.ORG' DISPLAY_NAME='Claude' EMAIL='claude@example.org' + PASSWORD='somePassword' MUST_CHANGE_PASSWORD=TRUE; +``` + +Prefer setting a `DEFAULT_WAREHOUSE` and `DEFAULT_ROLE` for users, specially if they use non-Snowflake client tools. + +Remember to `GRANT ROLE a=Access` after creating a user.
+Snowflake does **not** offer access to a user's default role automatically. After a user is created, one **must** +provide that user access to its default role.
+If a user can't access their default role, they won't be able to log in. + +When using SSO: + +- The users' LOGIN NAME must exactly match the email address used by one's Identity Provider.
+ Mismatches or fresh email addresses will result in a failed SSO attempt. +- Optionally remove the ability for a user to log in with a password by not specifying one in the creation command.
+ To give someone the ability to use a password later, simply modify that user's password and require them to change + it.
+ Setting up a password gives the user the option of selecting what method to use to login. This is required by tools + that do not support logging in via SSO. + +## Virtual warehouses + +Dedicated, independent clusters of compute resources in Snowflake. + +They are required for queries and all DML operations, including loading data into tables. + +Available in two types: _Standard_ or _Snowpark-optimized_.
+Type aside, warehouses are defined by their size and those other properties that control and automate their activity. + +Billing depends on how long the warehouse runs continuously. + +Warehouses can be set to automatically resume or suspend, based on activity.
+Auto-suspend and resume are both enabled by default. + +## Access with private keys + +Refer [Snowflake terraform provider authentication]. + +Procedure: + +1. Generate a keypair. + + ```sh + openssl genrsa -out "$HOME/.ssh/snowflake_key" 4096 + openssl rsa -in "$HOME/.ssh/snowflake_key" -pubout -out "$HOME/.ssh/snowflake_key.pub" + openssl pkcs8 -topk8 -inform 'pem' -in "$HOME/.ssh/snowflake_key" \ + -outform 'PEM' -v2 aes-256-cbc -out "$HOME/.ssh/snowflake_key.p8" + ``` + +1. Assign the key to your user in Snowflake. + + ```sql + ALTER USER jsmith SET RSA_PUBLIC_KEY='MIIBIjANBgkqh...'; + ``` + +1. Configure tools to use the key. + + ```sh + export SNOWFLAKE_PRIVATE_KEY="$(cat ~/.ssh/snowflake_key.p8)" + export SNOWFLAKE_PRIVATE_KEY_PATH="$HOME/.ssh/snowflake_key" SNOWFLAKE_PRIVATE_KEY_PASSPHRASE='somePassword' + snow connection add -n 'jwt' --authenticator 'SNOWFLAKE_JWT' --private-key-file "$HOME/.ssh/snowflake_key" + ``` + +## Snowflake CLI + +See [Snowflake CLI]. + +## RoleOut + +Refer [RoleOut]. + +## Further readings + +- [Website] +- [Documentation] +- [Data warehouse] +- [Snowflake CLI] +- [Roleout] + +### Sources + +- [Snowflake CREATE USERS: Syntax, Usage & Practical Examples] +- [Overview of Access Control] + + + + +[users]: #users + + +[Data warehouse]: ../data%20warehouse.md +[RoleOut]: roleout.md +[Snowflake CLI]: cli.md + + + +[Documentation]: https://docs.snowflake.com/en/ +[Overview of Access Control]: https://docs.snowflake.com/en/user-guide/security-access-control-overview +[Website]: https://www.snowflake.com/en/ + + +[Snowflake CREATE USERS: Syntax, Usage & Practical Examples]: https://hevodata.com/learn/snowflake-create-users/ +[Snowflake terraform provider authentication]: https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs#authentication diff --git a/knowledge base/snowflake/cli.md b/knowledge base/snowflake/cli.md new file mode 100644 index 0000000..d657a8e --- /dev/null +++ b/knowledge base/snowflake/cli.md @@ -0,0 +1,211 @@ +# Snowflake CLI + +Refer [Snowflake CLI]. + +Meant to replace the SnowSQL tool. + +1. [TL;DR](#tldr) +1. [Setup](#setup) +1. [Usage](#usage) +1. [Further readings](#further-readings) + +## TL;DR + +
+ Setup + +```sh +# Using Homebrew +brew install 'snowflake-cli' +# Get it from the [Snowflake CLI repository] +curl --continue-at '-' --location --fail --show-error --remote-name \ + --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.deb' \ +&& sudo dpkg -i 'snowflake-cli-3.7.2.aarch64.deb' +curl --continue-at '-' --location --fail --show-error --remote-name \ + --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.rpm' \ +&& sudo rpm -i 'snowflake-cli-3.7.2.rpm' +``` + +
+ +
+ Usage + +```sh +# Check it works. +snow --version + +# Get help. +snow --help +snow helpers -h + +# List configured connections to Snowflake. +snow connection list + +# Add connections. +snow connection add + +# Test connections. +snow connection test +snow connection test -c 'connection-name' + +# Executes Snowflake queries. +snow sql +``` + +
+ + + +## Setup + +Install the package from the [Snowflake CLI repository]. + +
+ +```sh +# Linux +# DEB +curl --continue-at '-' --location --fail --show-error --remote-name \ + --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.deb' \ +&& sudo dpkg -i 'snowflake-cli-3.7.2.aarch64.deb' +# RPM +curl --continue-at '-' --location --fail --show-error --remote-name \ + --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/linux_aarch64/3.7.2/snowflake-cli-3.7.2.aarch64.rpm' \ +&& sudo rpm -i 'snowflake-cli-3.7.2.rpm' + +# Mac OS X +# Via Homebrew +brew install 'snowflake-cli' +# Via the [Snowflake CLI repository] +curl --continue-at '-' --location --fail --show-error --remote-name \ + --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/darwin_arm64/3.7.2/snowflake-cli-3.7.2-darwin-arm64.pkg' \ +&& sudo installer -pkg 'snowflake-cli-3.7.2-darwin-arm64.pkg' -target '/' \ +&& ln -swiv '/Applications/SnowflakeCLI.app/Contents/MacOS/snow' "$HOME/bin/snow" +``` + +
+ +Refer [Configuring Snowflake CLI] and [Managing Snowflake connections] for the configuration. + +Snowflake CLI uses a global configuration file to configure connections and logs.
+The CLI looks for: + +- The file specified by the `--config-file` option. +- A `config.toml` file in the location specified by the `SNOWFLAKE_HOME` environment variable, if set. +- The `~/.snowflake/config.toml` file, if such directory exists. +- The `config.toml` file in the one of the following locations, based on one's operating system: + + - Linux: `$XDG_CONFIG_HOME/snowflake/config.toml`. + - Windows: `%USERPROFILE%\AppData\Local\snowflake\config.toml` + - Mac OS X: `~/Library/Application Support/snowflake/config.toml` + +If the global configuration file does not exist, running any `snow` command for the first time automatically creates an +empty `config.toml` file that one can then populate with the desired connections. + +For MacOS and Linux systems, Snowflake CLI requires the configuration file to limit its file permissions to read and +write for the file owner only. + +```sh +chown "$USER" "$HOME/.snowflake/config.toml" +chmod 'u=rw,go=' "$HOME/.snowflake/config.toml" +``` + +The configuration supports the following sections: + +- `[connections]`, for defining and managing connections. +- `[logs]`, for configuring which types of messages are saved to log files. + +A configuration file has the following structure: + +```toml +[cli.logs] +save_logs = true +level = "info" +path = "/home/john/.snowflake/logs" + +[connections.default] +account = "ABCDEFG-YZ01234" +user = "JDOE" +password = "SuperSecur3Pa$$word" +authenticator = "externalbrowser" +role = "PROD_SYSTEM_FR" +``` + +One can generate the basic settings for the TOML configuration file in Snowsight. + +> [!important] +> Should a `connection.toml` file exist in the same directory as the global configuration file, Snowflake CLI will use +> the connections defined there instead of the ones in the global `config.toml` file. + +One can also use environment variables to override parameter values defined in the configuration files.
+Use the format `SNOWFLAKE__=`, where: + +- `` is the name of a section in the configuration file, with periods (`.`) replaced with underscores + (`_`), e.g., `CLI_LOGS`. +- `` is the name of a variable defined in that section, e.g. `path`. + +
+ Examples + +```sh +# Override the path parameter in the [cli.logs] section in the config.toml file +SNOWFLAKE_CLI_LOGS_PATH='/Users/jondoe/snowcli_logs' snow … + +# Set the password for the 'myconnection' connection +SNOWFLAKE_CONNECTIONS_MYCONNECTION_PASSWORD='SomePassword' + +# Set the default connection name +SNOWFLAKE_DEFAULT_CONNECTION_NAME='myconnection' +``` + +
+ +## Usage + +```sh +# Add connections +snow connection add +snow --config-file 'my_config.toml' connection add \ + -n 'myconnection2' --account 'myaccount2' --user 'jdoe2' --no-interactive + +# List connections +snow connection list + +# Test connections +snow connection test +snow --config-file='my_config.toml' connection test -c 'myconnection2' --enable-diag --diag-log-path "$HOME/report" + +# Set the default connection +snow connection set-default 'myconnection2' +``` + +## Further readings + +- [Snowflake] + + + + + +[Snowflake]: README.md + + + +[Configuring Snowflake CLI]: https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-cli +[Managing Snowflake connections]: https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections +[snowflake cli repository]: https://sfc-repo.snowflakecomputing.com/snowflake-cli/index.html +[snowflake cli]: https://docs.snowflake.com/en/developer-guide/snowflake-cli/index + + diff --git a/knowledge base/snowflake/roleout.md b/knowledge base/snowflake/roleout.md new file mode 100644 index 0000000..95c1243 --- /dev/null +++ b/knowledge base/snowflake/roleout.md @@ -0,0 +1,84 @@ +# RoleOut + +Project trying to accelerate the design and deployment of Snowflake environments through Infrastructure as Code. + +1. [TL;DR](#tldr) +1. [Further readings](#further-readings) + +## TL;DR + +Administrators define Snowflake resources in a YAML file. RoleOut then uses it to generate SQL or Terraform code for +deployment. + +> [!important] +> The tool applies opinionated best practices.
+> It also comes with its own naming convention, but it can be tweaked. + +
+ Setup + +```sh +# Mac OS X +curl -C '-' -LfSO --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/Roleout-2.0.1-arm64.dmg' \ +&& sudo installer -pkg 'Roleout-2.0.1-arm64.dmg' -target '/' \ +&& sudo xattr -r -d 'com.apple.quarantine' '/Applications/Roleout.app' \ +&& curl -C '-' -LfS --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/roleout-cli-macos' \ + --output "$HOME/bin/roleout-cli" \ +&& chmod 'u+x' "$HOME/bin/roleout-cli" \ +&& xattr -d 'com.apple.quarantine' "$HOME/bin/roleout-cli" + +# Configure access +export SNOWFLAKE_ACCOUNT='ab01234.eu-west-1' \ + SNOWFLAKE_USER='DIANE' SNOWFLAKE_PRIVATE_KEY_PATH='some-private-key-path' \ + SNOWFLAKE_WAREHOUSE='DEV_DIANE_WH' SNOWFLAKE_ROLE='ACCOUNTADMIN' +``` + +
+ +
+ Usage + +```sh +# Load objects from Snowflake +roleout-cli snowflake populateProject -o 'my_config.yml' + +# Update existing configurations +roleout-cli snowflake populateProject -c 'my_config.yml' -o 'my_new_config.yml' + +# Import existing objects that are defined in the configuration +roleout-cli terraform import -c 'my_config.yml' +# Just write the `terraform import` commands to a file instead of running them +roleout-cli terraform import -c 'my_config.yml' --output 'my_import_commands.sh' +``` + +
+ + + +## Further readings + +- [Snowflake] +- [Codebase] + + + + + +[Snowflake]: README.md + + + +[Codebase]: https://github.com/Snowflake-Labs/roleout + + diff --git a/snippets/snowflake.fish b/snippets/snowflake.fish index 4f2dc43..db1be09 100644 --- a/snippets/snowflake.fish +++ b/snippets/snowflake.fish @@ -1,6 +1,65 @@ #!/usr/bin/env fish +### +# Snowflake CLI +# ------------------ +### + +# Install curl -C '-' -LfSO \ --url 'https://sfc-repo.snowflakecomputing.com/snowflake-cli/darwin_arm64/3.7.2/snowflake-cli-3.7.2-darwin-arm64.pkg' \ && sudo installer -pkg 'snowflake-cli-3.7.2-darwin-arm64.pkg' -target '/' \ && ln -swiv '/Applications/SnowflakeCLI.app/Contents/MacOS/snow' "$HOME/bin/snow" + +# Show the configuration +cat "$HOME/Library/Application Support/snowflake/config.toml" + +# Add connections +snow connection add +snow --config-file 'my_config.toml' connection add -n 'myconnection2' --account 'myaccount2' --user 'jdoe2' --no-interactive + +# List connections +snow connection list + +# Test connections +snow connection test +snow --config-file='my_config.toml' connection test -c 'myconnection2' --enable-diag --diag-log-path "$HOME/report" + +# Set the default connection +snow connection set-default 'myconnection2' + +# Execute SQL commands +snow sql + + +### +# Roleout +# ------------------ +### + +# Install +# Mac OS X +curl -C '-' -LfSO --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/Roleout-2.0.1-arm64.dmg' \ +&& sudo installer -pkg 'Roleout-2.0.1-arm64.dmg' -target '/' \ +&& sudo xattr -r -d 'com.apple.quarantine' '/Applications/Roleout.app' \ +&& curl -C '-' -LfS --url 'https://github.com/Snowflake-Labs/roleout/releases/download/v2.0.1/roleout-cli-macos' \ + --output "$HOME/bin/roleout-cli" \ +&& chmod 'u+x' "$HOME/bin/roleout-cli" \ +&& xattr -d 'com.apple.quarantine' "$HOME/bin/roleout-cli" + +# Configure access +export SNOWFLAKE_ACCOUNT='ab01234.eu-west-1' \ + SNOWFLAKE_USER='DIANE' SNOWFLAKE_PRIVATE_KEY_PATH='some-private-key-path' \ + SNOWFLAKE_WAREHOUSE='DEV_DIANE_WH' SNOWFLAKE_ROLE='ACCOUNTADMIN' + +# Load objects from Snowflake +roleout-cli snowflake populateProject -o 'my_config.yml' + +# Update existing configurations +roleout-cli snowflake populateProject -c 'my_config.yml' -o 'my_new_config.yml' + +# Import existing objects that are defined in the configuration +roleout-cli terraform import -c 'my_config.yml' +# Just write the `terraform import` commands to a file instead of running them +roleout-cli terraform import -c 'my_config.yml' --output 'my_import_commands.sh' +roleout-cli terraform import -c 'my_config.yml' -o '/dev/stdout'