Skip to content

Commit

Permalink
Merge pull request #31312 from hashicorp/remove-d/aws_identitystore_g…
Browse files Browse the repository at this point in the history
…roup.filter

d/aws_identitystore_(group|user): Remove `filter` argument
  • Loading branch information
ewbankkit authored May 10, 2023
2 parents af2a398 + d32db69 commit 8002bcb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 680 deletions.
7 changes: 7 additions & 0 deletions .changelog/31312.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:note
data-source/aws_identitystore_group: The `filter` argument has been removed
```

```release-note:note
data-source/aws_identitystore_user: The `filter` argument has been removed
```
113 changes: 8 additions & 105 deletions internal/service/identitystore/group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/identitystore"
"github.com/aws/aws-sdk-go-v2/service/identitystore/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -23,10 +22,9 @@ func DataSourceGroup() *schema.Resource {

Schema: map[string]*schema.Schema{
"alternate_identifier": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ConflictsWith: []string{"filter", "group_id"},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"external_id": {
Expand Down Expand Up @@ -67,6 +65,7 @@ func DataSourceGroup() *schema.Resource {
},
},
},
ExactlyOneOf: []string{"alternate_identifier", "group_id"},
},
"description": {
Type: schema.TypeString,
Expand All @@ -92,36 +91,15 @@ func DataSourceGroup() *schema.Resource {
},
},
},
"filter": {
Deprecated: "Use the alternate_identifier attribute instead.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
AtLeastOneOf: []string{"alternate_identifier", "filter", "group_id"},
ConflictsWith: []string{"alternate_identifier"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"attribute_path": {
Type: schema.TypeString,
Required: true,
},
"attribute_value": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"group_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
AtLeastOneOf: []string{"alternate_identifier", "filter", "group_id"},
ConflictsWith: []string{"alternate_identifier"},
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 47),
validation.StringMatch(regexp.MustCompile(`^([0-9a-f]{10}-|)[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$`), "must match ([0-9a-f]{10}-|)[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}"),
),
ExactlyOneOf: []string{"alternate_identifier", "group_id"},
},
"identity_store_id": {
Type: schema.TypeString,
Expand All @@ -144,53 +122,6 @@ func dataSourceGroupRead(ctx context.Context, d *schema.ResourceData, meta inter

identityStoreID := d.Get("identity_store_id").(string)

if v, ok := d.GetOk("filter"); ok && len(v.([]interface{})) > 0 {
// Use ListGroups for backwards compat.
input := &identitystore.ListGroupsInput{
IdentityStoreId: aws.String(identityStoreID),
Filters: expandFilters(d.Get("filter").([]interface{})),
}
paginator := identitystore.NewListGroupsPaginator(conn, input)
var results []types.Group

for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)

if err != nil {
return create.DiagError(names.IdentityStore, create.ErrActionReading, DSNameGroup, identityStoreID, err)
}

for _, group := range page.Groups {
if v, ok := d.GetOk("group_id"); ok && v.(string) != aws.ToString(group.GroupId) {
continue
}

results = append(results, group)
}
}

if len(results) == 0 {
return diag.Errorf("no Identity Store Group found matching criteria\n%v; try different search", input.Filters)
}

if len(results) > 1 {
return diag.Errorf("multiple Identity Store Groups found matching criteria\n%v; try different search", input.Filters)
}

group := results[0]

d.SetId(aws.ToString(group.GroupId))
d.Set("description", group.Description)
d.Set("display_name", group.DisplayName)
d.Set("group_id", group.GroupId)

if err := d.Set("external_ids", flattenExternalIds(group.ExternalIds)); err != nil {
return create.DiagError(names.IdentityStore, create.ErrActionSetting, DSNameGroup, d.Id(), err)
}

return nil
}

var groupID string

if v, ok := d.GetOk("alternate_identifier"); ok && len(v.([]interface{})) > 0 {
Expand Down Expand Up @@ -239,31 +170,3 @@ func dataSourceGroupRead(ctx context.Context, d *schema.ResourceData, meta inter

return nil
}

func expandFilters(l []interface{}) []types.Filter {
if len(l) == 0 || l[0] == nil {
return nil
}

filters := make([]types.Filter, 0, len(l))
for _, v := range l {
tfMap, ok := v.(map[string]interface{})
if !ok {
continue
}

filter := types.Filter{}

if v, ok := tfMap["attribute_path"].(string); ok && v != "" {
filter.AttributePath = aws.String(v)
}

if v, ok := tfMap["attribute_value"].(string); ok && v != "" {
filter.AttributeValue = aws.String(v)
}

filters = append(filters, filter)
}

return filters
}
Loading

0 comments on commit 8002bcb

Please sign in to comment.