Skip to content

Commit

Permalink
Merge pull request #242 from dbt-labs/release-0.2.22
Browse files Browse the repository at this point in the history
  • Loading branch information
b-per authored Mar 20, 2024
2 parents 86a5840 + 740d0d4 commit 5069fe2
Show file tree
Hide file tree
Showing 28 changed files with 557 additions and 247 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

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

## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.21...HEAD)
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.22...HEAD)

## [0.2.22](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.21...v0.2.22)

## Changes

- [#240](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/240) Add notice of deprecation for `triggers.custom_branch_only` for jobs and update logic to make it work even though people have it to true or false in their config. We might raise an error if the field is still there in the future.
- Update diff calculation for Extended Attributes, allowing strings which are not set with `jsonencode()`
- [#241](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/241) Force recreation of env vars when values change to work with the recent changes in the dbt Cloud API

## Documentation

- Add list of permission names and permission codes in the docs of the `service_token` and `group`
- Add info in `dbtcloud_repository` about the need to also create a `dbtcloud_project_repository`

## [0.2.21](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.2.20...v0.2.21)

Expand Down
29 changes: 28 additions & 1 deletion docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,34 @@ description: |-

# dbtcloud_group (Resource)

*Note*: Groups currently do not support updates, as per both the API and the UI.
The mapping of permission names [from the docs](https://docs.getdbt.com/docs/cloud/manage-access/enterprise-permissions) to the permissions to set in Terraform is the following:

|Permission name......... | Permission code|
|-- | --|
|Account Admin | account_admin|
|Account Viewer | account_viewer|
|Admin | admin|
|Analyst | analyst|
|Billing Admin | billing_admin|
|Database Admin | database_admin|
|Developer | developer|
|Git Admin | git_admin|
|Job Admin | job_admin|
|Job Runner | job_runner|
|Job Viewer | job_viewer|
|Member | member|
|Metadata Only | metadata_only|
|Owner | owner|
|Project Creator | project_creator|
|Read-Only | readonly|
|Security Admin | security_admin|
|Semantic Layer Only | semantic_layer_only|
|Stakeholder | stakeholder|
|Team Admin | team_admin|
|Webhooks Only | webhooks_only|




## Example Usage

Expand Down
10 changes: 1 addition & 9 deletions docs/resources/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ description: |-
Those improvements include modifications to deferral which was historically set at the job level and will now be set at the environment level.
Deferral can still be set to "self" by setting `self_deferring` to `true` but with the new approach, deferral to other runs need to be done with `deferring_environment_id` instead of `deferring_job_id`.

~> As of beginning of February 2024, job chaining with `job_completion_trigger_condition` is in private beta and not available to all users.
<br/>
<br/>
This notice will be removed once the feature is generally available.


## Example Usage

Expand All @@ -41,7 +36,6 @@ resource "dbtcloud_job" "daily_job" {
run_generate_sources = true
target_name = "default"
triggers = {
"custom_branch_only" : false,
"github_webhook" : false,
"git_provider_webhook" : false,
"schedule" : true
Expand All @@ -67,7 +61,6 @@ resource "dbtcloud_job" "ci_job" {
project_id = dbtcloud_project.dbt_project.id
run_generate_sources = false
triggers = {
"custom_branch_only" : true,
"github_webhook" : true,
"git_provider_webhook" : true,
"schedule" : false
Expand All @@ -91,7 +84,6 @@ resource "dbtcloud_job" "downstream_job" {
project_id = dbtcloud_project.dbt_project2.id
run_generate_sources = true
triggers = {
"custom_branch_only" : false,
"github_webhook" : false,
"git_provider_webhook" : false,
"schedule" : false
Expand All @@ -115,7 +107,7 @@ resource "dbtcloud_job" "downstream_job" {
- `execute_steps` (List of String) List of commands to execute for the job
- `name` (String) Job name
- `project_id` (Number) Project ID to create the job in
- `triggers` (Map of Boolean) Flags for which types of triggers to use, the values are `github_webhook`, `git_provider_webhook`, `schedule` and `custom_branch_only`. <br>`custom_branch_only` is only relevant for CI jobs triggered automatically on PR creation to only trigger a job on a PR to the custom branch of the environment. To create a job in a 'deactivated' state, set all to `false`.
- `triggers` (Map of Boolean) Flags for which types of triggers to use, the values are `github_webhook`, `git_provider_webhook`, and `schedule`. <br>`custom_branch_only` used to be allowed but has been deprecated from the API. The jobs will use the custom branch of the environment. Please remove the `custom_branch_only` from your config. <br>To create a job in a 'deactivated' state, set all to `false`.

### Optional

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/project_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
page_title: "dbtcloud_project_repository Resource - dbtcloud"
subcategory: ""
description: |-
This resource allows you to link a dbt Cloud project to a git repository.
---

# dbtcloud_project_repository (Resource)



This resource allows you to link a dbt Cloud project to a git repository.

## Example Usage

Expand Down
6 changes: 4 additions & 2 deletions docs/resources/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ description: |-

# dbtcloud_repository (Resource)

*Note*: Some upstream resources can be slow to create, so if creating a project at
the same time as the repository, it's recommended to use the `depends_on` meta argument.
This resource allows you to manage connections to git repositories in dbt Cloud.

By itself, this resource won't show you the repository in the dbt Cloud UI.
You will need to also set up a [`dbtcloud_project_repository` resource](https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/resources/project_repository) as well to link your dbt Cloud project and the git repository.

In order to find the `github_installation_id`, you can log in to dbt Cloud, replace `<dbt_cloud_url>` by your dbt Cloud
URL and run the following commands in the Google Chrome console:
Expand Down
29 changes: 26 additions & 3 deletions docs/resources/service_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ description: |-

# dbtcloud_service_token (Resource)

The mapping of permission names [from the docs](https://docs.getdbt.com/docs/cloud/manage-access/enterprise-permissions) to the permissions to set in Terraform is the following:

|Permission name......... | Permission code|
|-- | --|
|Account Admin | account_admin|
|Account Viewer | account_viewer|
|Admin | admin|
|Analyst | analyst|
|Billing Admin | billing_admin|
|Database Admin | database_admin|
|Developer | developer|
|Git Admin | git_admin|
|Job Admin | job_admin|
|Job Runner | job_runner|
|Job Viewer | job_viewer|
|Member | member|
|Metadata Only | metadata_only|
|Owner | owner|
|Project Creator | project_creator|
|Read-Only | readonly|
|Security Admin | security_admin|
|Semantic Layer Only | semantic_layer_only|
|Stakeholder | stakeholder|
|Team Admin | team_admin|
|Webhooks Only | webhooks_only|




Expand All @@ -29,9 +55,6 @@ resource "dbtcloud_service_token" "test_service_token" {
project_id = dbtcloud_project.dbt_project.id
}
}
// permission_set accepts one of the following values:
// "account_admin","admin","database_admin","git_admin","team_admin","job_admin","job_viewer","analyst","developer","stakeholder","readonly","project_creator","account_viewer","metadata_only"
```

<!-- schema generated by tfplugindocs -->
Expand Down
3 changes: 0 additions & 3 deletions examples/resources/dbtcloud_job/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ resource "dbtcloud_job" "daily_job" {
run_generate_sources = true
target_name = "default"
triggers = {
"custom_branch_only" : false,
"github_webhook" : false,
"git_provider_webhook" : false,
"schedule" : true
Expand All @@ -43,7 +42,6 @@ resource "dbtcloud_job" "ci_job" {
project_id = dbtcloud_project.dbt_project.id
run_generate_sources = false
triggers = {
"custom_branch_only" : true,
"github_webhook" : true,
"git_provider_webhook" : true,
"schedule" : false
Expand All @@ -67,7 +65,6 @@ resource "dbtcloud_job" "downstream_job" {
project_id = dbtcloud_project.dbt_project2.id
run_generate_sources = true
triggers = {
"custom_branch_only" : false,
"github_webhook" : false,
"git_provider_webhook" : false,
"schedule" : false
Expand Down
3 changes: 0 additions & 3 deletions examples/resources/dbtcloud_service_token/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ resource "dbtcloud_service_token" "test_service_token" {
project_id = dbtcloud_project.dbt_project.id
}
}

// permission_set accepts one of the following values:
// "account_admin","admin","database_admin","git_admin","team_admin","job_admin","job_viewer","analyst","developer","stakeholder","readonly","project_creator","account_viewer","metadata_only"
1 change: 0 additions & 1 deletion pkg/data_sources/job_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func jobs(jobName string) string {
"dbt run"
]
triggers = {
"custom_branch_only" : false,
"github_webhook" : false,
"schedule" : false,
"git_provider_webhook": false
Expand Down
18 changes: 14 additions & 4 deletions pkg/data_sources/notification_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,20 @@ func TestAccDbtCloudNotificationDataSource(t *testing.T) {
config := notification(randomProjectName)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.dbtcloud_notification.test_notification_external", "notification_type", "4"),
resource.TestCheckResourceAttrSet("data.dbtcloud_notification.test_notification_external", "on_failure.0"),
resource.TestCheckResourceAttr("data.dbtcloud_notification.test_notification_external", "external_email", "nomail@mail.com"),
resource.TestCheckResourceAttr(
"data.dbtcloud_notification.test_notification_external",
"notification_type",
"4",
),
resource.TestCheckResourceAttrSet(
"data.dbtcloud_notification.test_notification_external",
"on_failure.0",
),
resource.TestCheckResourceAttr(
"data.dbtcloud_notification.test_notification_external",
"external_email",
"nomail@mail.com",
),
)

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -55,7 +66,6 @@ func notification(projectName string) string {
"github_webhook" : false,
"git_provider_webhook" : false,
"schedule" : false,
"custom_branch_only" : false,
}
}
Expand Down
78 changes: 78 additions & 0 deletions pkg/dbt_cloud/common.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,86 @@
package dbt_cloud

import (
"encoding/json"
"fmt"
"net/http"

"github.com/samber/lo"
)

const (
STATE_ACTIVE = 1
STATE_DELETED = 2
ID_DELIMITER = ":"
NUM_THREADS_CREDENTIAL = 6
)

var (
PermissionSets = []string{
"owner",
"member",
"account_admin",
"security_admin",
"billing_admin",
"admin",
"database_admin",
"git_admin",
"team_admin",
"job_admin",
"job_runner",
"job_viewer",
"analyst",
"developer",
"stakeholder",
"readonly",
"project_creator",
"account_viewer",
"metadata_only",
"semantic_layer_only",
"webhooks_only",
}
)

// This is not used now but allows us to find the list of permission sets allowed
// Terraform doesn't allow to run it in the offline validation mode though as we don't have access to the configuration context
type ConstantsResponse struct {
Data Constants `json:"data"`
Status ResponseStatus `json:"status"`
}

type Constants struct {
PermissionSets map[string]string `json:"permissions_sets"`
}

func (c *Client) GetConstants() (*Constants, error) {
req, err := http.NewRequest(
"GET",
fmt.Sprintf("%s/v2/constants/", c.HostURL),
nil,
)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

constantsResponse := ConstantsResponse{}
err = json.Unmarshal(body, &constantsResponse)
if err != nil {
return nil, err
}

return &constantsResponse.Data, nil
}

func (c *Client) GetPermissionIDs() ([]string, error) {
constants, err := c.GetConstants()
if err != nil {
return nil, err
}

return lo.Keys(constants.PermissionSets), nil
}
6 changes: 0 additions & 6 deletions pkg/dbt_cloud/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
type JobTrigger struct {
Github_Webhook bool `json:"github_webhook"`
Schedule bool `json:"schedule"`
Custom_Branch_Only bool `json:"custom_branch_only"`
GitProviderWebhook bool `json:"git_provider_webhook"`
}

Expand Down Expand Up @@ -140,18 +139,13 @@ func (c *Client) CreateJob(
if !s_found {
schedule = false
}
custom_branch_only, cbo_found := triggers["custom_branch_only"]
if !cbo_found {
custom_branch_only = false
}
git_provider_webhook, gpw_found := triggers["git_provider_webhook"]
if !gpw_found {
git_provider_webhook = false
}
jobTriggers := JobTrigger{
Github_Webhook: github_webhook.(bool),
Schedule: schedule.(bool),
Custom_Branch_Only: custom_branch_only.(bool),
GitProviderWebhook: git_provider_webhook.(bool),
}
jobSettings := JobSettings{
Expand Down
Loading

0 comments on commit 5069fe2

Please sign in to comment.