-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/resource/aws_cognito_user_pool_domain: Remove hardcoded region …
…handling and create public ACM Certificate Reference: #8316 Reference: #15737 Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSCognitoUserPoolDomain_custom (816.97s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccAWSCognitoUserPoolDomain_custom (1.64s) ```
- Loading branch information
Showing
4 changed files
with
170 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
// Cognito User Pool Custom Domains can only be created with ACM Certificates in specific regions. | ||
|
||
// testAccCognitoUserPoolCustomDomainRegion is the chosen Cognito User Pool Custom Domains testing region | ||
// | ||
// Cached to prevent issues should multiple regions become available. | ||
var testAccCognitoUserPoolCustomDomainRegion string | ||
|
||
// testAccProviderCognitoUserPoolCustomDomain is the Cognito User Pool Custom Domains provider instance | ||
// | ||
// This Provider can be used in testing code for API calls without requiring | ||
// the use of saving and referencing specific ProviderFactories instances. | ||
// | ||
// testAccPreCheckCognitoUserPoolCustomDomain(t) must be called before using this provider instance. | ||
var testAccProviderCognitoUserPoolCustomDomain *schema.Provider | ||
|
||
// testAccProviderCognitoUserPoolCustomDomainConfigure ensures the provider is only configured once | ||
var testAccProviderCognitoUserPoolCustomDomainConfigure sync.Once | ||
|
||
// testAccPreCheckCognitoUserPoolCustomDomain verifies AWS credentials and that Cognito User Pool Custom Domains is supported | ||
func testAccPreCheckCognitoUserPoolCustomDomain(t *testing.T) { | ||
testAccPartitionHasServicePreCheck(cognitoidentityprovider.EndpointsID, t) | ||
|
||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderCognitoUserPoolCustomDomainConfigure.Do(func() { | ||
testAccProviderCognitoUserPoolCustomDomain = Provider() | ||
|
||
region := testAccGetCognitoUserPoolCustomDomainRegion() | ||
|
||
if region == "" { | ||
t.Skip("Cognito User Pool Custom Domains not available in this AWS Partition") | ||
} | ||
|
||
config := map[string]interface{}{ | ||
"region": region, | ||
} | ||
|
||
diags := testAccProviderCognitoUserPoolCustomDomain.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if diags != nil && diags.HasError() { | ||
for _, d := range diags { | ||
if d.Severity == diag.Error { | ||
t.Fatalf("error configuring Cognito User Pool Custom Domains provider: %s", d.Summary) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// testAccCognitoUserPoolCustomDomainRegionProviderConfig is the Terraform provider configuration for Cognito User Pool Custom Domains region testing | ||
// | ||
// Testing Cognito User Pool Custom Domains assumes no other provider configurations | ||
// are necessary and overwrites the "aws" provider configuration. | ||
func testAccCognitoUserPoolCustomDomainRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetCognitoUserPoolCustomDomainRegion()) | ||
} | ||
|
||
// testAccGetCognitoUserPoolCustomDomainRegion returns the Cognito User Pool Custom Domains region for testing | ||
func testAccGetCognitoUserPoolCustomDomainRegion() string { | ||
if testAccCognitoUserPoolCustomDomainRegion != "" { | ||
return testAccCognitoUserPoolCustomDomainRegion | ||
} | ||
|
||
// AWS Commercial: https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-add-custom-domain.html | ||
// AWS GovCloud (US) - not supported: https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-cog.html | ||
// AWS China - not supported: https://docs.amazonaws.cn/en_us/aws/latest/userguide/cognito.html | ||
switch testAccGetPartition() { | ||
case endpoints.AwsPartitionID: | ||
testAccCognitoUserPoolCustomDomainRegion = endpoints.UsEast1RegionID | ||
} | ||
|
||
return testAccCognitoUserPoolCustomDomainRegion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,8 +400,6 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi | |
| `AWS_API_GATEWAY_DOMAIN_NAME_REGIONAL_CERTIFICATE_NAME_ENABLED` | Flag to enable API Gateway Domain Name regional certificate upload testing. | | ||
| `AWS_CODEBUILD_BITBUCKET_SOURCE_LOCATION` | BitBucket source URL for CodeBuild testing. CodeBuild must have access to this repository via OAuth or Source Credentials. Defaults to `https://[email protected]/terraform/aws-test.git`. | | ||
| `AWS_CODEBUILD_GITHUB_SOURCE_LOCATION` | GitHub source URL for CodeBuild testing. CodeBuild must have access to this repository via OAuth or Source Credentials. Defaults to `https://github.com/hashibot-test/aws-test.git`. | | ||
| `AWS_COGNITO_USER_POOL_DOMAIN_CERTIFICATE_ARN` | Amazon Resource Name of ACM Certificate in `us-east-1` for Cognito User Pool Domain Name testing. | | ||
| `AWS_COGNITO_USER_POOL_DOMAIN_ROOT_DOMAIN` | Root domain name to use with Cognito User Pool Domain testing. | | ||
| `AWS_DEFAULT_REGION` | Primary AWS region for tests. Defaults to `us-west-2`. | | ||
| `AWS_EC2_CLASSIC_REGION` | AWS region for EC2-Classic testing. Defaults to `us-east-1` in AWS Commercial and `AWS_DEFAULT_REGION` otherwise. | | ||
| `AWS_EC2_CLIENT_VPN_LIMIT` | Concurrency limit for Client VPN acceptance tests. [Default is 5](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/limits.html) if not specified. | | ||
|