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

AWS Organizations Move Account support #8281

Closed
acarrasquillo opened this issue Apr 11, 2019 · 7 comments · Fixed by #8583
Closed

AWS Organizations Move Account support #8281

acarrasquillo opened this issue Apr 11, 2019 · 7 comments · Fixed by #8583
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/organizations Issues and PRs that pertain to the organizations service.
Milestone

Comments

@acarrasquillo
Copy link

acarrasquillo commented Apr 11, 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

In a AWS micro accounts model, ease and automation of accounts creation with the configuration of these accounts in an AWS Organization is required. For managing an AWS organization and its accounts via terraform, I see the need of being able to create AWS Organizations Organization unit (OU) and associate accounts with it.

New Resource(s)

  • aws_organizations_organization_unit - Creates an organizational unit (OU) within a root or parent OU.
  • aws_organizations_organization_move_account - Moves an account from its current source parent root or organizational unit (OU) to the specified destination parent root or OU

Potential Terraform Configuration

resource "aws_organizations_organization_unit" "unit" {
   name = "name"
   parent_id = "ou-1234567" or "r-1234567" 
}

resource "aws_organizations_move_account" "move_account" {
   account_id = "111111111111"
   source_parent_id = "r-1234567"
   destination_parent_id = "ou-1234567"
}

References

@acarrasquillo acarrasquillo added the enhancement Requests to existing resources that expand the functionality or scope. label Apr 11, 2019
@bflad bflad added service/organizations Issues and PRs that pertain to the organizations service. new-resource Introduces a new resource. and removed enhancement Requests to existing resources that expand the functionality or scope. labels Apr 11, 2019
@murraypete
Copy link

Think #4207 already has this covered - looks like it should be merged soon

@acarrasquillo
Copy link
Author

Thanks for the update @murraypete 🙏

@bflad bflad added this to the v2.10.0 milestone May 8, 2019
@bflad
Copy link
Contributor

bflad commented May 8, 2019

Thanks to @afeld and @bryanlalexander, we just merged a new aws_organizations_organizational_unit resource for managing Organizational Units, which will be released with version 2.10.0 of the Terraform AWS Provider, likely tomorrow. 👍

The second ask of this feature request is a little bit more nuanced, I believe. This seems like it should be modeled as a new optional argument on the existing aws_organizations_account resource instead of a new resource as we do not typically require operators to manage resources to perform a one time infrastructure update. By example, I believe it could be handled with a new parent_id argument like the following.

Given an existing configuration, we could continue to allow this new parent_id argument to be omitted:

resource "aws_organizations_organization" "example" {}

resource "aws_organizations_account" "example" {
  email = "[email protected]"
  name  = "example"
}

In this example configuration, the value of the parent_id attribute is implicitly the Organization root ID (in the real world an account could already be under an Organizational Unit too!), but importantly, the difference is not shown to operators so when this is introduced it is not a breaking change.

The above configuration would be equivalent to the following where it is explicitly defined and checked for drift detection. (Note: this is utilizing our recent addition of the roots attribute, which will also be released in version 2.10.0 of the Terraform AWS Provider)

resource "aws_organizations_organization" "example" {}

resource "aws_organizations_account" "example" {
  email     = "[email protected]"
  name      = "example"
  parent_id = "${aws_organizations_organization.example.roots.0.id}"
}

Now if we want to create a new Organizational Unit and move the account under it, we could write the following to perform the update:

resource "aws_organizations_organization" "example" {}

resource "aws_organizations_organizational_unit" "example" {
  name      = "example"
  parent_id = "${aws_organizations_organization.test.roots.0.id}"
}

resource "aws_organizations_account" "example" {
  email     = "[email protected]"
  name      = "example"
  parent_id = "${aws_organizations_organizational_unit.example.id}"
}

Under the hood, this would be performing the MoveAccount call both during the aws_organizations_account resource Create function (if parent_id is configured and different than the Organization root) and Update function (if parent_id is updated). Hopefully this makes sense. 👍

I'm going to retitle this feature request issue to reflect the second ask since the first part (managing OUs) has been implemented.

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. and removed new-resource Introduces a new resource. labels May 8, 2019
@bflad bflad removed this from the v2.10.0 milestone May 8, 2019
@bflad bflad changed the title AWS Organizations Organization unit (OU) support AWS Organizations Move Account support May 8, 2019
bflad added a commit that referenced this issue May 9, 2019
…entation

References:

* #4405
* #8281

Please note that automated acceptance testing is not currently possible with this resource, due to manual steps required to remove an account from an organization: https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_remove.html

These changes were manually verified via the following.

Given an existing configuration, previously applied with version 2.9.0 of the Terraform AWS Provider:

```hcl
resource "aws_organizations_organization" "organization" {
  feature_set = "ALL"
}

resource "aws_organizations_account" "bflad-dev1" {
  name  = "bflad-dev1"
  email = "--OMITTED--"
}

resource "aws_organizations_account" "bflad-dev2" {
  name  = "bflad-dev2"
  email = "--OMITTED--"
}
```

