diff --git a/aws/data_source_aws_cognito_user_pools.go b/aws/data_source_aws_cognito_user_pools.go index f365e0987c8..700f9f4958d 100644 --- a/aws/data_source_aws_cognito_user_pools.go +++ b/aws/data_source_aws_cognito_user_pools.go @@ -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" ) @@ -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}, + }, }, } } @@ -29,6 +35,7 @@ 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 { @@ -36,7 +43,17 @@ func dataSourceAwsCognitoUserPoolsRead(d *schema.ResourceData, meta interface{}) } 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) } } @@ -46,6 +63,8 @@ func dataSourceAwsCognitoUserPoolsRead(d *schema.ResourceData, meta interface{}) d.SetId(name) d.Set("ids", ids) + d.Set("arns", arns) + return nil } diff --git a/aws/data_source_aws_cognito_user_pools_test.go b/aws/data_source_aws_cognito_user_pools_test.go index 2e49cbbb1d8..a8bdd1ae142 100644 --- a/aws/data_source_aws_cognito_user_pools_test.go +++ b/aws/data_source_aws_cognito_user_pools_test.go @@ -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"), ), }, { @@ -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" } diff --git a/website/docs/d/cognito_user_pools.markdown b/website/docs/d/cognito_user_pools.markdown index ebbf82fc99a..fd2dde3cae7 100644 --- a/website/docs/d/cognito_user_pools.markdown +++ b/website/docs/d/cognito_user_pools.markdown @@ -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}"] } ```