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

[Bug]: CloudFormation Stack instances are being executed sequentially when using region_concurrency_type = "PARALLEL" #30806

Open
andrejskuidins opened this issue Apr 19, 2023 · 3 comments
Labels
bug Addresses a defect in current functionality. service/cloudformation Issues and PRs that pertain to the cloudformation service.

Comments

@andrejskuidins
Copy link

Terraform Core Version

1.3.4

AWS Provider Version

4.60.0

Affected Resource(s)

aws_cloudformation_stack_set
aws_cloudformation_stack_set_instance

Expected Behavior

In AWS console CloudFormation Stack instances are being executed in parallel

Actual Behavior

In AWS console CloudFormation Stack instances are being executed sequentially

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

Following code i being applied:

#KMS Key Replicas
resource "aws_cloudformation_stack_set" "kms_replicas" {
  administration_role_arn = aws_iam_role.AWSCloudFormationStackSetAdministrationRole.arn
  execution_role_name     = aws_iam_role.AWSCloudFormationStackSetExecutionRole.name
  name                    = "${var.name}-cf-stack-${var.tags["environment"]}-${data.aws_region.current.name}"
  capabilities            = var.capabilities
  permission_model        = var.permission_model
  operation_preferences {
    region_concurrency_type = "PARALLEL" #observed sequential propogation of stack set instances. Possible solution: new release of aws provider
    max_concurrent_count    = 1
  }
  template_body = templatefile("${path.module}/templates/replica.yml.tpl", {
    alias_name      = aws_kms_alias.kms_alias.name
    primary_key_arn = aws_kms_key.image_key.arn
    accounts        = var.accounts
    account_id      = data.aws_caller_identity.current.account_id
    roles           = var.kms_roles
    id              = aws_kms_key.image_key.id
  })
}

resource "aws_cloudformation_stack_set_instance" "kms_replicas" {
  for_each       = toset(local.replica_regions)
  region         = each.value
  stack_set_name = aws_cloudformation_stack_set.kms_replicas.name
  operation_preferences {
    region_concurrency_type = "PARALLEL" #observed sequential propogation of stack set instances. Possible solution: new release of aws provider
    max_concurrent_count    = 1
  }
  depends_on = [
    time_sleep.iam_propagation
  ]
}

#Since the IAM is a global service, it takes time to replicate its resources across the regions. 
#We need to have some roles for CloudFormation Stack Set
#It waits for 20 sec before creating the cloudformation stack set and stack set instances in order the roles to be available for use. 
#For further reading follow the link https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_eventual-consistency
resource "time_sleep" "iam_propagation" {
  create_duration = "20s"
  depends_on = [
    aws_iam_role.AWSCloudFormationStackSetAdministrationRole,
    aws_iam_role.AWSCloudFormationStackSetExecutionRole,
    aws_iam_role_policy.AWSCloudFormationStackSetExecutionRole_MinimumExecutionPolicy
  ]
}

Steps to Reproduce

terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@andrejskuidins andrejskuidins added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Apr 19, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/cloudformation Issues and PRs that pertain to the cloudformation service. label Apr 19, 2023
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Apr 19, 2023
@aries1980
Copy link
Contributor

aries1980 commented May 4, 2023

I can confirm this is indeed the case with 4.65.0, although I am not convinced this is related to the AWS provider or Terraform itself. I can see the settings in the Terraform plan and turning on the debug log, I can see the settings are sent with the API request.

I have the same experience with failure_tolerance_percentage and max_concurrent_percentage, both are set to a non-zero number but they are both zero after terraform apply.

My snippet:

resource "aws_cloudformation_stack_set" "resource_explorer" {
  name             = "xzy"
  permission_model = "SERVICE_MANAGED"
  call_as          = "DELEGATED_ADMIN"

  auto_deployment {
    enabled                          = true
    retain_stacks_on_account_removal = false
  }

  template_body = file("${path.module}/template.yaml")

  operation_preferences {
    failure_tolerance_percentage = 99
    max_concurrent_percentage    = 50
    region_concurrency_type      = "PARALLEL"
  }
}

@evantlueck
Copy link

evantlueck commented Oct 26, 2023

I did a lot of testing. I posted my findings here: #33170 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Addresses a defect in current functionality. service/cloudformation Issues and PRs that pertain to the cloudformation service.
Projects
None yet
Development

No branches or pull requests

4 participants