Skip to content

Commit

Permalink
Add resource dbtcloud_partial_license_map
Browse files Browse the repository at this point in the history
  • Loading branch information
b-per committed May 28, 2024
1 parent 54db22e commit 69dc1e0
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

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

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

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

### Changes

- [#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.
- [#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

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

Expand Down
54 changes: 54 additions & 0 deletions docs/resources/partial_license_map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
page_title: "dbtcloud_partial_license_map Resource - dbtcloud"
subcategory: ""
description: |-
Set up partial license maps with only a subset of SSO groups for a given license type.
This resource is different from dbtcloud_license_map as it allows having different resources setting up different groups for the same license type.
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.
~> This is a new resource like other "partial" ones and any feedback is welcome in the GitHub repository.
---

# dbtcloud_partial_license_map (Resource)


Set up partial license maps with only a subset of SSO groups for a given license type.

This resource is different from `dbtcloud_license_map` as it allows having different resources setting up different groups for the same license type.

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`.

~> This is a new resource like other "partial" ones and any feedback is welcome in the GitHub repository.

## Example Usage

```terraform
# Developer license group mapping
resource "dbtcloud_partial_license_map" "dev_license_map" {
license_type = "developer"
sso_license_mapping_groups = ["DEV-SSO-GROUP"]
}
# Read-only license mapping
resource "dbtcloud_partial_license_map" "read_only_license_map" {
license_type = "read_only"
sso_license_mapping_groups = ["READ-ONLY-SSO-GROUP"]
}
# IT license mapping
resource "dbtcloud_partial_license_map" "it_license_map" {
license_type = "it"
sso_license_mapping_groups = ["IT-SSO-GROUP"]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `license_type` (String) The license type to update
- `sso_license_mapping_groups` (Set of String) List of SSO groups to map to the license type.

### Read-Only

- `id` (Number) The ID of the notification
17 changes: 17 additions & 0 deletions examples/resources/dbtcloud_partial_license_map/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Developer license group mapping
resource "dbtcloud_partial_license_map" "dev_license_map" {
license_type = "developer"
sso_license_mapping_groups = ["DEV-SSO-GROUP"]
}

# Read-only license mapping
resource "dbtcloud_partial_license_map" "read_only_license_map" {
license_type = "read_only"
sso_license_mapping_groups = ["READ-ONLY-SSO-GROUP"]
}

# IT license mapping
resource "dbtcloud_partial_license_map" "it_license_map" {
license_type = "it"
sso_license_mapping_groups = ["IT-SSO-GROUP"]
}
19 changes: 19 additions & 0 deletions pkg/dbt_cloud/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,22 @@ func (c *Client) GetAllServiceTokens() ([]ServiceToken, error) {
}
return allServiceTokens, nil
}

func (c *Client) GetAllLicenseMaps() ([]LicenseMap, error) {
url := fmt.Sprintf("%s/v3/accounts/%d/license-maps/", c.HostURL, c.AccountID)

allLicenseMapsRaw := c.GetData(url)

allLicenseMaps := []LicenseMap{}
for _, notification := range allLicenseMapsRaw {

data, _ := json.Marshal(notification)
currentLicenseMap := LicenseMap{}
err := json.Unmarshal(data, &currentLicenseMap)
if err != nil {
return nil, err
}
allLicenseMaps = append(allLicenseMaps, currentLicenseMap)
}
return allLicenseMaps, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (r *groupPartialPermissionsResource) Create(

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

group, err := r.client.CreateGroup(name, assignByDefault, ssoMappingGroups)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions pkg/framework/objects/partial_license_map/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package partial_license_map

import (
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// TODO: Move the model to the non partial when moved to the Framework
type LicenseMapResourceModel struct {
ID types.Int64 `tfsdk:"id"`
LicenseType types.String `tfsdk:"license_type"`
SSOLicenseMappingGroups types.Set `tfsdk:"sso_license_mapping_groups"`
}

func matchPartial(
licenseMapModel LicenseMapResourceModel,
licenseTypeResponse dbt_cloud.LicenseMap,
) bool {
return licenseMapModel.LicenseType == types.StringValue(licenseTypeResponse.LicenseType)
}
Loading

0 comments on commit 69dc1e0

Please sign in to comment.