Skip to content

Commit dfdaee2

Browse files
authored
Merge pull request #196 from dbt-labs/release-0.2.9
Release 0.2.9
2 parents e9ca6cf + 599462e commit dfdaee2

24 files changed

+886
-11
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.8...HEAD)
5+
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.9...HEAD)
6+
7+
## [0.2.9](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.8...v0.2.9)
8+
9+
## Changes
10+
11+
- Add support for extended attributes for environments [(docs)](https://docs.getdbt.com/docs/dbt-cloud-environments#extended-attributes-beta), allowing people to add connection attributes available in dbt-core but not in the dbt Cloud interface
12+
- [#191](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/191) - Allow setting a description for jobs
613

714
## [0.2.8](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.7...v0.2.8)
815

docs/data-sources/environment.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ description: |-
2626
- `custom_branch` (String) Which custom branch to use in this environment
2727
- `dbt_version` (String) Version number of dbt to use in this environment, usually in the format 1.2.0-latest rather than core versions
2828
- `deployment_type` (String) The type of deployment environment (currently 'production' or empty)
29+
- `extended_attributes_id` (Number) The ID of the extended attributes applied
2930
- `id` (String) The ID of this resource.
3031
- `is_active` (Boolean) Whether the environment is active
3132
- `name` (String) Environment name
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "dbtcloud_extended_attributes Data Source - dbtcloud"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# dbtcloud_extended_attributes (Data Source)
10+
11+
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "dbtcloud_extended_attributes" "my_extended_attributes" {
17+
extended_attributes_id = 12345
18+
project_id = 6789
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `extended_attributes_id` (Number) ID of the extended attributes
28+
- `project_id` (Number) Project ID the extended attributes refers to
29+
30+
### Read-Only
31+
32+
- `extended_attributes` (String) A JSON string listing the extended attributes mapping
33+
- `id` (String) The ID of this resource.
34+
- `state` (Number) The state of the extended attributes (1 = active, 2 = inactive)
35+
36+

docs/data-sources/job.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ description: |-
2424

2525
- `deferring_environment_id` (Number) ID of the environment this job defers to
2626
- `deferring_job_id` (Number) ID of the job this job defers to
27+
- `description` (String) Long description for the job
2728
- `environment_id` (Number) ID of the environment the job is in
2829
- `id` (String) The ID of this resource.
2930
- `name` (String) Given name for the job

docs/resources/environment.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ resource "dbtcloud_environment" "prod_environment" {
5151
- `credential_id` (Number) Credential ID to create the environment with. A credential is not required for development environments but is required for deployment environments
5252
- `custom_branch` (String) Which custom branch to use in this environment
5353
- `deployment_type` (String) The type of environment. Only valid for environments of type 'deployment' and for now can only be empty or set to 'production'
54+
- `extended_attributes_id` (Number) ID of the extended attributes for the environment
5455
- `is_active` (Boolean) Whether the environment is active
5556
- `use_custom_branch` (Boolean) Whether to use a custom git branch in this environment
5657

docs/resources/extended_attributes.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
page_title: "dbtcloud_extended_attributes Resource - dbtcloud"
3+
subcategory: ""
4+
description: |-
5+
This resource allows setting extended attributes which can be assigned to a given environment (see docs https://docs.getdbt.com/docs/dbt-cloud-environments#extended-attributes-beta).In dbt Cloud those values are provided as YML but in the provider they need to be provided as JSON (see example below).
6+
---
7+
8+
# dbtcloud_extended_attributes (Resource)
9+
10+
11+
This resource allows setting extended attributes which can be assigned to a given environment ([see docs](https://docs.getdbt.com/docs/dbt-cloud-environments#extended-attributes-beta)).<br/><br/>In dbt Cloud those values are provided as YML but in the provider they need to be provided as JSON (see example below).
12+
13+
## Example Usage
14+
15+
```terraform
16+
# extended_attributes can be set as a raw JSON string or encoded with Terraform's `jsonencode()` function
17+
# we recommend using `jsonencode()` to avoid Terraform reporting changes due to whitespaces or keys ordering
18+
resource "dbtcloud_extended_attributes" "my_attributes" {
19+
extended_attributes = jsonencode(
20+
{
21+
type = "databricks"
22+
catalog = "dbt_catalog"
23+
http_path = "/sql/your/http/path"
24+
my_nested_field = {
25+
subfield = "my_value"
26+
}
27+
}
28+
)
29+
project_id = var.dbt_project_id
30+
}
31+
32+
resource dbtcloud_environment issue_depl {
33+
dbt_version = "1.6.0-latest"
34+
name = "My environment"
35+
project_id = var.dbt_project_id
36+
type = "deployment"
37+
use_custom_branch = false
38+
credential_id = var.dbt_credential_id
39+
deployment_type = "production"
40+
extended_attributes_id = dbtcloud_extended_attributes.my_attributes.extended_attributes_id
41+
}
42+
```
43+
44+
<!-- schema generated by tfplugindocs -->
45+
## Schema
46+
47+
### Required
48+
49+
- `extended_attributes` (String) A JSON string listing the extended attributes mapping. The keys are the connections attributes available in the `profiles.yml` for a given adapter. Any fields entered will override connection details or credentials set on the environment or project. To avoid incorrect Terraform diffs, it is recommended to create this string using `jsonencode` in your Terraform code. (see example)
50+
- `project_id` (Number) Project ID to create the extended attributes in
51+
52+
### Optional
53+
54+
- `state` (Number) Extended Attributes state (1 is active, 2 is inactive)
55+
56+
### Read-Only
57+
58+
- `extended_attributes_id` (Number) Extended Attributes ID
59+
- `id` (String) The ID of this resource.
60+
61+
## Import
62+
63+
Import is supported using the following syntax:
64+
65+
```shell
66+
# Import using a project ID and extended attribute ID found in the URL or via the API.
67+
terraform import dbtcloud_extended_attributes.test_extended_attributes "project_id_id:extended_attributes_id"
68+
terraform import dbtcloud_extended_attributes.test_extended_attributes 12345:6789
69+
```

docs/resources/job.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ resource "dbtcloud_job" "test" {
5959
- `dbt_version` (String) Version number of dbt to use in this job, usually in the format 1.2.0-latest rather than core versions
6060
- `deferring_environment_id` (Number) Environment identifier that this job defers to (new deferring approach)
6161
- `deferring_job_id` (Number) Job identifier that this job defers to (legacy deferring approach)
62+
- `description` (String) Description for the job
6263
- `generate_docs` (Boolean) Flag for whether the job should generate documentation
6364
- `is_active` (Boolean) Flag for whether the job is marked active or deleted
6465
- `num_threads` (Number) Number of threads to use in the job
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "dbtcloud_extended_attributes" "my_extended_attributes" {
2+
extended_attributes_id = 12345
3+
project_id = 6789
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Import using a project ID and extended attribute ID found in the URL or via the API.
2+
terraform import dbtcloud_extended_attributes.test_extended_attributes "project_id_id:extended_attributes_id"
3+
terraform import dbtcloud_extended_attributes.test_extended_attributes 12345:6789
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# extended_attributes can be set as a raw JSON string or encoded with Terraform's `jsonencode()` function
2+
# we recommend using `jsonencode()` to avoid Terraform reporting changes due to whitespaces or keys ordering
3+
resource "dbtcloud_extended_attributes" "my_attributes" {
4+
extended_attributes = jsonencode(
5+
{
6+
type = "databricks"
7+
catalog = "dbt_catalog"
8+
http_path = "/sql/your/http/path"
9+
my_nested_field = {
10+
subfield = "my_value"
11+
}
12+
}
13+
)
14+
project_id = var.dbt_project_id
15+
}
16+
17+
resource dbtcloud_environment issue_depl {
18+
dbt_version = "1.6.0-latest"
19+
name = "My environment"
20+
project_id = var.dbt_project_id
21+
type = "deployment"
22+
use_custom_branch = false
23+
credential_id = var.dbt_credential_id
24+
deployment_type = "production"
25+
extended_attributes_id = dbtcloud_extended_attributes.my_attributes.extended_attributes_id
26+
}

pkg/data_sources/environment.go

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ var environmentSchema = map[string]*schema.Schema{
6060
Computed: true,
6161
Description: "The type of deployment environment (currently 'production' or empty)",
6262
},
63+
"extended_attributes_id": &schema.Schema{
64+
Type: schema.TypeInt,
65+
Computed: true,
66+
Description: "The ID of the extended attributes applied",
67+
},
6368
}
6469

6570
func DatasourceEnvironment() *schema.Resource {
@@ -112,6 +117,9 @@ func datasourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m in
112117
if err := d.Set("deployment_type", environment.DeploymentType); err != nil {
113118
return diag.FromErr(err)
114119
}
120+
if err := d.Set("extended_attributes_id", environment.ExtendedAttributesID); err != nil {
121+
return diag.FromErr(err)
122+
}
115123

116124
d.SetId(fmt.Sprintf("%d%s%d", environment.Project_Id, dbt_cloud.ID_DELIMITER, *environment.ID))
117125

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package data_sources
2+
3+
import (
4+
"context"
5+
"strconv"
6+
7+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
)
11+
12+
var extendedAttributesSchema = map[string]*schema.Schema{
13+
"extended_attributes_id": &schema.Schema{
14+
Type: schema.TypeInt,
15+
Required: true,
16+
Description: "ID of the extended attributes",
17+
},
18+
"project_id": &schema.Schema{
19+
Type: schema.TypeInt,
20+
Required: true,
21+
Description: "Project ID the extended attributes refers to",
22+
},
23+
"state": &schema.Schema{
24+
Type: schema.TypeInt,
25+
Computed: true,
26+
Description: "The state of the extended attributes (1 = active, 2 = inactive)",
27+
},
28+
"extended_attributes": &schema.Schema{
29+
Type: schema.TypeString,
30+
Computed: true,
31+
Description: "A JSON string listing the extended attributes mapping",
32+
},
33+
}
34+
35+
func DatasourceExtendedAttributes() *schema.Resource {
36+
return &schema.Resource{
37+
ReadContext: datasourceExtendedAttributesRead,
38+
Schema: extendedAttributesSchema,
39+
}
40+
}
41+
42+
func datasourceExtendedAttributesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
43+
c := m.(*dbt_cloud.Client)
44+
45+
var diags diag.Diagnostics
46+
47+
extendedAttributesID := d.Get("extended_attributes_id").(int)
48+
projectID := d.Get("project_id").(int)
49+
50+
extendedAttributes, err := c.GetExtendedAttributes(projectID, extendedAttributesID)
51+
if err != nil {
52+
return diag.FromErr(err)
53+
}
54+
55+
if err := d.Set("extended_attributes_id", extendedAttributes.ID); err != nil {
56+
return diag.FromErr(err)
57+
}
58+
if err := d.Set("state", extendedAttributes.State); err != nil {
59+
return diag.FromErr(err)
60+
}
61+
if err := d.Set("project_id", extendedAttributes.ProjectID); err != nil {
62+
return diag.FromErr(err)
63+
}
64+
if err := d.Set("extended_attributes", string(extendedAttributes.ExtendedAttributes)); err != nil {
65+
return diag.FromErr(err)
66+
}
67+
68+
d.SetId(strconv.Itoa(*extendedAttributes.ID))
69+
70+
return diags
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package data_sources_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestDbtCloudExtendedAttributesDataSource(t *testing.T) {
11+
12+
config := extendedAttributes()
13+
14+
check := resource.ComposeAggregateTestCheckFunc(
15+
resource.TestCheckResourceAttrSet("data.dbtcloud_extended_attributes.test", "extended_attributes_id"),
16+
resource.TestCheckResourceAttrSet("data.dbtcloud_extended_attributes.test", "project_id"),
17+
resource.TestCheckResourceAttrSet("data.dbtcloud_extended_attributes.test", "extended_attributes"),
18+
resource.TestCheckResourceAttrSet("data.dbtcloud_environment.test", "extended_attributes_id"),
19+
)
20+
21+
resource.ParallelTest(t, resource.TestCase{
22+
Providers: providers(),
23+
Steps: []resource.TestStep{
24+
{
25+
Config: config,
26+
Check: check,
27+
},
28+
},
29+
})
30+
}
31+
32+
func extendedAttributes() string {
33+
return fmt.Sprintf(`
34+
resource "dbtcloud_project" "test_project" {
35+
name = "extended_attributes_test_project"
36+
}
37+
38+
resource "dbtcloud_environment" "test_environment" {
39+
project_id = dbtcloud_project.test_project.id
40+
name = "extended_attributes_test_env"
41+
dbt_version = "%s"
42+
type = "development"
43+
extended_attributes_id = dbtcloud_extended_attributes.test.extended_attributes_id
44+
}
45+
46+
resource "dbtcloud_extended_attributes" "test" {
47+
extended_attributes = jsonencode(
48+
{
49+
type = "databricks"
50+
catalog = "dbt_catalog"
51+
http_path = "/sql/your/http/path"
52+
my_nested_field = {
53+
subfield = "my_value"
54+
}
55+
}
56+
)
57+
project_id = dbtcloud_project.test_project.id
58+
}
59+
60+
data "dbtcloud_extended_attributes" "test" {
61+
extended_attributes_id = dbtcloud_extended_attributes.test.extended_attributes_id
62+
project_id = dbtcloud_project.test_project.id
63+
}
64+
65+
data "dbtcloud_environment" "test" {
66+
project_id = dbtcloud_project.test_project.id
67+
environment_id = dbtcloud_environment.test_environment.environment_id
68+
}
69+
`, DBT_CLOUD_VERSION)
70+
}

pkg/data_sources/helpers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
const (
9-
DBT_CLOUD_VERSION = "1.0.0"
9+
DBT_CLOUD_VERSION = "1.6.0-latest"
1010
)
1111

1212
func providers() map[string]*schema.Provider {

pkg/data_sources/job.go

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ var jobSchema = map[string]*schema.Schema{
2626
Computed: true,
2727
Description: "Given name for the job",
2828
},
29+
"description": &schema.Schema{
30+
Type: schema.TypeString,
31+
Computed: true,
32+
Description: "Long description for the job",
33+
},
2934
"job_id": &schema.Schema{
3035
Type: schema.TypeInt,
3136
Required: true,
@@ -91,6 +96,9 @@ func datasourceJobRead(ctx context.Context, d *schema.ResourceData, m interface{
9196
if err := d.Set("name", job.Name); err != nil {
9297
return diag.FromErr(err)
9398
}
99+
if err := d.Set("description", job.Description); err != nil {
100+
return diag.FromErr(err)
101+
}
94102
if err := d.Set("job_id", job.ID); err != nil {
95103
return diag.FromErr(err)
96104
}

0 commit comments

Comments
 (0)