Skip to content

Commit 6f8a313

Browse files
authored
Merge pull request #268 from dbt-labs/release-0.3.7
2 parents 2374ad8 + 28e8ddc commit 6f8a313

File tree

71 files changed

+1662
-919
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1662
-919
lines changed

CHANGELOG.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
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.6...HEAD)
5+
## [Unreleased](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.7...HEAD)
6+
7+
## [0.3.7](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.6...v0.3.7)
8+
9+
### Changes
10+
11+
- [#266](https://github.com/dbt-labs/terraform-provider-dbtcloud/issues/266) Add env level permissions for `dbtcloud_group` and `dbtcloud_group_partial_permissions`. As of June 5 this feature is not yet active for all customers.
12+
13+
### Docs
14+
15+
- Fix description of fields for some datasources
16+
17+
### Internals
18+
19+
- Move the `dbcloud_group` resource and datasource from the SDKv2 to the Framework
20+
- Create new helpers for comparing Go structs
21+
- Update all SDKv2 tests to run on the muxed provider to work when some resources have moved to the Plugin Framework
622

723
## [0.3.6](https://github.com/dbt-labs/terraform-provider-dbtcloud/compare/v0.3.5...v0.3.6)
824

docs/data-sources/environment.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Retrieve data for a single environment
2323
### Read-Only
2424

2525
- `credentials_id` (Number) The project ID to which the environment belong
26-
- `custom_branch` (String) The type of deployment environment (currently 'production', 'staging' or empty)
27-
- `dbt_version` (String) Version number of dbt to use in this environment, usually in the format 1.2.0-latest rather than core versions
28-
- `deployment_type` (String) The name of the environment
26+
- `custom_branch` (String) The custom branch name to use
27+
- `dbt_version` (String) Version number of dbt to use in this environment.
28+
- `deployment_type` (String) The type of deployment environment (currently 'production', 'staging' or empty)
2929
- `extended_attributes_id` (Number) The ID of the extended attributes applied
3030
- `name` (String) The name of the environment
31-
- `type` (String) The name of the environment
31+
- `type` (String) The type of environment (must be either development or deployment)
3232
- `use_custom_branch` (Boolean) Whether to use a custom git branch in this environment

docs/data-sources/environments.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Retrieve data for multiple environments
2828

2929
Read-Only:
3030

31-
- `credentials_id` (Number) The project ID to which the environment belong
32-
- `custom_branch` (String) The type of deployment environment (currently 'production', 'staging' or empty)
33-
- `dbt_version` (String) Version number of dbt to use in this environment, usually in the format 1.2.0-latest rather than core versions
34-
- `deployment_type` (String) The name of the environment
31+
- `credentials_id` (Number) Credential ID to create the environment with. A credential is not required for development environments but is required for deployment environments
32+
- `custom_branch` (String) The custom branch name to use
33+
- `dbt_version` (String) Version number of dbt to use in this environment.
34+
- `deployment_type` (String) The type of deployment environment (currently 'production', 'staging' or empty)
3535
- `environment_id` (Number) The ID of the environment
3636
- `extended_attributes_id` (Number) The ID of the extended attributes applied
3737
- `name` (String) The name of the environment
3838
- `project_id` (Number) The project ID to which the environment belong
39-
- `type` (String) The name of the environment
39+
- `type` (String) The type of environment (must be either development or deployment)
4040
- `use_custom_branch` (Boolean) Whether to use a custom git branch in this environment

docs/data-sources/group.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "dbtcloud_group Data Source - dbtcloud"
44
subcategory: ""
55
description: |-
6-
6+
Retrieve group details
77
---
88

99
# dbtcloud_group (Data Source)
1010

11-
11+
Retrieve group details
1212

1313

1414

@@ -17,12 +17,22 @@ description: |-
1717

1818
### Required
1919

20-
- `group_id` (Number) ID of the group
20+
- `group_id` (Number) The ID of the group
2121

2222
### Read-Only
2323

24-
- `assign_by_default` (Boolean) Whether or not to assign this group to users by default
25-
- `id` (String) The ID of this resource.
26-
- `is_active` (Boolean) Whether the group is active
24+
- `assign_by_default` (Boolean) Whether the group will be assigned by default to users. The value needs to be the same for all partial permissions for the same group.
25+
- `group_permissions` (Attributes Set) Partial permissions for the group. Those permissions will be added/removed when config is added/removed. (see [below for nested schema](#nestedatt--group_permissions))
26+
- `id` (Number) The ID of this resource
2727
- `name` (String) Group name
28-
- `sso_mapping_groups` (List of String) SSO mapping group names for this group
28+
- `sso_mapping_groups` (Set of String) SSO mapping group names for this group
29+
30+
<a id="nestedatt--group_permissions"></a>
31+
### Nested Schema for `group_permissions`
32+
33+
Read-Only:
34+
35+
- `all_projects` (Boolean) Whether access should be provided for all projects or not.
36+
- `permission_set` (String) Set of permissions to apply. The permissions allowed are the same as the ones for the `dbtcloud_group` resource.
37+
- `project_id` (Number) Project ID to apply this permission to for this group.
38+
- `writable_environment_categories` (Set of String) What types of environments to apply Write permissions to.

docs/resources/group.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
page_title: "dbtcloud_group Resource - dbtcloud"
33
subcategory: ""
44
description: |-
5-
5+
Provide a complete set of permissions for a group. This is different from dbt_cloud_partial_group_permissions.
6+
With this resource type only one resource can be used to manage the permissions for a given group.
67
---
78

89
# dbtcloud_group (Resource)
@@ -34,7 +35,9 @@ The mapping of permission names [from the docs](https://docs.getdbt.com/docs/clo
3435
|Webhooks Only | webhooks_only|
3536

3637

38+
Provide a complete set of permissions for a group. This is different from `dbt_cloud_partial_group_permissions`.
3739

40+
With this resource type only one resource can be used to manage the permissions for a given group.
3841

3942
## Example Usage
4043

@@ -58,30 +61,34 @@ resource "dbtcloud_group" "tf_group_1" {
5861

5962
### Required
6063

61-
- `name` (String) Group name
64+
- `name` (String) The name of the group. This is used to identify an existing group
6265

6366
### Optional
6467

65-
- `assign_by_default` (Boolean) Whether or not to assign this group to users by default
66-
- `group_permissions` (Block Set) (see [below for nested schema](#nestedblock--group_permissions))
67-
- `is_active` (Boolean) Whether the group is active
68-
- `sso_mapping_groups` (List of String) SSO mapping group names for this group
68+
- `assign_by_default` (Boolean) Whether the group will be assigned by default to users. The value needs to be the same for all partial permissions for the same group.
69+
- `group_permissions` (Block Set) Partial permissions for the group. Those permissions will be added/removed when config is added/removed. (see [below for nested schema](#nestedblock--group_permissions))
70+
- `sso_mapping_groups` (Set of String) Mapping groups from the IdP. At the moment the complete list needs to be provided in each partial permission for the same group.
6971

7072
### Read-Only
7173

72-
- `id` (String) The ID of this resource.
74+
- `id` (Number) The ID of the group
7375

7476
<a id="nestedblock--group_permissions"></a>
7577
### Nested Schema for `group_permissions`
7678

7779
Required:
7880

79-
- `all_projects` (Boolean) Whether or not to apply this permission to all projects for this group
80-
- `permission_set` (String) Set of permissions to apply
81+
- `all_projects` (Boolean) Whether access should be provided for all projects or not.
82+
- `permission_set` (String) Set of permissions to apply. The permissions allowed are the same as the ones for the `dbtcloud_group` resource.
8183

8284
Optional:
8385

84-
- `project_id` (Number) Project ID to apply this permission to for this group
86+
- `project_id` (Number) Project ID to apply this permission to for this group.
87+
- `writable_environment_categories` (Set of String) What types of environments to apply Write permissions to.
88+
Even if Write access is restricted to some environment types, the permission set will have Read access to all environments.
89+
The values allowed are `all`, `development`, `staging`, `production` and `other`.
90+
Not setting a value is the same as selecting `all`.
91+
Not all permission sets support environment level write settings, only `analyst`, `database_admin`, `developer`, `git_admin` and `team_admin`.
8592

8693
## Import
8794

docs/resources/group_partial_permissions.md

+5
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,8 @@ Required:
9696
Optional:
9797

9898
- `project_id` (Number) Project ID to apply this permission to for this group.
99+
- `writable_environment_categories` (Set of String) What types of environments to apply Write permissions to.
100+
Even if Write access is restricted to some environment types, the permission set will have Read access to all environments.
101+
The values allowed are `all`, `development`, `staging`, `production` and `other`.
102+
Not setting a value is the same as selecting `all`.
103+
Not all permission sets support environment level write settings, only `analyst`, `database_admin`, `developer`, `git_admin` and `team_admin`.

pkg/dbt_cloud/group.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
)
1010

1111
type GroupPermission struct {
12-
ID *int `json:"id,omitempty"`
13-
AccountID int `json:"account_id"`
14-
GroupID int `json:"group_id"`
15-
ProjectID int `json:"project_id,omitempty"`
16-
AllProjects bool `json:"all_projects"`
17-
State int `json:"state,omitempty"`
18-
Set string `json:"permission_set,omitempty"`
19-
Level string `json:"permission_level,omitempty"`
12+
ID *int `json:"id,omitempty"`
13+
AccountID int `json:"account_id"`
14+
GroupID int `json:"group_id"`
15+
ProjectID int `json:"project_id,omitempty"`
16+
AllProjects bool `json:"all_projects"`
17+
State int `json:"state,omitempty"`
18+
Set string `json:"permission_set,omitempty"`
19+
Level string `json:"permission_level,omitempty"`
20+
WritableEnvironmentCategories []string `json:"writable_environment_categories,omitempty"`
2021
}
2122

2223
type Group struct {

pkg/framework/objects/environment/schema.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ func (r *environmentDataSource) Schema(
3333
},
3434
"dbt_version": schema.StringAttribute{
3535
Computed: true,
36-
Description: "Version number of dbt to use in this environment, usually in the format 1.2.0-latest rather than core versions",
36+
Description: "Version number of dbt to use in this environment.",
3737
},
3838
"type": schema.StringAttribute{
3939
Computed: true,
40-
Description: "The name of the environment",
40+
Description: "The type of environment (must be either development or deployment)",
4141
},
4242
"use_custom_branch": schema.BoolAttribute{
4343
Computed: true,
4444
Description: "Whether to use a custom git branch in this environment",
4545
},
4646
"custom_branch": schema.StringAttribute{
4747
Computed: true,
48-
Description: "The type of deployment environment (currently 'production', 'staging' or empty)",
48+
Description: "The custom branch name to use",
4949
},
5050
"deployment_type": schema.StringAttribute{
5151
Computed: true,
52-
Description: "The name of the environment",
52+
Description: "The type of deployment environment (currently 'production', 'staging' or empty)",
5353
},
5454
"extended_attributes_id": schema.Int64Attribute{
5555
Computed: true,
@@ -86,31 +86,31 @@ func (r *environmentsDataSources) Schema(
8686
},
8787
"credentials_id": schema.Int64Attribute{
8888
Computed: true,
89-
Description: "The project ID to which the environment belong",
89+
Description: "Credential ID to create the environment with. A credential is not required for development environments but is required for deployment environments",
9090
},
9191
"name": schema.StringAttribute{
9292
Computed: true,
9393
Description: "The name of the environment",
9494
},
9595
"dbt_version": schema.StringAttribute{
9696
Computed: true,
97-
Description: "Version number of dbt to use in this environment, usually in the format 1.2.0-latest rather than core versions",
97+
Description: "Version number of dbt to use in this environment.",
9898
},
9999
"type": schema.StringAttribute{
100100
Computed: true,
101-
Description: "The name of the environment",
101+
Description: "The type of environment (must be either development or deployment)",
102102
},
103103
"use_custom_branch": schema.BoolAttribute{
104104
Computed: true,
105105
Description: "Whether to use a custom git branch in this environment",
106106
},
107107
"custom_branch": schema.StringAttribute{
108108
Computed: true,
109-
Description: "The type of deployment environment (currently 'production', 'staging' or empty)",
109+
Description: "The custom branch name to use",
110110
},
111111
"deployment_type": schema.StringAttribute{
112112
Computed: true,
113-
Description: "The name of the environment",
113+
Description: "The type of deployment environment (currently 'production', 'staging' or empty)",
114114
},
115115
"extended_attributes_id": schema.Int64Attribute{
116116
Computed: true,
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package group
2+
3+
import (
4+
"context"
5+
"strings"
6+
7+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
8+
"github.com/hashicorp/terraform-plugin-framework/datasource"
9+
"github.com/hashicorp/terraform-plugin-framework/types"
10+
)
11+
12+
var (
13+
_ datasource.DataSource = &groupDataSource{}
14+
_ datasource.DataSourceWithConfigure = &groupDataSource{}
15+
)
16+
17+
func GroupDataSource() datasource.DataSource {
18+
return &groupDataSource{}
19+
}
20+
21+
type groupDataSource struct {
22+
client *dbt_cloud.Client
23+
}
24+
25+
func (d *groupDataSource) Metadata(
26+
_ context.Context,
27+
req datasource.MetadataRequest,
28+
resp *datasource.MetadataResponse,
29+
) {
30+
resp.TypeName = req.ProviderTypeName + "_group"
31+
}
32+
33+
func (d *groupDataSource) Read(
34+
ctx context.Context,
35+
req datasource.ReadRequest,
36+
resp *datasource.ReadResponse,
37+
) {
38+
39+
var data GroupDatasourceModel
40+
41+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
42+
43+
groupID := data.GroupID.ValueInt64()
44+
retrievedGroup, err := d.client.GetGroup(int(groupID))
45+
46+
if err != nil {
47+
if strings.HasPrefix(err.Error(), "resource-not-found") {
48+
resp.Diagnostics.AddWarning(
49+
"Resource not found",
50+
"The group was not found and has been removed from the state.",
51+
)
52+
resp.State.RemoveResource(ctx)
53+
return
54+
}
55+
resp.Diagnostics.AddError("Error getting the group", err.Error())
56+
return
57+
}
58+
59+
data.GroupID = types.Int64Value(int64(*retrievedGroup.ID))
60+
data.ID = types.Int64Value(int64(*retrievedGroup.ID))
61+
data.Name = types.StringValue(retrievedGroup.Name)
62+
data.AssignByDefault = types.BoolValue(retrievedGroup.AssignByDefault)
63+
data.SSOMappingGroups, _ = types.SetValueFrom(
64+
context.Background(),
65+
types.StringType,
66+
retrievedGroup.SSOMappingGroups,
67+
)
68+
69+
remotePermissions := ConvertGroupPermissionDataToModel(retrievedGroup.Permissions)
70+
data.GroupPermissions = remotePermissions
71+
72+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
73+
}
74+
75+
func (d *groupDataSource) Configure(
76+
_ context.Context,
77+
req datasource.ConfigureRequest,
78+
_ *datasource.ConfigureResponse,
79+
) {
80+
if req.ProviderData == nil {
81+
return
82+
}
83+
84+
d.client = req.ProviderData.(*dbt_cloud.Client)
85+
}

pkg/sdkv2/data_sources/group_acceptance_test.go renamed to pkg/framework/objects/group/data_source_acceptance_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package data_sources_test
1+
package group_test
22

33
import (
44
"fmt"
55
"testing"
66

7+
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/framework/acctest_helper"
78
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
89
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
910
)
@@ -16,15 +17,14 @@ func TestAccDbtCloudGroupDataSource(t *testing.T) {
1617

1718
check := resource.ComposeAggregateTestCheckFunc(
1819
resource.TestCheckResourceAttr("data.dbtcloud_group.test_group_read", "name", groupName),
19-
resource.TestCheckResourceAttrSet("data.dbtcloud_group.test_group_read", "is_active"),
2020
resource.TestCheckResourceAttrSet(
2121
"data.dbtcloud_group.test_group_read",
2222
"assign_by_default",
2323
),
2424
)
2525

2626
resource.ParallelTest(t, resource.TestCase{
27-
Providers: providers(),
27+
ProtoV6ProviderFactories: acctest_helper.TestAccProtoV6ProviderFactories,
2828
Steps: []resource.TestStep{
2929
{
3030
Config: config,

0 commit comments

Comments
 (0)