amazon-web-servicesterraformaws-organizations

Create / Destroy AWS account using Terraform?


I am trying to create a tool to easily create and destroy AWS accounts in my AWS organization (or at least remove them from the organisation if they can not be deleted). Those accounts are going to be sandbox with a small budget and destroyed after a couple of weeks.

I found that Terraform has a specific resource for that called aws_organizations_account.

However, this is mentioned that deleting this Terraform resource will only remove an AWS account from an organization. Terraform will not close the account. The member account must be prepared to be a standalone account beforehand. See the AWS Organizations documentation for more information.

I deployed an aws_organizations_account resource using terraform, it worked. But when I am trying to delete that resource, I am a warning issue that The member account must be configured with a valid payment method, such as a credit card

main.tf

resource "aws_organizations_account" "account" {
  name      = "sandbox1"
  email     = "first.last+sandbox1@company.com"
  role_name = "myOrganizationRole"
}

Is there any way to get around this issue?


Solution

  • Deleting an account is now available with the close account api. This functionality is enabled on terraform via the close_on_deletion flag.