Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech debt: Use standard cross-account acceptance testing setup #10333

Closed
ewbankkit opened this issue Oct 1, 2019 · 7 comments
Closed

Tech debt: Use standard cross-account acceptance testing setup #10333

ewbankkit opened this issue Oct 1, 2019 · 7 comments
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. service/route53 Issues and PRs that pertain to the route53 service. service/s3 Issues and PRs that pertain to the s3 service. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented Oct 1, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

#7627 added standard cross-account acceptance testing setup functions testAccAlternateRegionProviderConfig(), testAccGetAlternateRegion() etc.
Ensure that these functions are used in acceptance tests for other cross-region resources.

  • aws_instance - TestAccAWSInstance_multipleRegions()
  • aws_rds_cluster - TestAccAWSRDSCluster_EncryptedCrossRegionReplication()
  • aws_route53_zone_association - TestAccAWSRoute53ZoneAssociation_region()
  • aws_s3_bucket - Multiple

Related:

@ewbankkit ewbankkit added the enhancement Requests to existing resources that expand the functionality or scope. label Oct 1, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 1, 2019
@ghost ghost added service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. service/route53 Issues and PRs that pertain to the route53 service. service/s3 Issues and PRs that pertain to the s3 service. labels Oct 1, 2019
@RickyRajinder
Copy link
Contributor

Hi, I'd like to contribute. Should each hard coded value be replaced with the alternate region functions or should the tests be extended to test on both default and alternate regions?

@bflad bflad added technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. and removed enhancement Requests to existing resources that expand the functionality or scope. needs-triage Waiting for first response or review from a maintainer. labels Oct 10, 2019
@ewbankkit
Copy link
Contributor Author

ewbankkit commented Oct 10, 2019

@RickyRajinder Thanks for volunteering 👏.

Looking at for example testAccAWSClusterConfigEncryptedCrossRegionReplica() I would suggest:

  • Removing the 2 hard-coded provider blocks