Overwrite Terraform AWS Provider binary including this changeset, ensure plan shows no changes, and ensure `parent_id` is properly written to Terraform state:

```console
$ cp ~/go/bin/terraform-provider-aws .terraform/plugins/darwin_amd64/terraform-provider-aws_v2.9.0_x4
$ terraform init
...
$ terraform plan
...
aws_organizations_organization.organization: Refreshing state... (ID: o-p687o6l073)
aws_organizations_account.bflad-dev2: Refreshing state... (ID: --OMITTED--)
aws_organizations_account.bflad-dev1: Refreshing state... (ID: --OMITTED--)

------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.
$ terraform refresh
...
$ terraform state show aws_organizations_account.bflad-dev1 | grep parent_id
parent_id     = r-cg2b
```

Add organizational unit to configuration and add `parent_id` to an existing account pointing to it:

```hcl
resource "aws_organizations_organization" "organization" {
  feature_set = "ALL"
}

resource "aws_organizations_organizational_unit" "test1" {
  name      = "test1"
  parent_id = "${aws_organizations_organization.organization.roots.0.id}"
}

resource "aws_organizations_account" "bflad-dev1" {
  name      = "bflad-dev1"
  email     = "--OMITTED--"
  parent_id = "${aws_organizations_organizational_unit.test1.id}"
}

resource "aws_organizations_account" "bflad-dev2" {
  name  = "bflad-dev2"
  email = "--OMITTED--"
}
```

Verifying `Update` functionality:

```
$ terraform apply
...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

  ~ aws_organizations_account.bflad-dev1
      parent_id: "r-cg2b" => "${aws_organizations_organizational_unit.test1.id}"

  + aws_organizations_organizational_unit.test1
      id:        <computed>
      arn:       <computed>
      name:      "test1"
      parent_id: "r-cg2b"

Plan: 1 to add, 1 to change, 0 to destroy.

...

aws_organizations_organizational_unit.test1: Creating...
  arn:       "" => "<computed>"
  name:      "" => "test1"
  parent_id: "" => "r-cg2b"
aws_organizations_organizational_unit.test1: Creation complete after 0s (ID: ou-cg2b-7aa8b56k)
aws_organizations_account.bflad-dev1: Modifying... (ID: --OMITTED--)
  parent_id: "r-cg2b" => "ou-cg2b-7aa8b56k"
aws_organizations_account.bflad-dev1: Modifications complete after 1s (ID: --OMITTED--)

$ terraform state show aws_organizations_account.bflad-dev1 | grep parent_id
parent_id     = ou-cg2b-7aa8b56k
```

Add account with `parent_id` to configuration:

```hcl
resource "aws_organizations_organization" "organization" {
  feature_set = "ALL"
}

resource "aws_organizations_organizational_unit" "test1" {
  name      = "test1"
  parent_id = "${aws_organizations_organization.organization.roots.0.id}"
}

resource "aws_organizations_account" "bflad-dev1" {
  name      = "bflad-dev1"
  email     = "--OMITTED--"
  parent_id = "${aws_organizations_organizational_unit.test1.id}"
}

resource "aws_organizations_account" "bflad-dev2" {
  name  = "bflad-dev2"
  email = "--OMITTED--"
}

resource "aws_organizations_account" "bflad-dev3" {
  name      = "bflad-dev3"
  email     = "--OMITTED--"
  parent_id = "${aws_organizations_organizational_unit.test1.id}"
}
```

Verifying `Create` functionality:

```
$ terraform apply
...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + aws_organizations_account.bflad-dev3
      id:               <computed>
      arn:              <computed>
      email:            "--OMITTED--"
      joined_method:    <computed>
      joined_timestamp: <computed>
      name:             "bflad-dev3"
      parent_id:        "ou-cg2b-7aa8b56k"
      status:           <computed>

Plan: 1 to add, 0 to change, 0 to destroy.

...

aws_organizations_account.bflad-dev3: Creating...
  arn:              "" => "<computed>"
  email:            "" => "--OMITTED--"
  joined_method:    "" => "<computed>"
  joined_timestamp: "" => "<computed>"
  name:             "" => "bflad-dev3"
  parent_id:        "" => "ou-cg2b-7aa8b56k"
  status:           "" => "<computed>"
aws_organizations_account.bflad-dev3: Still creating... (10s elapsed)
aws_organizations_account.bflad-dev3: Creation complete after 12s (ID: --OMITTED--)
$ terraform state show aws_organizations_account.bflad-dev3 | grep parent_id
parent_id     = ou-cg2b-7aa8b56k
```
@bflad
Copy link
Contributor

bflad commented May 9, 2019

Pull request submitted for parent_id functionality, based off some work done in #4405: #8583

@bflad
Copy link
Contributor

bflad commented May 17, 2019

Support for moving AWS Organizations Accounts via a new parent_id argument, has been merged and will release with version 2.11.0 of the Terraform AWS Provider, very shortly. 👍

@bflad
Copy link
Contributor

bflad commented May 17, 2019

This has been released in version 2.11.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Mar 30, 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 and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/organizations Issues and PRs that pertain to the organizations service.
Projects
None yet
3 participants