-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature - Add data source for all Tableau groups
- Loading branch information
Gary James
authored and
Gary James
committed
Nov 25, 2024
1 parent
ef45925
commit 187fe3a
Showing
9 changed files
with
220 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "tableau_groups Data Source - terraform-provider-tableau" | ||
subcategory: "" | ||
description: |- | ||
Retrieve groups details | ||
--- | ||
|
||
# tableau_groups (Data Source) | ||
|
||
Retrieve groups details | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `groups` (Attributes List) List of groups and their attributes (see [below for nested schema](#nestedatt--groups)) | ||
- `id` (String) ID of the list of groups | ||
|
||
<a id="nestedatt--groups"></a> | ||
### Nested Schema for `groups` | ||
|
||
Read-Only: | ||
|
||
- `id` (String) ID of the group | ||
- `minimum_site_role` (String) Minimum site role for the groups | ||
- `name` (String) Name for the groups |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package tableau | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSource = &groupsDataSource{} | ||
_ datasource.DataSourceWithConfigure = &groupsDataSource{} | ||
) | ||
|
||
func GroupsDataSource() datasource.DataSource { | ||
return &groupsDataSource{} | ||
} | ||
|
||
type groupsDataSource struct { | ||
client *Client | ||
} | ||
|
||
type groupsNestedDataModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Name types.String `tfsdk:"name"` | ||
MinimumSiteRole types.String `tfsdk:"minimum_site_role"` | ||
} | ||
|
||
type groupsDataSourceModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Groups []groupsNestedDataModel `tfsdk:"groups"` | ||
} | ||
|
||
func (d *groupsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_groups" | ||
} | ||
|
||
func (d *groupsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Description: "Retrieve groups details", | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "ID of the list of groups", | ||
}, | ||
"groups": schema.ListNestedAttribute{ | ||
Description: "List of groups and their attributes", | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "ID of the group", | ||
}, | ||
"name": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Name for the groups", | ||
}, | ||
"minimum_site_role": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Minimum site role for the groups", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *groupsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var state groupsDataSourceModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...) | ||
|
||
groups, err := d.client.GetGroups() | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
"Unable to Read Tableau Groups", | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
for _, group := range groups { | ||
groupDataSourceModel := groupsNestedDataModel{ | ||
ID: types.StringValue(group.ID), | ||
Name: types.StringValue(group.Name), | ||
MinimumSiteRole: types.StringValue(group.MinimumSiteRole), | ||
} | ||
state.Groups = append(state.Groups, groupDataSourceModel) | ||
} | ||
|
||
state.ID = types.StringValue("allGroups") | ||
|
||
diags := resp.State.Set(ctx, &state) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} | ||
|
||
func (d *groupsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
d.client = req.ProviderData.(*Client) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tableau | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccGroupsDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: providerConfig + ` | ||
data "tableau_groups" "test" { | ||
}`, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.tableau_groups.test", "id"), | ||
resource.TestCheckResourceAttrSet("data.tableau_groups.test", "groups.#"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
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