From de5d2ccc55e0982f45155f278970a4cf54105dcd Mon Sep 17 00:00:00 2001 From: "xiaowei.wang" Date: Tue, 24 Apr 2018 11:18:18 +0200 Subject: [PATCH] r/cognito_user_pool_client: update ImportStateIdFunc --- ...ource_aws_cognito_user_pool_client_test.go | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/aws/resource_aws_cognito_user_pool_client_test.go b/aws/resource_aws_cognito_user_pool_client_test.go index a2d0b226612..53b0328fa9f 100644 --- a/aws/resource_aws_cognito_user_pool_client_test.go +++ b/aws/resource_aws_cognito_user_pool_client_test.go @@ -41,39 +41,30 @@ func TestAccAWSCognitoUserPoolClient_importBasic(t *testing.T) { resourceName := "aws_cognito_user_pool_client.client" - getStateId := func(*terraform.State) (string, error) { - var userPoolId string - var clientId string + getStateId := func(s *terraform.State) (string, error) { - conn := testAccProvider.Meta().(*AWSClient).cognitoidpconn - // do we need pagination-like logic here in case too many existing user pools? - pools, err := conn.ListUserPools(&cognitoidentityprovider.ListUserPoolsInput{MaxResults: aws.Int64(60)}) - if err != nil { - return "", fmt.Errorf("failed to list cognito user pools: %s", err) - } - for _, pool := range pools.UserPools { - if aws.StringValue(pool.Name) == userPoolName { - userPoolId = aws.StringValue(pool.Id) - } + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return "", fmt.Errorf("Not found: %s", resourceName) } - if len(userPoolId) == 0 { - return "", fmt.Errorf("cognito user pool %s not found", userPoolName) + + if rs.Primary.ID == "" { + return "", errors.New("No Cognito User Pool Client ID set") } - clients, err := conn.ListUserPoolClients(&cognitoidentityprovider.ListUserPoolClientsInput{ + conn := testAccProvider.Meta().(*AWSClient).cognitoidpconn + userPoolId := rs.Primary.Attributes["user_pool_id"] + clientId := rs.Primary.ID + + params := &cognitoidentityprovider.DescribeUserPoolClientInput{ UserPoolId: aws.String(userPoolId), - MaxResults: aws.Int64(10), - }) - if err != nil { - return "", fmt.Errorf("failed to list clients in user pool %s: %s", userPoolName, err) - } - for _, client := range clients.UserPoolClients { - if aws.StringValue(client.ClientName) == clientName { - clientId = aws.StringValue(client.ClientId) - } + ClientId: aws.String(clientId), } - if len(clientId) == 0 { - return "", fmt.Errorf("client %s not found in cognito user pool %s", clientName, userPoolName) + + _, err := conn.DescribeUserPoolClient(params) + + if err != nil { + return "", err } return fmt.Sprintf("%s/%s", userPoolId, clientId), nil