Skip to content

Commit e7aef32

Browse files
authored
Merge pull request #260 from dbt-labs/release-0.3.6
2 parents c2fa411 + 0e289e8 commit e7aef32

File tree

20 files changed

+849
-29
lines changed

20 files changed

+849
-29
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.3.5...HEAD)
5+
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.6...HEAD)
6+
7+
## [0.3.6](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.5...v0.3.6)
8+
9+
### Changes
10+
11+
- [#232](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/232) add deprecation notice for `dbtcloud_project_artefacts` as the resource is not required now that dbt Explorer is GA.
12+
- [#208](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/208) add new `dbtcloud_partial_license_map` for defining SSO group mapping to license types from different Terraform projects/resources
613

714
## [0.3.5](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.4...v0.3.5)
815

docs/resources/job.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ resource "dbtcloud_job" "downstream_job" {
119119
- `deferring_job_id` (Number) Job identifier that this job defers to (legacy deferring approach)
120120
- `description` (String) Description for the job
121121
- `generate_docs` (Boolean) Flag for whether the job should generate documentation
122-
- `is_active` (Boolean) Flag for whether the job is marked active or deleted. To create/keep a job in a 'deactivated' state, check the `triggers` config.
122+
- `is_active` (Boolean) Should always be set to true as setting it to false is the same as creating a job in a deleted state. To create/keep a job in a 'deactivated' state, check the `triggers` config.
123123
- `job_completion_trigger_condition` (Block Set, Max: 1) Which other job should trigger this job when it finishes, and on which conditions (sometimes referred as 'job chaining'). (see [below for nested schema](#nestedblock--job_completion_trigger_condition))
124124
- `num_threads` (Number) Number of threads to use in the job
125125
- `run_generate_sources` (Boolean) Flag for whether the job should add a `dbt source freshness` step to the job. The difference between manually adding a step with `dbt source freshness` in the job steps or using this flag is that with this flag, a failed freshness will still allow the following steps to run.

docs/resources/partial_license_map.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
page_title: "dbtcloud_partial_license_map Resource - dbtcloud"
3+
subcategory: ""
4+
description: |-
5+
Set up partial license maps with only a subset of SSO groups for a given license type.
6+
This resource is different from dbtcloud_license_map as it allows having different resources setting up different groups for the same license type.
7+
If a company uses only one Terraform project/workspace to manage all their dbt Cloud Account config, it is recommended to use dbt_cloud_license_map instead of dbt_cloud_group_partial_license_map.
8+
~> This is a new resource like other "partial" ones and any feedback is welcome in the GitHub repository.
9+
---
10+
11+
# dbtcloud_partial_license_map (Resource)
12+
13+
14+
Set up partial license maps with only a subset of SSO groups for a given license type.
15+
16+
This resource is different from `dbtcloud_license_map` as it allows having different resources setting up different groups for the same license type.
17+
18+
If a company uses only one Terraform project/workspace to manage all their dbt Cloud Account config, it is recommended to use `dbt_cloud_license_map` instead of `dbt_cloud_group_partial_license_map`.
19+
20+
~> This is a new resource like other "partial" ones and any feedback is welcome in the GitHub repository.
21+
22+
## Example Usage
23+
24+
```terraform
25+
# Developer license group mapping
26+
resource "dbtcloud_partial_license_map" "dev_license_map" {
27+
license_type = "developer"
28+
sso_license_mapping_groups = ["DEV-SSO-GROUP"]
29+
}
30+
31+
# Read-only license mapping
32+
resource "dbtcloud_partial_license_map" "read_only_license_map" {
33+
license_type = "read_only"
34+
sso_license_mapping_groups = ["READ-ONLY-SSO-GROUP"]
35+
}
36+
37+
# IT license mapping
38+
resource "dbtcloud_partial_license_map" "it_license_map" {
39+
license_type = "it"
40+
sso_license_mapping_groups = ["IT-SSO-GROUP"]
41+
}
42+
```
43+
44+
<!-- schema generated by tfplugindocs -->
45+
## Schema
46+
47+
### Required
48+
49+
- `license_type` (String) The license type to update
50+
- `sso_license_mapping_groups` (Set of String) List of SSO groups to map to the license type.
51+
52+
### Read-Only
53+
54+
- `id` (Number) The ID of the notification

docs/resources/project_artefacts.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
page_title: "dbtcloud_project_artefacts Resource - dbtcloud"
33
subcategory: ""
44
description: |-
5-
5+
[Deprecated] Resource for mentioning what jobs are the source of truth for the legacy dbt Docs and dbt Source Freshness pages. dbt Explorer doesn't require this config anymore.
66
---
77

88
# dbtcloud_project_artefacts (Resource)
99

1010

11-
11+
[Deprecated] Resource for mentioning what jobs are the source of truth for the legacy dbt Docs and dbt Source Freshness pages. dbt Explorer doesn't require this config anymore.
1212

1313
## Example Usage
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Developer license group mapping
2+
resource "dbtcloud_partial_license_map" "dev_license_map" {
3+
license_type = "developer"
4+
sso_license_mapping_groups = ["DEV-SSO-GROUP"]
5+
}
6+
7+
# Read-only license mapping
8+
resource "dbtcloud_partial_license_map" "read_only_license_map" {
9+
license_type = "read_only"
10+
sso_license_mapping_groups = ["READ-ONLY-SSO-GROUP"]
11+
}
12+
13+
# IT license mapping
14+
resource "dbtcloud_partial_license_map" "it_license_map" {
15+
license_type = "it"
16+
sso_license_mapping_groups = ["IT-SSO-GROUP"]
17+
}

pkg/dbt_cloud/bigquery_credential.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (c *Client) CreateBigQueryCredential(
6666
Account_Id: c.AccountID,
6767
Project_Id: projectId,
6868
Type: type_,
69-
State: STATE_ACTIVE, // TODO: make variable
69+
State: STATE_ACTIVE,
7070
Dataset: dataset,
7171
Threads: numThreads,
7272
}

pkg/dbt_cloud/group.go

+40-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ type GroupPermissionListResponse struct {
4040
}
4141

4242
func (c *Client) GetGroup(groupID int) (*Group, error) {
43-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/v3/accounts/%s/groups/%s/", c.HostURL, strconv.Itoa(c.AccountID), strconv.Itoa(groupID)), nil)
43+
req, err := http.NewRequest(
44+
"GET",
45+
fmt.Sprintf(
46+
"%s/v3/accounts/%s/groups/%s/",
47+
c.HostURL,
48+
strconv.Itoa(c.AccountID),
49+
strconv.Itoa(groupID),
50+
),
51+
nil,
52+
)
4453
if err != nil {
4554
return nil, err
4655
}
@@ -59,20 +68,28 @@ func (c *Client) GetGroup(groupID int) (*Group, error) {
5968
return &groupResponse.Data, nil
6069
}
6170

62-
func (c *Client) CreateGroup(name string, assignByDefault bool, ssoMappingGroups []string) (*Group, error) {
71+
func (c *Client) CreateGroup(
72+
name string,
73+
assignByDefault bool,
74+
ssoMappingGroups []string,
75+
) (*Group, error) {
6376
newGroup := Group{
6477
AccountID: c.AccountID,
6578
Name: name,
6679
AssignByDefault: assignByDefault,
6780
SSOMappingGroups: ssoMappingGroups,
68-
State: STATE_ACTIVE, // TODO: make variable
81+
State: STATE_ACTIVE,
6982
}
7083
newGroupData, err := json.Marshal(newGroup)
7184
if err != nil {
7285
return nil, err
7386
}
7487

75-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v3/accounts/%d/groups/", c.HostURL, c.AccountID), strings.NewReader(string(newGroupData)))
88+
req, err := http.NewRequest(
89+
"POST",
90+
fmt.Sprintf("%s/v3/accounts/%d/groups/", c.HostURL, c.AccountID),
91+
strings.NewReader(string(newGroupData)),
92+
)
7693
if err != nil {
7794
return nil, err
7895
}
@@ -97,7 +114,11 @@ func (c *Client) UpdateGroup(groupID int, group Group) (*Group, error) {
97114
return nil, err
98115
}
99116

100-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v3/accounts/%s/groups/%d/", c.HostURL, strconv.Itoa(c.AccountID), groupID), strings.NewReader(string(groupData)))
117+
req, err := http.NewRequest(
118+
"POST",
119+
fmt.Sprintf("%s/v3/accounts/%s/groups/%d/", c.HostURL, strconv.Itoa(c.AccountID), groupID),
120+
strings.NewReader(string(groupData)),
121+
)
101122
if err != nil {
102123
return nil, err
103124
}
@@ -116,13 +137,25 @@ func (c *Client) UpdateGroup(groupID int, group Group) (*Group, error) {
116137
return &groupResponse.Data, nil
117138
}
118139

119-
func (c *Client) UpdateGroupPermissions(groupID int, groupPermissions []GroupPermission) (*[]GroupPermission, error) {
140+
func (c *Client) UpdateGroupPermissions(
141+
groupID int,
142+
groupPermissions []GroupPermission,
143+
) (*[]GroupPermission, error) {
120144
groupPermissionData, err := json.Marshal(groupPermissions)
121145
if err != nil {
122146
return nil, err
123147
}
124148

125-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v3/accounts/%s/group-permissions/%d/", c.HostURL, strconv.Itoa(c.AccountID), groupID), strings.NewReader(string(groupPermissionData)))
149+
req, err := http.NewRequest(
150+
"POST",
151+
fmt.Sprintf(
152+
"%s/v3/accounts/%s/group-permissions/%d/",
153+
c.HostURL,
154+
strconv.Itoa(c.AccountID),
155+
groupID,
156+
),
157+
strings.NewReader(string(groupPermissionData)),
158+
)
126159
if err != nil {
127160
return nil, err
128161
}

pkg/dbt_cloud/paginate.go

+19
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,22 @@ func (c *Client) GetAllServiceTokens() ([]ServiceToken, error) {
166166
}
167167
return allServiceTokens, nil
168168
}
169+
170+
func (c *Client) GetAllLicenseMaps() ([]LicenseMap, error) {
171+
url := fmt.Sprintf("%s/v3/accounts/%d/license-maps/", c.HostURL, c.AccountID)
172+
173+
allLicenseMapsRaw := c.GetData(url)
174+
175+
allLicenseMaps := []LicenseMap{}
176+
for _, notification := range allLicenseMapsRaw {
177+
178+
data, _ := json.Marshal(notification)
179+
currentLicenseMap := LicenseMap{}
180+
err := json.Unmarshal(data, &currentLicenseMap)
181+
if err != nil {
182+
return nil, err
183+
}
184+
allLicenseMaps = append(allLicenseMaps, currentLicenseMap)
185+
}
186+
return allLicenseMaps, nil
187+
}

pkg/dbt_cloud/postgres_credential.go

+63-8
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,21 @@ type PostgresCredentialResponse struct {
2626
}
2727

2828
// GetPostgresCredential retrieves a specific Postgres credential by its ID
29-
func (c *Client) GetPostgresCredential(projectId int, credentialId int) (*PostgresCredential, error) {
30-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/v3/accounts/%d/projects/%d/credentials/%d/", c.HostURL, c.AccountID, projectId, credentialId), nil)
29+
func (c *Client) GetPostgresCredential(
30+
projectId int,
31+
credentialId int,
32+
) (*PostgresCredential, error) {
33+
req, err := http.NewRequest(
34+
"GET",
35+
fmt.Sprintf(
36+
"%s/v3/accounts/%d/projects/%d/credentials/%d/",
37+
c.HostURL,
38+
c.AccountID,
39+
projectId,
40+
credentialId,
41+
),
42+
nil,
43+
)
3144
if err != nil {
3245
return nil, err
3346
}
@@ -47,12 +60,21 @@ func (c *Client) GetPostgresCredential(projectId int, credentialId int) (*Postgr
4760
}
4861

4962
// CreatePostgresCredential creates a new Postgres credential
50-
func (c *Client) CreatePostgresCredential(projectId int, isActive bool, type_ string, defaultSchema string, targetName string, username string, password string, numThreads int) (*PostgresCredential, error) {
63+
func (c *Client) CreatePostgresCredential(
64+
projectId int,
65+
isActive bool,
66+
type_ string,
67+
defaultSchema string,
68+
targetName string,
69+
username string,
70+
password string,
71+
numThreads int,
72+
) (*PostgresCredential, error) {
5173
newPostgresCredential := PostgresCredential{
5274
Account_Id: c.AccountID,
5375
Project_Id: projectId,
5476
Type: type_,
55-
State: STATE_ACTIVE, // TODO: make variable
77+
State: STATE_ACTIVE,
5678
Threads: numThreads,
5779
Username: username,
5880
Default_Schema: defaultSchema,
@@ -64,7 +86,16 @@ func (c *Client) CreatePostgresCredential(projectId int, isActive bool, type_ st
6486
return nil, err
6587
}
6688

67-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v3/accounts/%d/projects/%d/credentials/", c.HostURL, c.AccountID, projectId), strings.NewReader(string(newPostgresCredentialData)))
89+
req, err := http.NewRequest(
90+
"POST",
91+
fmt.Sprintf(
92+
"%s/v3/accounts/%d/projects/%d/credentials/",
93+
c.HostURL,
94+
c.AccountID,
95+
projectId,
96+
),
97+
strings.NewReader(string(newPostgresCredentialData)),
98+
)
6899
if err != nil {
69100
return nil, err
70101
}
@@ -84,13 +115,27 @@ func (c *Client) CreatePostgresCredential(projectId int, isActive bool, type_ st
84115
}
85116

86117
// UpdatePostgresCredential updates an existing Postgres credential
87-
func (c *Client) UpdatePostgresCredential(projectId int, credentialId int, postgresCredential PostgresCredential) (*PostgresCredential, error) {
118+
func (c *Client) UpdatePostgresCredential(
119+
projectId int,
120+
credentialId int,
121+
postgresCredential PostgresCredential,
122+
) (*PostgresCredential, error) {
88123
postgresCredentialData, err := json.Marshal(postgresCredential)
89124
if err != nil {
90125
return nil, err
91126
}
92127

93-
req, err := http.NewRequest("POST", fmt.Sprintf("%s/v3/accounts/%d/projects/%d/credentials/%d/", c.HostURL, c.AccountID, projectId, credentialId), strings.NewReader(string(postgresCredentialData)))
128+
req, err := http.NewRequest(
129+
"POST",
130+
fmt.Sprintf(
131+
"%s/v3/accounts/%d/projects/%d/credentials/%d/",
132+
c.HostURL,
133+
c.AccountID,
134+
projectId,
135+
credentialId,
136+
),
137+
strings.NewReader(string(postgresCredentialData)),
138+
)
94139
if err != nil {
95140
return nil, err
96141
}
@@ -111,7 +156,17 @@ func (c *Client) UpdatePostgresCredential(projectId int, credentialId int, postg
111156

112157
// DeletePostgresCredential deletes a Postgres credential by its ID
113158
func (c *Client) DeletePostgresCredential(credentialId, projectId string) (string, error) {
114-
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/v3/accounts/%d/projects/%s/credentials/%s/", c.HostURL, c.AccountID, projectId, credentialId), nil)
159+
req, err := http.NewRequest(
160+
"DELETE",
161+
fmt.Sprintf(
162+
"%s/v3/accounts/%d/projects/%s/credentials/%s/",
163+
c.HostURL,
164+
c.AccountID,
165+
projectId,
166+
credentialId,
167+
),
168+
nil,
169+
)
115170
if err != nil {
116171
return "", err
117172
}

pkg/dbt_cloud/snowflake_credential.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *Client) CreateSnowflakeCredential(
8282
Account_Id: c.AccountID,
8383
Project_Id: projectId,
8484
Type: type_,
85-
State: STATE_ACTIVE, // TODO: make variable
85+
State: STATE_ACTIVE,
8686
Database: database,
8787
Role: role,
8888
Warehouse: warehouse,

pkg/framework/objects/group_partial_permissions/resource.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (r *groupPartialPermissionsResource) Create(
208208

209209
} else {
210210
// if the group with the name given doesn't exist , create it
211-
// TODO: Move this to the group resources in the Framework
211+
// TODO: Move this to the group resources once the resource is move to the Framework
212212

213213
group, err := r.client.CreateGroup(name, assignByDefault, ssoMappingGroups)
214214
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package partial_license_map
2+
3+
import (
4+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
5+
"github.com/hashicorp/terraform-plugin-framework/types"
6+
)
7+
8+
// TODO: Move the model to the non partial when moved to the Framework
9+
type LicenseMapResourceModel struct {
10+
ID types.Int64 `tfsdk:"id"`
11+
LicenseType types.String `tfsdk:"license_type"`
12+
SSOLicenseMappingGroups types.Set `tfsdk:"sso_license_mapping_groups"`
13+
}
14+
15+
func matchPartial(
16+
licenseMapModel LicenseMapResourceModel,
17+
licenseTypeResponse dbt_cloud.LicenseMap,
18+
) bool {
19+
return licenseMapModel.LicenseType == types.StringValue(licenseTypeResponse.LicenseType)
20+
}

0 commit comments

Comments
 (0)