Skip to content

Commit 0763711

Browse files
committed
feat: adding the feature to deploy via accounts
1 parent 7b569ec commit 0763711

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ This module provides a simple way to deploy a CloudFormation stack to multiple a
2929
| <a name="input_name"></a> [name](#input\_name) | The name of the cloudformation stack | `string` | n/a | yes |
3030
| <a name="input_tags"></a> [tags](#input\_tags) | The tags to apply to the cloudformation stack | `map(string)` | n/a | yes |
3131
| <a name="input_template"></a> [template](#input\_template) | The body of the cloudformation template to deploy | `string` | n/a | yes |
32-
| <a name="input_accounts"></a> [accounts](#input\_accounts) | A list of account IDs used as a target | `list(string)` | `null` | no |
32+
| <a name="input_accounts"></a> [accounts](#input\_accounts) | When using an account deployments, the following accounts will be included | `list(string)` | `null` | no |
3333
| <a name="input_call_as"></a> [call\_as](#input\_call\_as) | Specifies whether you are acting as an account administrator in the organization's management account or as a delegated administrator in a member account | `string` | `"SELF"` | no |
3434
| <a name="input_capabilities"></a> [capabilities](#input\_capabilities) | The capabilities required to deploy the cloudformation template | `list(string)` | <pre>[<br/> "CAPABILITY_NAMED_IAM",<br/> "CAPABILITY_AUTO_EXPAND",<br/> "CAPABILITY_IAM"<br/>]</pre> | no |
35-
| <a name="input_enable_exclude"></a> [enable\_exclude](#input\_enable\_exclude) | Indicates the accounts list will be used as an exclusion list | `bool` | `false` | no |
3635
| <a name="input_enabled_regions"></a> [enabled\_regions](#input\_enabled\_regions) | The regions to deploy the cloudformation stack to (if empty, deploys to current region) | `list(string)` | `null` | no |
36+
| <a name="input_exclude_accounts"></a> [exclude\_accounts](#input\_exclude\_accounts) | When using an organizational deployments, the following accounts will be excluded | `list(string)` | `null` | no |
3737
| <a name="input_failure_tolerance_count"></a> [failure\_tolerance\_count](#input\_failure\_tolerance\_count) | The number of failures that are tolerated before the stack operation is stopped | `number` | `0` | no |
3838
| <a name="input_max_concurrent_count"></a> [max\_concurrent\_count](#input\_max\_concurrent\_count) | The maximum number of concurrent deployments | `number` | `10` | no |
3939
| <a name="input_organizational_units"></a> [organizational\_units](#input\_organizational\_units) | The organizational units to deploy the stackset to | `list(string)` | `[]` | no |

locals.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ locals {
1616
]
1717
])
1818

19-
deployments = { for x in local.organization_unit_deployments : x.key => x }
19+
organizational_deployments = { for x in local.organization_unit_deployments : x.key => x }
2020
}
2121

main.tf

+20-3
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,36 @@ resource "aws_cloudformation_stack_set" "stackset" {
3333

3434
## Deploy the stackset to the following organizational units
3535
resource "aws_cloudformation_stack_set_instance" "ou" {
36-
for_each = local.deployments
36+
for_each = local.organizational_deployments
3737

3838
call_as = var.call_as
3939
region = each.value.region
4040
stack_set_name = aws_cloudformation_stack_set.stackset.name
4141

4242
deployment_targets {
43-
accounts = var.accounts
44-
account_filter_type = var.accounts != null && var.enable_exclude ? "DIFFERENCE" : null
43+
accounts = var.exclude_accounts
44+
account_filter_type = var.exclude_accounts != null ? "DIFFERENCE" : null
4545
organizational_unit_ids = [each.value.organization_unit]
4646
}
4747

4848
depends_on = [
4949
aws_cloudformation_stack_set.stackset,
5050
]
5151
}
52+
53+
## Deploy the stackset to the following accounts
54+
resource "aws_cloudformation_stack_set_instance" "accounts" {
55+
for_each = var.accounts != null ? toset(var.accounts) : toset([])
56+
57+
call_as = var.call_as
58+
region = each.value.region
59+
stack_set_name = aws_cloudformation_stack_set.stackset.name
60+
61+
deployment_targets {
62+
accounts = var.accounts
63+
}
64+
65+
depends_on = [
66+
aws_cloudformation_stack_set.stackset,
67+
]
68+
}

tests/module.tftest.hcl

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ run "exclude_accounts" {
3333
tags = {}
3434
template = ""
3535
parameters = {}
36-
accounts = [
36+
exclude_accounts = [
3737
"123456789012",
3838
"123456789013"
3939
]
40-
enable_exclude = true
4140
}
4241
}
4342

variables.tf

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ variable "enabled_regions" {
2828
}
2929

3030
variable "accounts" {
31-
description = "A list of account IDs used as a target"
31+
description = "When using an account deployments, the following accounts will be included"
3232
type = list(string)
3333
default = null
3434
}
3535

36-
variable "enable_exclude" {
37-
description = "Indicates the accounts list will be used as an exclusion list"
38-
type = bool
39-
default = false
36+
variable "exclude_accounts" {
37+
description = "When using an organizational deployments, the following accounts will be excluded"
38+
type = list(string)
39+
default = null
4040
}
4141

4242
variable "description" {

0 commit comments

Comments
 (0)