| page_title | dbtcloud_environment Resource - dbtcloud |
|---|---|
| subcategory | |
| description | Resource to manage dbt Cloud environments for the different dbt Cloud projects. In a given dbt Cloud project, one development environment can be defined and as many deployment environments as needed can be created. ~> In August 2024, dbt Cloud released the "global connection" feature, allowing connections to be defined at the account level and reused across environments and projects. This version of the provider has the connection_id as an optional field but it is recommended to start setting it up in your projects. In future versions, this field will become mandatory. |
Resource to manage dbt Cloud environments for the different dbt Cloud projects. In a given dbt Cloud project, one development environment can be defined and as many deployment environments as needed can be created. ~> In August 2024, dbt Cloud released the "global connection" feature, allowing connections to be defined at the account level and reused across environments and projects. This version of the provider has the connection_id as an optional field but it is recommended to start setting it up in your projects. In future versions, this field will become mandatory.
resource "dbtcloud_environment" "ci_environment" {
// the dbt_version is major.minor.0-latest , major.minor.0-pre, compatible, extended, versionless, latest or latest-fusion (by default, it is set to latest if not configured)
dbt_version = "latest"
name = "CI"
project_id = dbtcloud_project.dbt_project.id
type = "deployment"
credential_id = dbtcloud_snowflake_credential.ci_credential.credential_id
connection_id = dbtcloud_global_connection.my_global_connection.id
}
// we can also set a deployment environment as being the production one
resource "dbtcloud_environment" "prod_environment" {
dbt_version = "1.7.0-latest"
name = "Prod"
project_id = dbtcloud_project.dbt_project.id
type = "deployment"
credential_id = dbtcloud_snowflake_credential.prod_credential.credential_id
deployment_type = "production"
connection_id = dbtcloud_connection.my_legacy_connection.connection_id
}
// Creating a development environment
resource "dbtcloud_environment" "dev_environment" {
dbt_version = "latest"
name = "Dev"
project_id = dbtcloud_project.dbt_project.id
type = "development"
connection_id = dbtcloud_global_connection.my_other_global_connection.id
// credential_id is not actionable for development environments
}
// Deployment environment with a primary profile (binds connection + credentials via profile)
// NOTE: avoid setting connection_id, credential_id, or extended_attributes_id alongside
// primary_profile_id — dbt Cloud may propagate the environment's values onto the profile,
// overwriting the profile's own settings and affecting other environments sharing that profile.
resource "dbtcloud_environment" "profiled_environment" {
dbt_version = "latest"
name = "Staging"
project_id = dbtcloud_project.dbt_project.id
type = "deployment"
deployment_type = "staging"
primary_profile_id = dbtcloud_profile.my_profile.profile_id
}name(String) The name of the environmentproject_id(Number) Project ID to create the environment intype(String) The type of environment (must be either development or deployment)
connection_id(Number) A connection ID (used with Global Connections)credential_id(Number) The Credential ID for this environment. A credential is not actionable for development environments, as users have to set their own development credentials in dbt Cloud.custom_branch(String) The custom branch name to usedbt_version(String) Version number of dbt to use in this environment. It needs to be in the formatmajor.minor.0-latest(e.g.1.5.0-latest),major.minor.0-pre,compatible,extended,versionless,latestorlatest-fusion. Whileversionlessis still supported, usinglatestis recommended. Defaults tolatestif no version is provideddeployment_type(String) The type of environment. Only valid for environments of type 'deployment' and for now can only be 'production', 'staging' or left empty for generic environmentsenable_model_query_history(Boolean) Whether to enable model query history in this environment. As of Oct 2024, works only for Snowflake and BigQuery.extended_attributes_id(Number) The ID of the extended attributes appliedis_active(Boolean) Whether the environment is activeprimary_profile_id(Number) The ID of the primary profile for this environment. A profile ties together a connection and credentials. Only applicable to deployment environments. ~> Settingprimary_profile_idalongsideconnection_id,credential_id, orextended_attributes_idwill produce an error. When a profile is assigned, the API determines those values from the profile. Manage connection, credentials, and extended attributes through thedbtcloud_profileresource instead.resource_metadata(Dynamic) Metadata for tracking resource identity during account migrations. Stored in Terraform state only and not sent to the API.use_custom_branch(Boolean) Whether to use a custom git branch in this environment
environment_id(Number) The ID of the environment. Duplicated. Here for backward compatibility.id(String) The ID of environment.
Import is supported using the following syntax:
# using import blocks (requires Terraform >= 1.5)
import {
to = dbtcloud_environment.prod_environment
id = "project_id:environment_id"
}
import {
to = dbtcloud_environment.prod_environment
id = "12345:6789"
}
# using the older import command
terraform import dbtcloud_environment.prod_environment "project_id:environment_id"
terraform import dbtcloud_environment.prod_environment 12345:6789