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 Policy/Attachment: Add skip_destroy attribute #29382

Merged
merged 7 commits into from
Feb 22, 2023

Conversation

jar-b
Copy link
Member

@jar-b jar-b commented Feb 13, 2023

Description

Adds an optional skip_destroy attribute to the aws_organizations_policy and aws_organizations_policy_attachment resources. This will allow for use cases where at least one policy attachment must be preserved to meet the minimum count required by AWS, while still allowing destruction of the underlying organization or account to proceed entirely within Terraform.

# this can now be freely destroyed, and with it the skipped policy/attachment will be cleaned up
resource "aws_organizations_organization" "test" {
  enabled_policy_types = ["SERVICE_CONTROL_POLICY"]
}

resource "aws_organizations_policy" "test" {
  depends_on = [aws_organizations_organization.test]

  name    = "test"
  type    = "SERVICE_CONTROL_POLICY"
  content = data.aws_iam_policy_document.test.json # definition omitted for brevity

  # preserve this policy so the associated attachment can remain
  skip_destroy = true
}

resource "aws_organizations_policy_attachment" "test" {
  policy_id = aws_organizations_policy.test.id
  target_id = aws_organizations_organization.test.master_account_id

  # preserve this attachment to meet the minimum attached policy requirement
  skip_destroy = true
}

Relations

Closes #26797

Output from Acceptance Testing

$ make testacc PKG=organizations TESTS="TestAccOrganizations_serial/PolicyAttachment/|TestAccOrganizations_serial/Policy/"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/organizations/... -v -count 1 -parallel 20 -run='TestAccOrganizations_serial/PolicyAttachment/|TestAccOrganizations_serial/Policy/'  -timeout 180m
=== RUN   TestAccOrganizations_serial
=== PAUSE TestAccOrganizations_serial
=== CONT  TestAccOrganizations_serial
=== RUN   TestAccOrganizations_serial/Policy
=== RUN   TestAccOrganizations_serial/Policy/Description
=== RUN   TestAccOrganizations_serial/Policy/Type_AI_OPT_OUT
=== RUN   TestAccOrganizations_serial/Policy/Type_Tag
=== RUN   TestAccOrganizations_serial/Policy/Type_SCP
=== RUN   TestAccOrganizations_serial/Policy/ImportAwsManagedPolicy
=== RUN   TestAccOrganizations_serial/Policy/basic
=== RUN   TestAccOrganizations_serial/Policy/concurrent
=== RUN   TestAccOrganizations_serial/Policy/Tags
=== RUN   TestAccOrganizations_serial/Policy/SkipDestroy
=== RUN   TestAccOrganizations_serial/Policy/disappears
=== RUN   TestAccOrganizations_serial/Policy/Type_Backup
=== RUN   TestAccOrganizations_serial/PolicyAttachment
=== RUN   TestAccOrganizations_serial/PolicyAttachment/OrganizationalUnit
=== RUN   TestAccOrganizations_serial/PolicyAttachment/Root
=== RUN   TestAccOrganizations_serial/PolicyAttachment/SkipDestroy
=== RUN   TestAccOrganizations_serial/PolicyAttachment/disappears
=== RUN   TestAccOrganizations_serial/PolicyAttachment/Account
--- PASS: TestAccOrganizations_serial (288.35s)
    --- PASS: TestAccOrganizations_serial/Policy (194.45s)
        --- PASS: TestAccOrganizations_serial/Policy/Description (19.27s)
        --- PASS: TestAccOrganizations_serial/Policy/Type_AI_OPT_OUT (12.09s)
        --- PASS: TestAccOrganizations_serial/Policy/Type_Tag (11.64s)
        --- PASS: TestAccOrganizations_serial/Policy/Type_SCP (19.23s)
        --- PASS: TestAccOrganizations_serial/Policy/ImportAwsManagedPolicy (12.07s)
        --- PASS: TestAccOrganizations_serial/Policy/basic (22.96s)
        --- PASS: TestAccOrganizations_serial/Policy/concurrent (26.38s)
        --- PASS: TestAccOrganizations_serial/Policy/Tags (37.51s)
        --- PASS: TestAccOrganizations_serial/Policy/SkipDestroy (10.28s)
        --- PASS: TestAccOrganizations_serial/Policy/disappears (11.00s)
        --- PASS: TestAccOrganizations_serial/Policy/Type_Backup (12.02s)
    --- PASS: TestAccOrganizations_serial/PolicyAttachment (93.90s)
        --- PASS: TestAccOrganizations_serial/PolicyAttachment/OrganizationalUnit (18.72s)
        --- PASS: TestAccOrganizations_serial/PolicyAttachment/Root (16.57s)
        --- PASS: TestAccOrganizations_serial/PolicyAttachment/SkipDestroy (15.42s)
        --- PASS: TestAccOrganizations_serial/PolicyAttachment/disappears (15.34s)
        --- PASS: TestAccOrganizations_serial/PolicyAttachment/Account (27.85s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/organizations      291.528s

@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. service/organizations Issues and PRs that pertain to the organizations service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/M Managed by automation to categorize the size of a PR. labels Feb 13, 2023
@jar-b jar-b force-pushed the f-organizations_policy_attachment-ignore-last-policy branch from f585131 to 14c8333 Compare February 16, 2023 16:16
@jar-b jar-b changed the title AWS Organizations Policy Attachment: Add ignore_last_policy_exception attribute AWS Organizations Policy/Attachment: Add skip_destroy attribute Feb 16, 2023
@github-actions github-actions bot added size/L Managed by automation to categorize the size of a PR. and removed size/M Managed by automation to categorize the size of a PR. labels Feb 16, 2023
@jar-b jar-b force-pushed the f-organizations_policy_attachment-ignore-last-policy branch from 14c8333 to d902310 Compare February 16, 2023 16:50
@jar-b jar-b marked this pull request as ready for review February 16, 2023 20:14
@jar-b jar-b force-pushed the f-organizations_policy_attachment-ignore-last-policy branch from d902310 to 48a2f58 Compare February 21, 2023 21:39
@jar-b jar-b force-pushed the f-organizations_policy_attachment-ignore-last-policy branch from 48a2f58 to 2d896e3 Compare February 22, 2023 15:50
@YakDriver YakDriver self-assigned this Feb 22, 2023
Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM 🎉 . In places we have testing challenges, I think the "best effort" and some reliance on the community is totally reasonable. The community would probably be okay with more reliance if it meant a bit faster turn around I'm guessing.

@jar-b jar-b merged commit 37601e3 into main Feb 22, 2023
@jar-b jar-b deleted the f-organizations_policy_attachment-ignore-last-policy branch February 22, 2023 16:40
@github-actions github-actions bot added this to the v4.56.0 milestone Feb 22, 2023
github-actions bot pushed a commit that referenced this pull request Feb 22, 2023
@github-actions
Copy link

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. service/organizations Issues and PRs that pertain to the organizations service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: aws_organizations_account account closure with all SCP's detached causes error.
2 participants