Skip to content

Commit 2717ec4

Browse files
committed
resource account: allow setting NoStackInheritance
You can now set NoStackInheritance: true for an account. This will make it so that a stack doesn't inherit from the current OU or parent OUs. The most useful case for this is when you have the management account at the top level and want to declare top level stacks as well to target all sub accounts except the management account.
1 parent 8758861 commit 2717ec4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

resource/account.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Account struct {
1919
Tags []string `yaml:"Tags,omitempty"`
2020
AWSTags []string `yaml:"-"`
2121
BaselineStacks []Stack `yaml:"Stacks,omitempty"`
22+
NoStackInheritance bool `yaml:"NoStackInheritance,omitempty"`
2223
ServiceControlPolicies []Stack `yaml:"ServiceControlPolicies,omitempty"`
2324
ManagementAccount bool `yaml:"-"`
2425

@@ -109,7 +110,7 @@ func (a Account) CurrentTags() []string {
109110

110111
func (a Account) AllBaselineStacks() ([]Stack, error) {
111112
var stacks []Stack
112-
if a.Parent != nil {
113+
if a.Parent != nil && !a.NoStackInheritance {
113114
stacks = append(stacks, a.Parent.AllBaselineStacks()...)
114115
}
115116

resource/account_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ var (
4040
AccountName: "Example2",
4141
AccountID: "2",
4242
},
43+
{
44+
45+
AccountName: "mgmt-account",
46+
AccountID: "3",
47+
NoStackInheritance: true,
48+
BaselineStacks: []resource.Stack{
49+
{
50+
Name: "mgmt-stack",
51+
Type: "Terraform",
52+
Path: "tf/mgmt",
53+
},
54+
},
55+
},
4356
},
4457
ChildOUs: []*resource.OrganizationUnit{
4558
{
@@ -163,6 +176,17 @@ func TestAllBaselineStacks(t *testing.T) {
163176
},
164177
},
165178
},
179+
{
180+
rootOU: rootOU,
181+
targetAccountEmail: "[email protected]",
182+
wantStacks: []resource.Stack{
183+
{
184+
Name: "mgmt-stack",
185+
Type: "Terraform",
186+
Path: "tf/mgmt",
187+
},
188+
},
189+
},
166190
}
167191

168192
for _, tc := range tests {

0 commit comments

Comments
 (0)