-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588f8a0
commit 0708a7f
Showing
12 changed files
with
498 additions
and
573 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,94 @@ | ||
package datasources | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
var accountRolesSchema = map[string]*schema.Schema{ | ||
"pattern": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Filters the command output by object name.", | ||
}, | ||
"roles": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "List of all the roles which you can view across your entire account, including the system-defined roles and any custom roles that exist.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Identifier for the role.", | ||
}, | ||
"comment": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The comment on the role", | ||
}, | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The owner of the role", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func Roles() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: ReadAccountRoles, | ||
Schema: accountRolesSchema, | ||
DeprecationMessage: "This resource is deprecated and will be removed in a future major version release. Please use snowflake_account_roles instead.", | ||
} | ||
} | ||
|
||
func ReadAccountRoles(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { | ||
db := meta.(*sql.DB) | ||
client := sdk.NewClientFromDB(db) | ||
|
||
req := sdk.NewShowRoleRequest() | ||
if pattern, ok := d.GetOk("pattern"); ok { | ||
req.WithLike(sdk.NewLikeRequest(pattern.(string))) | ||
} | ||
|
||
roles, err := client.Roles.Show(ctx, req) | ||
if err != nil { | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Failed to show account roles", | ||
Detail: fmt.Sprintf("Search pattern: %v, err: %s", d.Get("pattern").(string), err), | ||
}, | ||
} | ||
} | ||
|
||
mappedRoles := make([]map[string]any, len(roles)) | ||
for i, role := range roles { | ||
mappedRoles[i] = map[string]any{ | ||
"name": role.Name, | ||
"comment": role.Comment, | ||
"owner": role.Owner, | ||
} | ||
} | ||
|
||
if err := d.Set("roles", mappedRoles); err != nil { | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Failed to set roles", | ||
Detail: fmt.Sprintf("Search pattern: %v, err: %s", d.Get("pattern").(string), err), | ||
}, | ||
} | ||
} | ||
|
||
d.SetId("roles_read") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.