provider "aws" {
  alias  = "useast1"
  region = "us-east-1"
}
provider "aws" {
  alias  = "uswest2"
  region = "us-west-2"
}
  • Replacing
	return fmt.Sprintf(`

with

	return testAccAlternateRegionProviderConfig() + fmt.Sprintf(`
  • Removing all provider = "aws.useast1" lines
  • Replacing all provider = "aws.uswest2" with provider = "aws.alternate"
  • Replacing
data "aws_availability_zones" "us-east-1" {
  provider = "aws.useast1"
}

with

data "aws_availability_zones" "current" {}

and changing associated references

  • Adding
data "aws_region" "alternate" {
  provider = "aws.alternate"
}

data "aws_partition" "current" {}

and replacing

  replication_source_identifier = "arn:aws:rds:us-west-2:${data.aws_caller_identity.current.account_id}:cluster:${aws_rds_cluster.test_primary.cluster_identifier}"

with

  replication_source_identifier = "arn:${data.aws_partition.current.partition}:rds:${data.aws_region.alternate.name}:${data.aws_caller_identity.current.account_id}:cluster:${aws_rds_cluster.test_primary.cluster_identifier}"

and in TestAccAWSRDSCluster_EncryptedCrossRegionReplication():

  • Replacing
		PreCheck:          func() { testAccPreCheck(t) },

with

		PreCheck: func() {
			testAccPreCheck(t)
			testAccMultipleRegionsPreCheck(t)
			testAccAlternateRegionPreCheck(t)
		},
  • Replacing
		CheckDestroy:      testAccCheckWithProviders(testAccCheckAWSClusterDestroyWithProvider, &providers),

with

		CheckDestroy:      testAccCheckAWSClusterDestroy,
  • Replacing
				Check: resource.ComposeTestCheckFunc(
					testAccCheckAWSClusterExistsWithProvider(resourceName,
						&primaryCluster, testAccAwsRegionProviderFunc("us-west-2", &providers)),
					testAccCheckAWSClusterExistsWithProvider(resourceName2,
						&replicaCluster, testAccAwsRegionProviderFunc("us-east-1", &providers)),
				),

with

				Check: resource.ComposeTestCheckFunc(
					testAccCheckAWSClusterExists(resourceName, &primaryCluster),
					testAccCheckAWSClusterExistsWithProvider(resourceName2,
						&replicaCluster, testAccAwsRegionProviderFunc(testAccGetAlternateRegion(), &providers)),
				),

@ewbankkit
Copy link
Contributor Author

Also in TestAccAWSRDSCluster_EncryptedCrossRegionReplication(), calling acctest.RandInt() twice is going to cause the import test case to recreate the resources. So save the random value in a variable and pass it to testAccAWSClusterConfigEncryptedCrossRegionReplica().

@ewbankkit
Copy link
Contributor Author

Re-evaluate once #12277 et al. are merged.

@ewbankkit
Copy link
Contributor Author

Revisit for v3.x after #14312 is merged.

bflad added a commit that referenced this issue Aug 6, 2020
…ter_EncryptedCrossRegionReplication

Reference: #10333
Reference: #14384

Previously:

```
    TestAccAWSRDSCluster_EncryptedCrossRegionReplication: testing.go:684: Step 0 error: errors during apply:

        Error: error creating RDS cluster: InvalidParameterCombination: Cannot specify database name for cross region replication cluster
```

Output from acceptance testing:

```
--- PASS: TestAccAWSRDSCluster_ReplicationSourceIdentifier_KmsKeyId (1545.00s)
```
bflad added a commit that referenced this issue Aug 6, 2020
Reference: #10333
Reference: #13527
Reference: #13826
Reference: #14215

Changes:

* Add disappears testing to aws_route53_vpc_association_authorization.
* Ensure aws_route53_vpc_association_authorization example shows implicit ordering for downstream aws_route53_zone_association usage
* Fix aws_route53_zone_association VPC Region handling by including it in the ID, falling back to the attribute state, or falling back to the provider region. Document additional import handling.
* Add aws_route53_zone_association error handling to remove resource from state.
* Standardize aws_route53_zone_association disappears testing.

Output from acceptance testing:

```
--- PASS: TestAccAWSRoute53VpcAssociationAuthorization_disappears (110.26s)
--- PASS: TestAccAWSRoute53VpcAssociationAuthorization_basic (113.19s)

--- PASS: TestAccAWSRoute53ZoneAssociation_CrossAccount (211.48s)
--- PASS: TestAccAWSRoute53ZoneAssociation_CrossRegion (275.34s)
--- PASS: TestAccAWSRoute53ZoneAssociation_disappears_Zone (280.22s)
--- PASS: TestAccAWSRoute53ZoneAssociation_disappears (281.72s)
--- PASS: TestAccAWSRoute53ZoneAssociation_disappears_VPC (281.85s)
--- PASS: TestAccAWSRoute53ZoneAssociation_basic (283.83s)
```
bflad added a commit that referenced this issue Aug 6, 2020
…ter_EncryptedCrossRegionReplication (#14491)

Reference: #10333
Reference: #14384

Previously:

```
    TestAccAWSRDSCluster_EncryptedCrossRegionReplication: testing.go:684: Step 0 error: errors during apply:

        Error: error creating RDS cluster: InvalidParameterCombination: Cannot specify database name for cross region replication cluster
```

Output from acceptance testing:

```
--- PASS: TestAccAWSRDSCluster_ReplicationSourceIdentifier_KmsKeyId (1545.00s)
```
@ewbankkit
Copy link
Contributor Author

Closing as this is being/has been addressed via the linked issues.

@ghost
Copy link

ghost commented Nov 27, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. service/rds Issues and PRs that pertain to the rds service. service/route53 Issues and PRs that pertain to the route53 service. service/s3 Issues and PRs that pertain to the s3 service. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

No branches or pull requests

3 participants