Skip to content

Commit

Permalink
Merge pull request #23891 from roberth-k/d-aws_memorydb_acl
Browse files Browse the repository at this point in the history
d/aws_memorydb_acl: new data source
  • Loading branch information
ewbankkit authored Mar 28, 2022
2 parents 6c440d6 + 02bbae8 commit b009895
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/23891.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_memorydb_acl
```
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ func Provider() *schema.Provider {
"aws_regions": meta.DataSourceRegions(),
"aws_service": meta.DataSourceService(),

"aws_memorydb_acl": memorydb.DataSourceACL(),
"aws_memorydb_parameter_group": memorydb.DataSourceParameterGroup(),
"aws_memorydb_subnet_group": memorydb.DataSourceSubnetGroup(),
"aws_memorydb_user": memorydb.DataSourceUser(),
Expand Down
72 changes: 72 additions & 0 deletions internal/service/memorydb/acl_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package memorydb

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func DataSourceACL() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceACLRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"minimum_engine_version": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"tags": tftags.TagsSchemaComputed(),
"user_names": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}

func dataSourceACLRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).MemoryDBConn
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

name := d.Get("name").(string)

acl, err := FindACLByName(ctx, conn, name)

if err != nil {
return diag.FromErr(tfresource.SingularDataSourceFindError("MemoryDB ACL", err))
}

d.SetId(aws.StringValue(acl.Name))

d.Set("arn", acl.ARN)
d.Set("minimum_engine_version", acl.MinimumEngineVersion)
d.Set("name", acl.Name)
d.Set("user_names", flex.FlattenStringSet(acl.UserNames))

tags, err := ListTags(conn, d.Get("arn").(string))

if err != nil {
return diag.Errorf("error listing tags for MemoryDB ACL (%s): %s", d.Id(), err)
}

if err := d.Set("tags", tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return diag.Errorf("error setting tags: %s", err)
}

return nil
}
62 changes: 62 additions & 0 deletions internal/service/memorydb/acl_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package memorydb_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/memorydb"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccMemoryDBACLDataSource_basic(t *testing.T) {
rName := "tf-test-" + sdkacctest.RandString(8)
resourceName := "aws_memorydb_acl.test"
dataSourceName := "data.aws_memorydb_acl.test"
userName1 := "tf-" + sdkacctest.RandString(8)
userName2 := "tf-" + sdkacctest.RandString(8)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, memorydb.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccACLDataSourceConfig(rName, userName1, userName2),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "minimum_engine_version", resourceName, "minimum_engine_version"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttr(dataSourceName, "user_names.#", "2"),
resource.TestCheckTypeSetElemAttrPair(dataSourceName, "user_names.*", resourceName, "user_names.0"),
resource.TestCheckTypeSetElemAttrPair(dataSourceName, "user_names.*", resourceName, "user_names.1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.Test", resourceName, "tags.Test"),
),
},
},
})
}

func testAccACLDataSourceConfig(rName, userName1, userName2 string) string {
return acctest.ConfigCompose(
testAccACLConfigUsers(userName1, userName2),
fmt.Sprintf(`
resource "aws_memorydb_acl" "test" {
depends_on = [aws_memorydb_user.test]
name = %[1]q
user_names = [%[2]q, %[3]q]
tags = {
Test = "test"
}
}
data "aws_memorydb_acl" "test" {
name = aws_memorydb_acl.test.name
}
`, rName, userName1, userName2),
)
}
35 changes: 35 additions & 0 deletions website/docs/d/memorydb_acl.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
subcategory: "MemoryDB"
layout: "aws"
page_title: "AWS: aws_memorydb_acl"
description: |-
Provides information about a MemoryDB ACL.
---

# Resource: aws_memorydb_acl

Provides information about a MemoryDB ACL.

## Example Usage

```terraform
data "aws_memorydb_acl" "example" {
name = "my-acl"
}
```

## Argument Reference

The following arguments are required:

* `name` - (Required) Name of the ACL.

## Attributes Reference

In addition, the following attributes are exported:

* `id` - Name of the ACL.
* `arn` - ARN of the ACL.
* `minimum_engine_version` - The minimum engine version supported by the ACL.
* `tags` - A map of tags assigned to the ACL.
* `user_names` - Set of MemoryDB user names included in this ACL.

0 comments on commit b009895

Please sign in to comment.