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

resource/aws_organizations_account: Add parent_id argument (support moving accounts) #8583

Merged
merged 3 commits into from
May 17, 2019

Commits on May 9, 2019

  1. Configuration menu
    Copy the full SHA
    ba1dd53 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    072c303 View commit details
    Browse the repository at this point in the history
  3. resource/aws_organizations_account: Finish initial parent_id implem…

    …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 committed May 9, 2019
    Configuration menu
    Copy the full SHA
    ecf4653 View commit details
    Browse the repository at this point in the history