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

data-source/cognito_user_pools: add attribute of arns #4256

Merged
merged 1 commit into from
Apr 20, 2018
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
21 changes: 20 additions & 1 deletion aws/data_source_aws_cognito_user_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/hashicorp/terraform/helper/schema"
)
Expand All @@ -21,6 +22,11 @@ func dataSourceAwsCognitoUserPools() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"arns": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand All @@ -29,14 +35,25 @@ func dataSourceAwsCognitoUserPoolsRead(d *schema.ResourceData, meta interface{})
conn := meta.(*AWSClient).cognitoidpconn
name := d.Get("name").(string)
var ids []string
var arns []string

pools, err := getAllCognitoUserPools(conn)
if err != nil {
return fmt.Errorf("Error listing cognito user pools: %s", err)
}
for _, pool := range pools {
if name == aws.StringValue(pool.Name) {
ids = append(ids, aws.StringValue(pool.Id))
id := aws.StringValue(pool.Id)
arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "cognito-idp",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("userpool/%s", id),
}.String()

ids = append(ids, id)
arns = append(arns, arn)
}
}

Expand All @@ -46,6 +63,8 @@ func dataSourceAwsCognitoUserPoolsRead(d *schema.ResourceData, meta interface{})

d.SetId(name)
d.Set("ids", ids)
d.Set("arns", arns)

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions aws/data_source_aws_cognito_user_pools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func TestAccDataSourceAwsCognitoUserPools_basic(t *testing.T) {
{
Config: testAccDataSourceAwsCognitoUserPoolsConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.aws_cognito_user_pools.selected", "ids.#", "3"),
resource.TestCheckResourceAttr("data.aws_cognito_user_pools.selected", "ids.#", "2"),
resource.TestCheckResourceAttr("data.aws_cognito_user_pools.selected", "arns.#", "2"),
),
},
{
Expand All @@ -32,7 +33,7 @@ func TestAccDataSourceAwsCognitoUserPools_basic(t *testing.T) {
func testAccDataSourceAwsCognitoUserPoolsConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_cognito_user_pool" "main" {
count = 3
count = 2
name = "%s"
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/cognito_user_pools.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "aws_api_gateway_authorizer" "cognito" {
name = "cognito"
type = "COGNITO_USER_POOLS"
rest_api_id = "${data.aws_api_gateway_rest_api.selected.id}"
provider_arns = ["${data.aws_cognito_user_pools.selected.ids}"]
provider_arns = ["${data.aws_cognito_user_pools.selected.arns}"]
}
```

Expand Down