Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update permissions for groups and tokens #218

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions pkg/resources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var (
"owner",
"member",
"account_admin",
"security_admin",
"billing_admin",
"admin",
"database_admin",
"git_admin",
Expand All @@ -29,6 +31,7 @@ var (
"project_creator",
"account_viewer",
"metadata_only",
"semantic_layer_only",
"webhooks_only",
}
)
Expand Down Expand Up @@ -98,7 +101,11 @@ func ResourceGroup() *schema.Resource {
}
}

func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceGroupCreate(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

var diags diag.Diagnostics
Expand Down Expand Up @@ -142,7 +149,11 @@ func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, m interfac
return diags
}

func resourceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceGroupRead(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

var diags diag.Diagnostics
Expand Down Expand Up @@ -188,15 +199,21 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{
return diags
}

func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceGroupUpdate(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

groupID, err := strconv.Atoi(d.Id())
if err != nil {
return diag.FromErr(err)
}

if d.HasChange("name") || d.HasChange("assign_by_default") || d.HasChange("sso_mapping_groups") {
if d.HasChange("name") ||
d.HasChange("assign_by_default") ||
d.HasChange("sso_mapping_groups") {
group, err := c.GetGroup(groupID)
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -247,7 +264,11 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, m interfac
return resourceGroupRead(ctx, d, m)
}

func resourceGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceGroupDelete(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

groupID, err := strconv.Atoi(d.Id())
Expand Down
51 changes: 41 additions & 10 deletions pkg/resources/service_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import (

var (
servicetokenPermissionSets = []string{
"owner",
"member",
"account_admin",
"security_admin",
"billing_admin",
"admin",
"database_admin",
"git_admin",
Expand All @@ -27,6 +31,8 @@ var (
"project_creator",
"account_viewer",
"metadata_only",
"semantic_layer_only",
"webhooks_only",
}
)

Expand Down Expand Up @@ -68,10 +74,13 @@ func ResourceServiceToken() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"permission_set": {
Type: schema.TypeString,
Required: true,
Description: "Set of permissions to apply",
ValidateFunc: validation.StringInSlice(servicetokenPermissionSets, false),
Type: schema.TypeString,
Required: true,
Description: "Set of permissions to apply",
ValidateFunc: validation.StringInSlice(
servicetokenPermissionSets,
false,
),
},
"project_id": {
Type: schema.TypeInt,
Expand All @@ -94,7 +103,11 @@ func ResourceServiceToken() *schema.Resource {
}
}

func resourceServiceTokenCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceServiceTokenCreate(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

var diags diag.Diagnostics
Expand All @@ -108,7 +121,10 @@ func resourceServiceTokenCreate(ctx context.Context, d *schema.ResourceData, m i
}

serviceTokenPermissionsRaw := d.Get("service_token_permissions").(*schema.Set).List()
serviceTokenPermissions := make([]dbt_cloud.ServiceTokenPermission, len(serviceTokenPermissionsRaw))
serviceTokenPermissions := make(
[]dbt_cloud.ServiceTokenPermission,
len(serviceTokenPermissionsRaw),
)
for i, p := range serviceTokenPermissionsRaw {
permission := p.(map[string]interface{})
serviceTokenPermission := dbt_cloud.ServiceTokenPermission{
Expand Down Expand Up @@ -136,7 +152,11 @@ func resourceServiceTokenCreate(ctx context.Context, d *schema.ResourceData, m i
return diags
}

func resourceServiceTokenRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceServiceTokenRead(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

var diags diag.Diagnostics
Expand Down Expand Up @@ -185,7 +205,11 @@ func resourceServiceTokenRead(ctx context.Context, d *schema.ResourceData, m int
return diags
}

func resourceServiceTokenUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceServiceTokenUpdate(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

serviceTokenID, err := strconv.Atoi(d.Id())
Expand Down Expand Up @@ -221,7 +245,10 @@ func resourceServiceTokenUpdate(ctx context.Context, d *schema.ResourceData, m i

if d.HasChange("service_token_permissions") {
serviceTokenPermissionsRaw := d.Get("service_token_permissions").(*schema.Set).List()
serviceTokenPermissions := make([]dbt_cloud.ServiceTokenPermission, len(serviceTokenPermissionsRaw))
serviceTokenPermissions := make(
[]dbt_cloud.ServiceTokenPermission,
len(serviceTokenPermissionsRaw),
)
for i, p := range serviceTokenPermissionsRaw {
permission := p.(map[string]interface{})
serviceTokenPermission := dbt_cloud.ServiceTokenPermission{
Expand All @@ -242,7 +269,11 @@ func resourceServiceTokenUpdate(ctx context.Context, d *schema.ResourceData, m i
return resourceServiceTokenRead(ctx, d, m)
}

func resourceServiceTokenDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func resourceServiceTokenDelete(
ctx context.Context,
d *schema.ResourceData,
m interface{},
) diag.Diagnostics {
c := m.(*dbt_cloud.Client)

var diags diag.Diagnostics
Expand Down