-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: Adding new ou to the deployment_targets in aws_cloudformation_stack_set_instance fails #33785
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
terraform 1.5.2 Hello! I wasn't able to find a very code-concise solution, but this ended up working well for me. This is assuming your stackset related infrastructure code is inside a module with a variable "target_ous" {
type = list(string)
description = "Where would you like to deploy the stackset?"
}
locals {
deduped_ous = distinct(var.target_ous)
}
data "aws_organizations_organizational_unit_descendant_accounts" "targeted_accounts" {
for_each = { for ou in local.deduped_ous : ou => ou }
parent_id = each.key
}
locals {
ou_descendants_map = { for ou, child_accounts in data.aws_organizations_organizational_unit_descendant_accounts.targeted_accounts : ou => [ for account in child_accounts.accounts : account.id ] }
# Identify OUs whose account list is a subset of any other OU's account list
subset_ous = [for ou_id, accounts in local.ou_descendants_map :
ou_id if length([
for other_ou_id, other_accounts in local.ou_descendants_map :
other_ou_id if (other_ou_id != ou_id && length(setsubtract(accounts, other_accounts)) == 0)
]) > 0
]
# list of OUs which are not a subset of any other OU's account list which should each have their own aws_cloudformation_stack_set_instance resource.
final_ous = setsubtract(local.deduped_ous, local.subset_ous)
}
resource "aws_cloudformation_stack_set_instance" "instance" {
for_each = { for ou in local.final_ous : ou => [ou] }
stack_set_name = aws_cloudformation_stack_set.stackset.name
region = data.aws_region.this.id
retain_stack = false
deployment_targets {
organizational_unit_ids = each.value
}
operation_preferences { # ref: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack_set#operation_preferences-argument-reference
failure_tolerance_percentage = 50
max_concurrent_percentage = 50
region_concurrency_type = "PARALLEL"
}
} From testing, I was able to replicate your issue as well. This solution ensures that every ou is evaluated against each other ou; and The only edge case error I found using this setup is if you have a parent ou and child ou (of that parent) targeted, the stackset has been deployed at least one time prior, and you remove the aforementioned parent ou without removing the child of that parent, then after that apply runs; on your next apply, will encounter an error similar to But this edge case is completely avoidable by making sure to only target parent OUs to begin with. In summary, the code above is expected for use within a module. It takes in a variable called Obviously, the issue with the provider remains. This doesn't fix the underlying logic issues with this bug thread. But it is a workaround to make sure your stackset use still LOGICALLY functions as you would expect. Therefore allowing you to create new OU targets, and remove OU targets, without terraform failing erroneously. |
Warning This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them. Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed. |
This functionality has been released in v5.58.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! |
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. |
Terraform Core Version
1.5.2
AWS Provider Version
5.15.0
Affected Resource(s)
aws_cloudformation_stack_set_instance
Expected Behavior
Modify the OUs that aws_cloudformation_stack_set_instance is applied to
Actual Behavior
No OU edits are possible
Relevant Error/Panic Output Snippet
Terraform Configuration Files
Steps to Reproduce
Debug Output
Panic Output
No response
Important Factoids
No response
References
No response
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: