-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup terraform for snowflake ci instance
- Loading branch information
1 parent
4ff6bdb
commit d488576
Showing
8 changed files
with
263 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: "Terraform apply" | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./.terraform | ||
|
||
jobs: | ||
apply: | ||
name: "Apply" | ||
runs-on: ubuntu-latest | ||
environment: "Snowflake: KTB38830" | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
|
||
- name: "Setup Terraform" | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: ${{ vars.TERRAFORM_VERSION }} | ||
|
||
- name: "Terraform init" | ||
run: terraform init | ||
|
||
- name: "Terraform apply" | ||
run: terraform apply -auto-approve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: "Terraform code quality" | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./.terraform | ||
|
||
jobs: | ||
code-quality: | ||
name: "Code quality" | ||
runs-on: ubuntu-latest | ||
environment: "Snowflake: KTB38830" | ||
steps: | ||
- name: "Checkout" | ||
uses: actions/checkout@v4 | ||
|
||
- name: "Setup Terraform" | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: ${{ vars.TERRAFORM_VERSION }} | ||
|
||
- name: "Terraform init" | ||
run: terraform init | ||
|
||
- name: "Terraform format" | ||
run: terraform fmt -check | ||
|
||
- name: "Terraform validate" | ||
run: terraform validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: "Terraform plan" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
branch: | ||
description: "Branch to run plan on" | ||
type: string | ||
default: main | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./.terraform | ||
|
||
jobs: | ||
plan: | ||
name: "Plan" | ||
runs-on: ubuntu-latest | ||
environment: "Snowflake: KTB38830" | ||
steps: | ||
- name: "Checkout `${{ inputs.branch }}`" | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.branch }} | ||
|
||
- name: "Setup Terraform" | ||
uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: ${{ vars.TERRAFORM_VERSION }} | ||
|
||
- name: "Terraform init" | ||
run: terraform init | ||
|
||
- name: "Terraform plan" | ||
run: terraform plan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = "1.8.3" | ||
|
||
required_providers { | ||
snowflake = { | ||
source = "Snowflake-Labs/snowflake" | ||
version = "0.91.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
provider "snowflake" { | ||
alias = "security_admin" | ||
role = "SECURITYADMIN" | ||
# SNOWFLAKE_ACCOUNT | ||
# SNOWFLAKE_USER | ||
# SNOWFLAKE_AUTHENTICATOR | ||
# SNOWFLAKE_PRIVATE_KEY | ||
} | ||
|
||
# Resources needed to run dbt-snowflake | ||
|
||
resource "snowflake_database" "database" { | ||
name = "DBT_SNOWFLAKE_DB" | ||
data_retention_time_in_days = 0 | ||
comment = "Used by `dbt-snowflake` for CI" | ||
} | ||
|
||
resource "snowflake_warehouse" "warehouse" { | ||
name = "DBT_SNOWFLAKE_WH" | ||
warehouse_size = "XSMALL" | ||
auto_suspend = 60 | ||
comment = "Used by `dbt-snowflake` for CI" | ||
} | ||
|
||
resource "snowflake_role" "role" { | ||
provider = snowflake.security_admin | ||
name = "DBT_SNOWFLAKE_ROLE" | ||
comment = "Application role for `dbt_snowflake`" | ||
} | ||
|
||
resource "snowflake_grant_privileges_to_account_role" "database_grant" { | ||
provider = snowflake.security_admin | ||
privileges = ["USAGE", "MODIFY", "CREATE SCHEMA"] | ||
account_role_name = snowflake_role.role.name | ||
|
||
on_account_object { | ||
object_type = "DATABASE" | ||
object_name = snowflake_database.database.name | ||
} | ||
} | ||
|
||
resource "snowflake_grant_privileges_to_account_role" "warehouse_grant" { | ||
provider = snowflake.security_admin | ||
privileges = ["USAGE"] | ||
account_role_name = snowflake_role.role.name | ||
|
||
on_account_object { | ||
object_type = "WAREHOUSE" | ||
object_name = snowflake_warehouse.warehouse.name | ||
} | ||
} | ||
|
||
resource "tls_private_key" "user" { | ||
algorithm = "RSA" | ||
rsa_bits = 2048 | ||
} | ||
|
||
resource "snowflake_user" "user" { | ||
provider = snowflake.security_admin | ||
name = "DBT_SNOWFLAKE" | ||
display_name = "dbt-snowflake" | ||
rsa_public_key = substr(tls_private_key.user.public_key_pem, 27, 398) | ||
default_warehouse = snowflake_warehouse.warehouse.name | ||
default_role = snowflake_role.role.name | ||
default_namespace = snowflake_database.database.name | ||
comment = "Application user for `dbt_snowflake`" | ||
} | ||
|
||
resource "snowflake_grant_account_role" "role_grant" { | ||
provider = snowflake.security_admin | ||
role_name = snowflake_role.role.name | ||
user_name = snowflake_user.user.name | ||
} | ||
|
||
output "dbt_snowflake_user_public_key" { | ||
value = tls_private_key.user.public_key_pem | ||
} | ||
|
||
output "dbt_snowflake_user_private_key" { | ||
value = tls_private_key.user.private_key_pem | ||
sensitive = true | ||
} | ||
|
||
# Additional resources required for integration tests | ||
|
||
resource "snowflake_database" "database_quoted" { | ||
name = "DBT_SNOWFLAKE_DB_QUOTED" | ||
data_retention_time_in_days = 0 | ||
comment = "Used by `dbt-snowflake` for CI" | ||
} | ||
|
||
resource "snowflake_database" "database_alt" { | ||
name = "DBT_SNOWFLAKE_DB_ALT" | ||
data_retention_time_in_days = 0 | ||
comment = "Used by `dbt-snowflake` for CI" | ||
} | ||
|
||
resource "snowflake_warehouse" "warehouse_alt" { | ||
name = "DBT_SNOWFLAKE_WH_ALT" | ||
warehouse_size = "XSMALL" | ||
auto_suspend = 60 | ||
comment = "Used by `dbt-snowflake` for CI" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters