Skip to content

Commit

Permalink
feat: Mark name arg as optional to match AWS API for aws_ram_resource…
Browse files Browse the repository at this point in the history
…_share data source
  • Loading branch information
acwwat committed Mar 4, 2024
1 parent 2dc8341 commit b7e7f76
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
12 changes: 8 additions & 4 deletions internal/service/ram/resource_share_data_source.go
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

// @SDKDataSource("aws_ram_resource_share")
Expand Down Expand Up @@ -48,7 +49,8 @@ func dataSourceResourceShare() *schema.Resource {
},
"name": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
},
"owning_account_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -84,13 +86,15 @@ func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, me
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).RAMConn(ctx)

name := d.Get("name").(string)
resourceOwner := d.Get("resource_owner").(string)
inputG := &ram.GetResourceSharesInput{
Name: aws.String(name),
ResourceOwner: aws.String(resourceOwner),
}

if v, ok := d.GetOk("name"); ok {
inputG.Name = aws.String(v.(string))
}

if v, ok := d.GetOk("filter"); ok && v.(*schema.Set).Len() > 0 {
inputG.TagFilters = expandTagFilters(v.(*schema.Set).List())
}
Expand All @@ -102,7 +106,7 @@ func dataSourceResourceShareRead(ctx context.Context, d *schema.ResourceData, me
share, err := findResourceShare(ctx, conn, inputG)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading RAM Resource Share (%s): %s", name, err)
return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("RAM Resource Share", err))
}

arn := aws.StringValue(share.ResourceShareArn)
Expand Down
30 changes: 30 additions & 0 deletions internal/service/ram/resource_share_data_source_test.go
Expand Up @@ -53,6 +53,15 @@ func TestAccRAMResourceShareDataSource_tags(t *testing.T) {
Config: testAccResourceShareDataSourceConfig_tags(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"),
),
},
{
Config: testAccResourceShareDataSourceConfig_tagsWithoutName(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"),
),
},
Expand Down Expand Up @@ -145,6 +154,27 @@ data "aws_ram_resource_share" "test" {
`, rName)
}

func testAccResourceShareDataSourceConfig_tagsWithoutName(rName string) string {
return fmt.Sprintf(`
resource "aws_ram_resource_share" "test" {
name = %[1]q
tags = {
Name = %[1]q
}
}
data "aws_ram_resource_share" "test" {
resource_owner = "SELF"
filter {
name = "Name"
values = [%[1]q]
}
}
`, rName)
}

func testAccResourceShareDataSourceConfig_resources(rName string) string {
return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(`
resource "aws_ram_resource_share" "test" {
Expand Down
5 changes: 1 addition & 4 deletions website/docs/d/ram_resource_share.html.markdown
Expand Up @@ -23,9 +23,7 @@ data "aws_ram_resource_share" "example" {

```terraform
data "aws_ram_resource_share" "tag_filter" {
name = "MyResourceName"
resource_owner = "SELF"
filter {
name = "NameOfTag"
values = ["exampleNameTagValue"]
Expand All @@ -37,9 +35,8 @@ data "aws_ram_resource_share" "tag_filter" {

This data source supports the following arguments:

* `name` - (Required) Name of the resource share to retrieve.
* `name` - (Optional) Name of the resource share to retrieve.
* `resource_owner` (Required) Owner of the resource share. Valid values are `SELF` or `OTHER-ACCOUNTS`.

* `resource_share_status` (Optional) Specifies that you want to retrieve details of only those resource shares that have this status. Valid values are `PENDING`, `ACTIVE`, `FAILED`, `DELETING`, and `DELETED`.
* `filter` - (Optional) Filter used to scope the list e.g., by tags. See [related docs] (https://docs.aws.amazon.com/ram/latest/APIReference/API_TagFilter.html).
* `name` - (Required) Name of the tag key to filter on.
Expand Down

0 comments on commit b7e7f76

Please sign in to comment.