hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.82k stars 9.17k forks source link

AWS Organizations acceptance test #11582

Open ericksoen opened 4 years ago

ericksoen commented 4 years ago

Community Note

Description

I've noticed that when I run the AWS Organizations Acceptance tests, I frequently encounter an error from the configured testAccOrganizationsAccountPreCheck that outputs the error "skipping tests; this AWS account must not be an existing member of an AWS Organization". The AWS Organizations API doesn't make it easy to leave an organization, e.g., the master account can't leave an organization and a member account receives the error "ConstraintViolationException when calling the LeaveOrganization operation. This operation requires a wait period" (without much supporting documentation from AWS regarding the duration of the wait period).

To make acceptance tests easier to run repeatedly, I was curious about the changing the behavior to remove the resource "aws_organizations_organization" "test" {} from certain acceptance tests and adding a PreTestCheck that validates that the account where acceptance tests are being run includes an AWS Organization. Alternatively (or in addition), where an explicitly AWS Organization resource is required, using the data aws_organizations_organization data source to get a provider reference.

New or Affected Resource(s)

Potential Terraform Configuration

References

gdavison commented 4 years ago

Thanks for this issue, @ericksoen. Typically, our acceptance tests are written to be standalone. As you've found, this can cause problems with some services. We've been talking on our team about some approaches we can take to deal with these more challenging services. Go 1.14 added a new Cleanup() function which could help with this.