dbt-labs / terraform-provider-dbtcloud

dbt Cloud Terraform Provider
https://registry.terraform.io/providers/dbt-labs/dbtcloud
MIT License
84 stars 19 forks source link

Example for snowflake credentials rotation? #54

Closed ernestoongaro closed 2 years ago

ernestoongaro commented 2 years ago

Is it possible to upload new snowflake credentials into an environment with this project?

GtheSheep commented 2 years ago

Hey @ernestoongaro - you should be able to use the Snowflake Credential resource combined with the Environment data source/ resource to do this by providing the credential_id to the environment I believe. Credential: https://registry.terraform.io/providers/GtheSheep/dbt-cloud/latest/docs/resources/dbt_cloud_snowflake_credential Env: https://registry.terraform.io/providers/GtheSheep/dbt-cloud/latest/docs/resources/dbt_cloud_environment

Is it a new or existing env specifically? With that I should be able to add an example for this. Thanks for this!

ernestoongaro commented 2 years ago

Thanks Gary! It would be for an existing environment, if you have an example that would help me a lot!

On Thu, Feb 10, 2022 at 11:53 AM Gary James @.***> wrote:

Hey @ernestoongaro https://github.com/ernestoongaro - you should be able to use the Snowflake Credential resource combined with the Environment data source/ resource to do this by providing the credential_id to the environment I believe. Credential: https://registry.terraform.io/providers/GtheSheep/dbt-cloud/latest/docs/resources/dbt_cloud_snowflake_credential Env: https://registry.terraform.io/providers/GtheSheep/dbt-cloud/latest/docs/resources/dbt_cloud_environment

Is it a new or existing env specifically? With that I should be able to add an example for this. Thanks for this!

— Reply to this email directly, view it on GitHub https://github.com/GtheSheep/terraform-provider-dbt-cloud/issues/54#issuecomment-1034832212, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALVKBP7JPAUXXH34C7SSTU2ORLNANCNFSM5N7RF5TQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

GtheSheep commented 2 years ago

Hey @ernestoongaro - In order to add the credential to an existing environment, you would need to import the environment to Terraform such that it can be managed as a resource (I think), in which case, a full example would be something like:

terraform {
  required_providers {
    dbt = {
      source  = "GtheSheep/dbt-cloud"
      version = "0.0.75"
    }
  }
}

provider "dbt" {
  account_id = <ACCOUNT ID>
  token      = "<TOKEN>"
}

data "dbt_cloud_project" "test_project" {
  project_id = <project ID>
}

resource "dbt_cloud_snowflake_credential" "new_credential" {
  project_id  = data.dbt_cloud_project.test_project.project_id
  auth_type   = "password"
  num_threads = 16
  schema      = "SCHEMA"
  user        = "user"
  password    = "password"
}

resource "dbt_cloud_environment" "test_environment" {
  dbt_version   = "1.0.1"
  name          = "test"
  project_id    = data.dbt_cloud_project.test_project.project_id
  type          = "deployment"
  credential_id = dbt_cloud_snowflake_credential.new_credential.credential_id
}

of course, I'd recommend passing the passwords at apply/ plan time as variables rather than storing in code, they're marked as sensitive in the provider, hope this helps 😸

ernestoongaro commented 2 years ago

Wow thanks so much! Will give it a go once I have the other pieces in place. Should this be saved into your examples folder somehow @GtheSheep?

GtheSheep commented 2 years ago

@ernestoongaro good call! I've added the credential and environment as relative files in the examples folder 😺

ernestoongaro commented 2 years ago

That's awesome! Thank you

(closed in https://github.com/GtheSheep/terraform-provider-dbt-cloud/commit/4bdacab58516349ea37f70b23afacac895426230 and https://github.com/GtheSheep/terraform-provider-dbt-cloud/commit/858f78db4d0532c2b1078de1cc5b56661ae6a1b5)