Skip to content

Commit 854609c

Browse files
committed
Fix CloudFormation StackSet creation when deployed to the management account
1 parent e584933 commit 854609c

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

main.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
locals {
22
# Internal
3-
account_id = data.aws_caller_identity.current.account_id
4-
organization_id = data.aws_organizations_organization.org.id
5-
partition_id = data.aws_partition.current.partition
6-
region = data.aws_region.current.region
7-
deployment_regions = [local.region]
3+
account_id = data.aws_caller_identity.current.account_id
4+
organization_id = data.aws_organizations_organization.org.id
5+
organization_management_account_id = data.aws_organizations_organization.org.master_account_id
6+
partition_id = data.aws_partition.current.partition
7+
region = data.aws_region.current.region
8+
deployment_regions = [local.region]
89

910
# Member account deployment role names are templated here but used throughout this module and submodules.
1011
member_account_deployment_helper_role_name_template = "${var.member_account_resource_name_prefix}<SERVICE>-deployment-helper-<REGION>"
@@ -40,10 +41,11 @@ module "deployment" {
4041
retained_vaults = each.value.retained_vaults
4142

4243
current = {
43-
account_id = local.account_id
44-
organization_id = local.organization_id
45-
partition = local.partition_id
46-
region = local.region
44+
account_id = local.account_id
45+
organization_id = local.organization_id
46+
organization_management_account_id = local.organization_management_account_id
47+
partition = local.partition_id
48+
region = local.region
4749
}
4850
central_account_resource_name_prefix = var.central_account_resource_name_prefix
4951
central_backup_service_linked_role_arn = local.backup_service_linked_role_arn

modules/service-deployment/cloudformation.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ resource "aws_cloudformation_stack_set" "member_account_deployments" {
1212
description = "Centralised AWS Backup for ${var.service_name}."
1313
capabilities = ["CAPABILITY_NAMED_IAM"]
1414
permission_model = "SERVICE_MANAGED"
15-
call_as = "DELEGATED_ADMIN"
15+
call_as = var.current.organization_management_account_id == var.current.account_id ? "SELF" : "DELEGATED_ADMIN"
1616

1717
# Try to do as much as possible in native CloudFormation, but some things, like dynamic lists, are only possible in Terraform.
1818
# jsonencode(jsondecode(...)) used to minify the file.
@@ -60,7 +60,7 @@ resource "aws_cloudformation_stack_set" "member_account_deployments" {
6060

6161
resource "aws_cloudformation_stack_instances" "member_account_deployments" {
6262
stack_set_name = aws_cloudformation_stack_set.member_account_deployments.name
63-
call_as = "DELEGATED_ADMIN"
63+
call_as = var.current.organization_management_account_id == var.current.account_id ? "SELF" : "DELEGATED_ADMIN"
6464
regions = var.deployment_regions
6565
deployment_targets {
6666
organizational_unit_ids = var.deployment_targets

modules/service-deployment/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ variable "current" {
4949
type = object({
5050
account_id : string
5151
organization_id : string
52+
organization_management_account_id : string
5253
partition : string
5354
region : string
5455
})

0 commit comments

Comments
 (0)