-
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_lightsail_domain: Remove hardcoded region and stan…
…dardize disappears testing Reference: #16302 Output from acceptance testing in AWS Commercial: ``` --- PASS: TestAccAWSLightsailDomain_disappears (10.22s) --- PASS: TestAccAWSLightsailDomain_basic (10.27s) ``` Output from acceptance testing in AWS GovCloud (US): ``` --- SKIP: TestAccAWSLightsailDomain_basic (1.70s) --- SKIP: TestAccAWSLightsailDomain_disappears (1.70s) ```
- Loading branch information
Showing
2 changed files
with
108 additions
and
31 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,90 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-sdk-go/service/lightsail" | ||
"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" | ||
) | ||
|
||
// Lightsail Domains can only be created in specific regions. | ||
|
||
// testAccLightsailDomainRegion is the chosen Lightsail Domains testing region | ||
// | ||
// Cached to prevent issues should multiple regions become available. | ||
var testAccLightsailDomainRegion string | ||
|
||
// testAccProviderLightsailDomain is the Lightsail 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. | ||
// | ||
// testAccPreCheckLightsailDomain(t) must be called before using this provider instance. | ||
var testAccProviderLightsailDomain *schema.Provider | ||
|
||
// testAccProviderLightsailDomainConfigure ensures the provider is only configured once | ||
var testAccProviderLightsailDomainConfigure sync.Once | ||
|
||
// Prevent panic with testAccCheckResourceDisappears | ||
func init() { | ||
testAccProviderLightsailDomain = Provider() | ||
} | ||
|
||
// testAccPreCheckLightsailDomain verifies AWS credentials and that Lightsail Domains is supported | ||
func testAccPreCheckLightsailDomain(t *testing.T) { | ||
testAccPartitionHasServicePreCheck(lightsail.EndpointsID, t) | ||
|
||
// Since we are outside the scope of the Terraform configuration we must | ||
// call Configure() to properly initialize the provider configuration. | ||
testAccProviderLightsailDomainConfigure.Do(func() { | ||
region := testAccGetLightsailDomainRegion() | ||
|
||
if region == "" { | ||
t.Skip("Lightsail Domains not available in this AWS Partition") | ||
} | ||
|
||
config := map[string]interface{}{ | ||
"region": region, | ||
} | ||
|
||
diags := testAccProviderLightsailDomain.Configure(context.Background(), terraform.NewResourceConfigRaw(config)) | ||
|
||
if diags != nil && diags.HasError() { | ||
for _, d := range diags { | ||
if d.Severity == diag.Error { | ||
t.Fatalf("error configuring Lightsail Domains provider: %s", d.Summary) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// testAccLightsailDomainRegionProviderConfig is the Terraform provider configuration for Lightsail Domains region testing | ||
// | ||
// Testing Lightsail Domains assumes no other provider configurations | ||
// are necessary and overwrites the "aws" provider configuration. | ||
func testAccLightsailDomainRegionProviderConfig() string { | ||
return testAccRegionalProviderConfig(testAccGetLightsailDomainRegion()) | ||
} | ||
|
||
// testAccGetLightsailDomainRegion returns the Lightsail Domains region for testing | ||
func testAccGetLightsailDomainRegion() string { | ||
if testAccLightsailDomainRegion != "" { | ||
return testAccLightsailDomainRegion | ||
} | ||
|
||
// AWS Commercial: https://lightsail.aws.amazon.com/ls/docs/en_us/articles/lightsail-how-to-create-dns-entry | ||
// AWS GovCloud (US) - service not supported: https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/using-services.html | ||
// AWS China - service not supported: https://www.amazonaws.cn/en/about-aws/regional-product-services/ | ||
switch testAccGetPartition() { | ||
case endpoints.AwsPartitionID: | ||
testAccLightsailDomainRegion = endpoints.UsEast1RegionID | ||
} | ||
|
||
return testAccLightsailDomainRegion | ||
} |
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