From a21839135e5f16badbbddf53db1f135ccbad77fc Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 3 Jun 2022 12:10:54 +0300 Subject: [PATCH 1/3] ram resource share data source - filter by status --- .../service/ram/resource_share_data_source.go | 19 ++++--- .../ram/resource_share_data_source_test.go | 50 ++++++++++++++++--- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/internal/service/ram/resource_share_data_source.go b/internal/service/ram/resource_share_data_source.go index 33552e57836..9638f433320 100644 --- a/internal/service/ram/resource_share_data_source.go +++ b/internal/service/ram/resource_share_data_source.go @@ -35,12 +35,15 @@ func DataSourceResourceShare() *schema.Resource { }, "resource_owner": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - ram.ResourceOwnerOtherAccounts, - ram.ResourceOwnerSelf, - }, false), + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(ram.ResourceOwner_Values(), false), + }, + + "resource_share_status": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(ram.ResourceShareStatus_Values(), false), }, "name": { @@ -82,6 +85,10 @@ func dataSourceResourceShareRead(d *schema.ResourceData, meta interface{}) error ResourceOwner: aws.String(owner), } + if v, ok := d.GetOk("resource_share_status"); ok { + params.ResourceShareStatus = aws.String(v.(string)) + } + if filtersOk { params.TagFilters = buildTagFilters(filters.(*schema.Set)) } diff --git a/internal/service/ram/resource_share_data_source_test.go b/internal/service/ram/resource_share_data_source_test.go index 7abe8cb462c..28dd8ae28f1 100644 --- a/internal/service/ram/resource_share_data_source_test.go +++ b/internal/service/ram/resource_share_data_source_test.go @@ -59,30 +59,52 @@ func TestAccRAMResourceShareDataSource_tags(t *testing.T) { }) } +func TestAccRAMResourceShareDataSource_status(t *testing.T) { + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_ram_resource_share.test" + datasourceName := "data.aws_ram_resource_share.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, ram.EndpointsID), + ProviderFactories: acctest.ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccResourceShareDataSourceConfig_Status(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"), + resource.TestCheckResourceAttrSet(datasourceName, "owning_account_id"), + ), + }, + }, + }) +} + func testAccResourceShareDataSourceConfig_Name(rName string) string { return fmt.Sprintf(` resource "aws_ram_resource_share" "wrong" { - name = "%s-wrong" + name = "%[1]s-wrong" } resource "aws_ram_resource_share" "test" { - name = "%s" + name = %[1]q } data "aws_ram_resource_share" "test" { name = aws_ram_resource_share.test.name resource_owner = "SELF" } -`, rName, rName) +`, rName) } func testAccResourceShareDataSourceConfig_Tags(rName string) string { return fmt.Sprintf(` resource "aws_ram_resource_share" "test" { - name = "%s" + name = %[1]q tags = { - Name = "%s-Tags" + Name = "%[1]s-Tags" } } @@ -92,10 +114,10 @@ data "aws_ram_resource_share" "test" { filter { name = "Name" - values = ["%s-Tags"] + values = ["%[1]s-Tags"] } } -`, rName, rName, rName) +`, rName) } const testAccResourceShareDataSourceConfig_NonExistent = ` @@ -104,3 +126,17 @@ data "aws_ram_resource_share" "test" { resource_owner = "SELF" } ` + +func testAccResourceShareDataSourceConfig_Status(rName string) string { + return fmt.Sprintf(` +resource "aws_ram_resource_share" "test" { + name = "%s" +} + +data "aws_ram_resource_share" "test" { + name = aws_ram_resource_share.test.name + resource_owner = "SELF" + resource_share_status = "ACTIVE" +} +`, rName) +} From 57ee0e99ddda71e40e20812cb4a1baf257347e5e Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 3 Jun 2022 12:13:51 +0300 Subject: [PATCH 2/3] docs --- website/docs/d/ram_resource_share.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/docs/d/ram_resource_share.html.markdown b/website/docs/d/ram_resource_share.html.markdown index d33188aa755..f91e4a6850e 100644 --- a/website/docs/d/ram_resource_share.html.markdown +++ b/website/docs/d/ram_resource_share.html.markdown @@ -38,8 +38,9 @@ data "aws_ram_resource_share" "tag_filter" { The following Arguments are supported * `name` - (Required) The name of the resource share to retrieve. -* `resource_owner` (Required) The owner of the resource share. Valid values are SELF or OTHER-ACCOUNTS +* `resource_owner` (Required) The 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) A 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) The name of the tag key to filter on. * `values` - (Required) The value of the tag key. From 8ef795fcfe5abac6842468ef66712998572a9e74 Mon Sep 17 00:00:00 2001 From: drfaust92 Date: Fri, 3 Jun 2022 12:15:58 +0300 Subject: [PATCH 3/3] changelog --- .changelog/25159.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/25159.txt diff --git a/.changelog/25159.txt b/.changelog/25159.txt new file mode 100644 index 00000000000..e9b0f66d6ad --- /dev/null +++ b/.changelog/25159.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +data-source/aws_ram_resource_share: Add `resource_share_status` argument. +```