Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/aws_ram_resource_share - add resource_share_status argument #25159

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
data-source/aws_ram_resource_share: Add `resource_share_status` argument.
```
19 changes: 13 additions & 6 deletions internal/service/ram/resource_share_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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))
}
Expand Down
50 changes: 43 additions & 7 deletions internal/service/ram/resource_share_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand All @@ -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 = `
Expand All @@ -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)
}
3 changes: 2 additions & 1 deletion website/docs/d/ram_resource_share.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down