From 8d9caeaae70fca1f078298109f64bc9926b7813a Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Thu, 29 Jun 2023 11:41:58 +0200 Subject: [PATCH] CognitoIDP[UserPoolClient]: Avoid underlying provider validation failure * In a current state the instantiation of `UserPoolClient` fails with ``` cannot run refresh: refresh failed: reading Amazon Cognito IDP (Identity Provider) User Pool Client (): InvalidParameter: 1 validation error(s) found. - minimum field size of 1, DescribeUserPoolClientInput.ClientId. ``` unless we explicitly set the `external-name` annotation. See #752 for more debugging data * This change will preset the `id` with `spec.forProvider.name` to avoid the validation failure. The `id` will be populated eventually with the dynamic value from the cloud provider * I also tried to follow the doc at https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cognito_user_pool_client#import but it seems to be wrong in practice: If we use smth like ``` TemplatedStringAsIdentifierWithNoName("{{ .parameters.user_pool_id }}/{{ .parameters.name }}"), ``` it will fail with ``` cannot run refresh: refresh failed: reading Amazon Cognito IDP (Identity Provider) User Pool Client (us-west-1_dMnICLKVB/): InvalidParameterException: 1 validation error detected: Value 'us-west-1_dMnICLKVB/' at 'clientId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w+]+ ``` It proves that the import doc deviates from reality and fails its own provider validation. * It is possible that we observe the bug in the underlying terraform aws provider. * This fix provides best possible solution without the fix of underlying provider and associated costs. * Fixes #752 Signed-off-by: Yury Tsarev --- config/externalname.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/externalname.go b/config/externalname.go index 38da8d0a55..2aa1059975 100644 --- a/config/externalname.go +++ b/config/externalname.go @@ -111,7 +111,7 @@ var ExternalNameConfigs = map[string]config.ExternalName{ // us-west-2_abc123 "aws_cognito_user_pool": config.IdentifierFromProvider, // us-west-2_abc123/3ho4ek12345678909nh3fmhpko - "aws_cognito_user_pool_client": config.IdentifierFromProvider, + "aws_cognito_user_pool_client": TemplatedStringAsIdentifierWithNoName("{{ .parameters.name }}"), // auth.example.org "aws_cognito_user_pool_domain": config.IdentifierFromProvider, // us-west-2_ZCTarbt5C,12bu4fuk3mlgqa2rtrujgp6egq