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

r/aws_cloudformation_stack_set_instance: Empty OU refactor #24523

Conversation

sbutler
Copy link
Contributor

@sbutler sbutler commented May 3, 2022

Community Note

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

Description

The original code tried to add deployment target support by finding an account in one of the targets, and then using all the same code as account stack set instances. This is deficient:

  • If none of the targets contain an account the code fails, due to the resource Id not having an accountID value.
  • It does not expose information like account IDs and stack set IDs for any accounts in the deployment targets, except the arbitrary account it used.
  • It can cause the resource Id to needlessly drift due to the account selection process changing (account moved OU's, or the API decided to return things in a different order, etc).

This refactor treats deployment targets as their own branch of the logic, with their own new attributes.

Relations

Closes #23349

The added ForceNew directive for the deployment_targets argument relates to (and possibly resolves):

Relates #27877
Relates #25253

Output from Acceptance Testing

WIP due to not being familiar enough with Go to add additional tests for this change.

Output from acceptance testing:

$ make testacc TESTS=TestAccXXX PKG=ec2

...

The original code tried to add deployment target support by finding
an account in one of the targets, and then using all the same code
as account stack set instances. This is deficient:

- If none of the targets contain an account the code fails, due to
  the resource Id not having an accountID value.
- It does not expose information like account IDs and stack set IDs
  for any accounts in the deployment targets, except the arbitrary
  accoun it used.
- It can cause the resource Id to needlessly drift due to the
  account selection process changing (account moved OU's, or the
  API decided to return things in a different order, etc).

This refactor treats deployment targets as their own branch of the
logic, with their own new attributes.
@github-actions github-actions bot added service/cloudformation Issues and PRs that pertain to the cloudformation service. needs-triage Waiting for first response or review from a maintainer. size/M Managed by automation to categorize the size of a PR. labels May 3, 2022
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @sbutler 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels May 5, 2022
@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 May 6, 2022
@jjasiek191
Copy link

Any chance to resolve this issue? It has been open almost year ago

@rkno82
Copy link
Contributor

rkno82 commented Apr 26, 2023

Who can merge that fix?

sbutler and others added 6 commits May 1, 2023 14:12
…yments

- persist list of organizational unit ids in the resource identifier, allowing
for consistent read operations and better import support
- force a new resource when deployment_targets change to ensure changes to stack
sets across multiple organizational units are handled correctly
- track full list of account IDs and stack IDs deployed when stack set instances
are created for an organizational unit
- prevent failures when deploying to an empty organizational unit
… deployments

- add CheckExists and CheckDestroy handlers tailored to handle resources
where organizational unit ids are stored in the ID
- add test deploying to an empty organizational unit
@github-actions github-actions bot added documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Jul 19, 2023
@jar-b jar-b changed the title [WIP] b/aws_cloudformation_stack_set_instance: Empty OU refactor r/aws_cloudformation_stack_set_instance: Empty OU refactor Jul 19, 2023
@jar-b jar-b self-assigned this Jul 19, 2023
Copy link
Member

@jar-b jar-b left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

$ make testacc PKG=cloudformation TESTS=TestAccCloudFormationStackSetInstance_
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudformation/... -v -count 1 -parallel 20 -run='TestAccCloudFormationStackSetInstance_'  -timeout 180m

=== NAME  TestAccCloudFormationStackSetInstance_operationPreferences
    acctest.go:951: this AWS account must be the management account of an AWS Organization
--- SKIP: TestAccCloudFormationStackSetInstance_operationPreferences (0.58s)
=== NAME  TestAccCloudFormationStackSetInstance_DeploymentTargets_emptyOU
    acctest.go:951: this AWS account must be the management account of an AWS Organization
--- SKIP: TestAccCloudFormationStackSetInstance_DeploymentTargets_emptyOU (0.58s)
=== NAME  TestAccCloudFormationStackSetInstance_deploymentTargets
    acctest.go:951: this AWS account must be the management account of an AWS Organization
--- SKIP: TestAccCloudFormationStackSetInstance_deploymentTargets (0.58s)
--- PASS: TestAccCloudFormationStackSetInstance_disappears (66.63s)
--- PASS: TestAccCloudFormationStackSetInstance_Disappears_stackSet (68.75s)
--- PASS: TestAccCloudFormationStackSetInstance_basic (72.35s)
--- PASS: TestAccCloudFormationStackSetInstance_retainStack (132.25s)
--- PASS: TestAccCloudFormationStackSetInstance_parameterOverrides (134.60s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/cloudformation     137.843s

From an organizations management account:

$ make testacc PKG=cloudformation TESTS="TestAccCloudFormationStackSetInstance_DeploymentTargets_emptyOU|TestAccCloudFormationStackSetInstance_deploymentTargets|TestAccCloudFormationStackSetInstance_operationPreferences"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cloudformation/... -v -count 1 -parallel 20 -run='TestAccCloudFormationStackSetInstance_DeploymentTargets_emptyOU|TestAccCloudFormationStackSetInstance_deploymentTargets|TestAccCloudFormationStackSetInstance_operationPreferences'  -timeout 180m

--- PASS: TestAccCloudFormationStackSetInstance_operationPreferences (57.70s)
--- PASS: TestAccCloudFormationStackSetInstance_deploymentTargets (68.51s)
--- PASS: TestAccCloudFormationStackSetInstance_DeploymentTargets_emptyOU (74.15s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/cloudformation     77.362

@jar-b
Copy link
Member

jar-b commented Jul 20, 2023

Thanks for your contribution, @sbutler! 👏

@jar-b jar-b merged commit e8f5acf into hashicorp:main Jul 20, 2023
@github-actions github-actions bot added this to the v5.9.0 milestone Jul 20, 2023
@github-actions
Copy link

This functionality has been released in v5.9.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 Aug 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. documentation Introduces or discusses updates to documentation. service/cloudformation Issues and PRs that pertain to the cloudformation service. size/XL 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.

CloudFormation StackSet fails when no accounts are in target OU
5 participants