Skip to content

Commit 1096b10

Browse files
committed
Update doc and use global connection
1 parent 4849d8f commit 1096b10

12 files changed

Lines changed: 61 additions & 42 deletions

File tree

examples/dbtcloud_github_snowflake/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ terraform {
1414
}
1515
dbtcloud = {
1616
source = "dbt-labs/dbtcloud"
17-
version = ">= 0.2.10"
17+
version = ">= 0.3.0"
1818
}
1919
}
2020
}

modules/combined/dbtcloud_github_snowflake/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
7-
| <a name="requirement_dbtcloud"></a> [dbtcloud](#requirement\_dbtcloud) | >= 0.2.10 |
7+
| <a name="requirement_dbtcloud"></a> [dbtcloud](#requirement\_dbtcloud) | >= 0.3.0 |
88
| <a name="requirement_github"></a> [github](#requirement\_github) | ~> 5.0 |
99
| <a name="requirement_snowflake"></a> [snowflake](#requirement\_snowflake) | ~> 0.71 |
1010

modules/combined/dbtcloud_github_snowflake/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ terraform {
1313
}
1414
dbtcloud = {
1515
source = "dbt-labs/dbtcloud"
16-
version = ">= 0.2.10"
16+
version = ">= 0.3.0"
1717
}
1818
}
1919
}

modules/dbtcloud/dbtcloud_common/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
7-
| <a name="requirement_dbtcloud"></a> [dbtcloud](#requirement\_dbtcloud) | >= 0.2.10 |
7+
| <a name="requirement_dbtcloud"></a> [dbtcloud](#requirement\_dbtcloud) | >= 0.3.0 |
88

99
## Providers
1010

1111
| Name | Version |
1212
|------|---------|
13-
| <a name="provider_dbtcloud"></a> [dbtcloud](#provider\_dbtcloud) | >= 0.2.10 |
13+
| <a name="provider_dbtcloud"></a> [dbtcloud](#provider\_dbtcloud) | >= 0.3.0 |
1414

1515
## Modules
1616

@@ -26,21 +26,20 @@ No modules.
2626
| [dbtcloud_job.ci](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/job) | resource |
2727
| [dbtcloud_job.daily_prod](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/job) | resource |
2828
| [dbtcloud_project.dbt_project](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/project) | resource |
29-
| [dbtcloud_project_connection.dbt_project_connection](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/project_connection) | resource |
3029
| [dbtcloud_project_repository.dbt_project_repository](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/project_repository) | resource |
3130
| [dbtcloud_repository.dbt_repository](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/repository) | resource |
3231

3332
## Inputs
3433

3534
| Name | Description | Type | Default | Required |
3635
|------|-------------|------|---------|:--------:|
37-
| <a name="input_database_envs"></a> [database\_envs](#input\_database\_envs) | n/a | <pre>map(object({<br> wh_size = string<br> defer_to_env_name = string<br> git_branch = string<br> }))</pre> | n/a | yes |
36+
| <a name="input_database_envs"></a> [database\_envs](#input\_database\_envs) | The different environments required (i.e. DEV, PROD etc...) and their properties | <pre>map(object({<br> wh_size = string<br> defer_to_env_name = string<br> git_branch = string<br> }))</pre> | n/a | yes |
3837
| <a name="input_dbt_connection"></a> [dbt\_connection](#input\_dbt\_connection) | The connection to the DW | `map(any)` | n/a | yes |
39-
| <a name="input_dbt_creds"></a> [dbt\_creds](#input\_dbt\_creds) | n/a | `map(any)` | n/a | yes |
40-
| <a name="input_dbt_creds_ci"></a> [dbt\_creds\_ci](#input\_dbt\_creds\_ci) | n/a | `map(any)` | n/a | yes |
38+
| <a name="input_dbt_creds"></a> [dbt\_creds](#input\_dbt\_creds) | A map of environment name to dbt cloud credential ID | <pre>map(object({<br> credential_id = integer<br> }))</pre> | n/a | yes |
39+
| <a name="input_dbt_creds_ci"></a> [dbt\_creds\_ci](#input\_dbt\_creds\_ci) | A map of environment name to dbt cloud credential ID for CI | <pre>map(object({<br> credential_id = integer<br> }))</pre> | n/a | yes |
4140
| <a name="input_dbt_project_name"></a> [dbt\_project\_name](#input\_dbt\_project\_name) | The project name in dbt Cloud | `string` | n/a | yes |
4241
| <a name="input_dbt_version"></a> [dbt\_version](#input\_dbt\_version) | The dbt version | `string` | n/a | yes |
43-
| <a name="input_defer_from_to"></a> [defer\_from\_to](#input\_defer\_from\_to) | n/a | `map(any)` | n/a | yes |
42+
| <a name="input_defer_from_to"></a> [defer\_from\_to](#input\_defer\_from\_to) | Map of all the environments that can defer to another one in CI. Key and Value are the environment names | <pre>map(object({<br> defer_to_env_name = string<br> }))</pre> | n/a | yes |
4443
| <a name="input_github_installation_id"></a> [github\_installation\_id](#input\_github\_installation\_id) | The project name in dbt Cloud | `string` | n/a | yes |
4544
| <a name="input_github_repo_remote_url"></a> [github\_repo\_remote\_url](#input\_github\_repo\_remote\_url) | The remote URL for the GitHub repository | `string` | `null` | no |
4645

modules/dbtcloud/dbtcloud_common/main.tf

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
dbtcloud = {
66
source = "dbt-labs/dbtcloud"
7-
version = ">= 0.2.10"
7+
version = ">= 0.3.0"
88
}
99
}
1010
}
@@ -14,11 +14,6 @@ resource "dbtcloud_project" "dbt_project" {
1414
name = var.dbt_project_name
1515
}
1616

17-
resource "dbtcloud_project_connection" "dbt_project_connection" {
18-
project_id = dbtcloud_project.dbt_project.id
19-
connection_id = var.dbt_connection.connection_id
20-
}
21-
2217
resource "dbtcloud_repository" "dbt_repository" {
2318
project_id = dbtcloud_project.dbt_project.id
2419
remote_url = var.github_repo_remote_url
@@ -40,6 +35,7 @@ resource "dbtcloud_environment" "envs" {
4035
type = each.key == "DEV" ? "development" : "deployment"
4136
deployment_type = each.key == "PROD" ? "production" : null
4237
credential_id = each.key == "DEV" ? null : var.dbt_creds[each.key].credential_id
38+
connection_id = var.dbt_connection.connection_id
4339
custom_branch = each.value["git_branch"]
4440
use_custom_branch = each.value["git_branch"] == null ? false : true
4541
}
@@ -51,6 +47,7 @@ resource "dbtcloud_environment" "envs_ci" {
5147
project_id = dbtcloud_project.dbt_project.id
5248
type = "deployment"
5349
credential_id = var.dbt_creds_ci[each.key].credential_id
50+
connection_id = var.dbt_connection.connection_id
5451
custom_branch = var.database_envs[each.value["defer_to_env_name"]].git_branch
5552
use_custom_branch = var.database_envs[each.value["defer_to_env_name"]].git_branch == null ? false : true
5653
}

modules/dbtcloud/dbtcloud_common/variables.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ variable "dbt_version" {
2727
}
2828

2929
variable "database_envs" {
30+
description = "The different environments required (i.e. DEV, PROD etc...) and their properties"
3031
type = map(object({
3132
wh_size = string
3233
defer_to_env_name = string
@@ -35,13 +36,22 @@ variable "database_envs" {
3536
}
3637

3738
variable "dbt_creds" {
38-
type = map(any)
39+
description = "A map of environment name to dbt cloud credential ID"
40+
type = map(object({
41+
credential_id = integer
42+
}))
3943
}
4044

4145
variable "dbt_creds_ci" {
42-
type = map(any)
46+
description = "A map of environment name to dbt cloud credential ID for CI"
47+
type = map(object({
48+
credential_id = integer
49+
}))
4350
}
4451

4552
variable "defer_from_to" {
46-
type = map(any)
53+
description = "Map of all the environments that can defer to another one in CI. Key and Value are the environment names"
54+
type = map(object({
55+
defer_to_env_name = string
56+
}))
4757
}

modules/dbtcloud/dbtcloud_snowflake/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
7-
| <a name="requirement_dbtcloud"></a> [dbtcloud](#requirement\_dbtcloud) | >= 0.2.10 |
7+
| <a name="requirement_dbtcloud"></a> [dbtcloud](#requirement\_dbtcloud) | >= 0.3.0 |
88

99
## Providers
1010

1111
| Name | Version |
1212
|------|---------|
13-
| <a name="provider_dbtcloud"></a> [dbtcloud](#provider\_dbtcloud) | >= 0.2.10 |
13+
| <a name="provider_dbtcloud"></a> [dbtcloud](#provider\_dbtcloud) | >= 0.3.0 |
1414

1515
## Modules
1616

@@ -20,7 +20,7 @@ No modules.
2020

2121
| Name | Type |
2222
|------|------|
23-
| [dbtcloud_connection.dbt_connection](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/connection) | resource |
23+
| [dbtcloud_global_connection.dbt_connection](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/global_connection) | resource |
2424
| [dbtcloud_snowflake_credential.creds](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/snowflake_credential) | resource |
2525
| [dbtcloud_snowflake_credential.creds_ci](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/snowflake_credential) | resource |
2626

@@ -30,8 +30,8 @@ No modules.
3030
|------|-------------|------|---------|:--------:|
3131
| <a name="input_dbt_project_id"></a> [dbt\_project\_id](#input\_dbt\_project\_id) | The Project ID for the dbt Cloud Project | `number` | n/a | yes |
3232
| <a name="input_dbt_project_name"></a> [dbt\_project\_name](#input\_dbt\_project\_name) | The Project ID for the dbt Cloud Project | `string` | n/a | yes |
33-
| <a name="input_defer_from_to"></a> [defer\_from\_to](#input\_defer\_from\_to) | n/a | `map(any)` | n/a | yes |
34-
| <a name="input_envs_except_dev"></a> [envs\_except\_dev](#input\_envs\_except\_dev) | n/a | `map(any)` | n/a | yes |
33+
| <a name="input_defer_from_to"></a> [defer\_from\_to](#input\_defer\_from\_to) | Map of all the environments that can defer to another one in CI. Key and Value are the environment names | <pre>map(object({<br> defer_to_env_name = string<br> }))</pre> | n/a | yes |
34+
| <a name="input_envs_except_dev"></a> [envs\_except\_dev](#input\_envs\_except\_dev) | The deployment environments. A subset of `database_envs`. | `map(any)` | n/a | yes |
3535
| <a name="input_snowflake_account"></a> [snowflake\_account](#input\_snowflake\_account) | The Snowflake Account ID | `string` | n/a | yes |
3636
| <a name="input_snowflake_databases"></a> [snowflake\_databases](#input\_snowflake\_databases) | The Snowflake Databases that were created | <pre>map(object({<br> name = string<br> }))</pre> | n/a | yes |
3737
| <a name="input_snowflake_roles"></a> [snowflake\_roles](#input\_snowflake\_roles) | The Snowflake Roles that were created | <pre>map(object({<br> name = string<br> }))</pre> | n/a | yes |

modules/dbtcloud/dbtcloud_snowflake/main.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ terraform {
55
required_providers {
66
dbtcloud = {
77
source = "dbt-labs/dbtcloud"
8-
version = ">= 0.2.10"
8+
version = ">= 0.3.0"
99
}
1010
}
1111
}
1212

13-
// create a connection and link the project to the connection
13+
14+
// create a global connection that we will link to environments
1415
// this is an example with Snowflake but for other warehouses please look at the resource docs
15-
resource "dbtcloud_connection" "dbt_connection" {
16-
project_id = var.dbt_project_id
17-
type = "snowflake"
18-
name = "WH ${var.dbt_project_name}"
19-
account = var.snowflake_account
20-
database = var.snowflake_databases["DEV"].name
21-
role = var.snowflake_roles["DEV"].name
22-
warehouse = var.snowflake_warehouses["DEV"].name
16+
resource "dbtcloud_global_connection" "dbt_connection" {
17+
name = "Snowflake DW - ${var.dbt_project_name}"
18+
snowflake = {
19+
account = var.snowflake_account
20+
database = var.snowflake_databases["DEV"].name
21+
warehouse = var.snowflake_warehouses["DEV"].name
22+
role = var.snowflake_roles["DEV"].name
23+
}
2324
}
2425

2526
// we use user/password but there are other options on the resource docs

modules/dbtcloud/dbtcloud_snowflake/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
output "dbt_connection" {
2-
value = dbtcloud_connection.dbt_connection
2+
value = dbtcloud_global_connection.dbt_connection
33
}
44

55
output "dbt_creds" {

modules/dbtcloud/dbtcloud_snowflake/variables.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ variable "snowflake_service_users" {
4343
}
4444

4545
variable "envs_except_dev" {
46+
description = "The deployment environments. A subset of `database_envs`."
4647
type = map(any)
4748
}
4849

4950
variable "defer_from_to" {
50-
type = map(any)
51+
description = "Map of all the environments that can defer to another one in CI. Key and Value are the environment names"
52+
type = map(object({
53+
defer_to_env_name = string
54+
}))
5155
}

0 commit comments

Comments
 (0)