Skip to content

Commit

Permalink
resource account: allow setting NoStackInheritance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dschofie committed Jul 1, 2024
1 parent 8758861 commit 7885313
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion resource/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Account struct {
Tags []string `yaml:"Tags,omitempty"`
AWSTags []string `yaml:"-"`
BaselineStacks []Stack `yaml:"Stacks,omitempty"`
NoStackInheritance bool `yaml:"NoStackInheritance,omitempty"`
ServiceControlPolicies []Stack `yaml:"ServiceControlPolicies,omitempty"`
ManagementAccount bool `yaml:"-"`

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

func (a Account) AllBaselineStacks() ([]Stack, error) {
var stacks []Stack
if a.Parent != nil {
if a.Parent != nil && !a.NoStackInheritance {
stacks = append(stacks, a.Parent.AllBaselineStacks()...)
}

Expand Down
24 changes: 24 additions & 0 deletions resource/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ var (
AccountName: "Example2",
AccountID: "2",
},
{
Email: "[email protected]",
AccountName: "mgmt-account",
AccountID: "3",
NoStackInheritance: true,
BaselineStacks: []resource.Stack{
{
Name: "mgmt-stack",
Type: "Terraform",
Path: "tf/mgmt",
},
},
},
},
ChildOUs: []*resource.OrganizationUnit{
{
Expand Down Expand Up @@ -163,6 +176,17 @@ func TestAllBaselineStacks(t *testing.T) {
},
},
},
{
rootOU: rootOU,
targetAccountEmail: "[email protected]",
wantStacks: []resource.Stack{
{
Name: "mgmt-stack",
Type: "Terraform",
Path: "tf/mgmt",
},
},
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 7885313

Please sign in to comment.