Skip to content

Commit

Permalink
Merge pull request #76 from ekristen/fix-config-nil-pointer
Browse files Browse the repository at this point in the history
fix(config): check if filters is nil before resolving deprecations
  • Loading branch information
ekristen authored Sep 26, 2024
2 parents c0b844c + b6664a0 commit f564f34
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ func (c *Config) Filters(accountID string) (filter.Filters, error) {
// new resource type.
func (c *Config) ResolveDeprecations() error {
for _, a := range c.Accounts {
// Note: if there are no filters defined, then there's no substitution to perform.
if a.Filters == nil {
return nil
}

for resourceType, resources := range a.Filters {
replacement, ok := c.Deprecations[resourceType]
if !ok {
Expand Down
14 changes: 14 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ func TestResourceTypeDeprecations(t *testing.T) {
assert.NoError(t, err)
}

func TestResourceTypeDeprecationsNoFilters(t *testing.T) {
opts := Options{
Path: "testdata/deprecated-resources-no-filters.yaml",
Deprecations: map[string]string{"IamRole": "IAMRole"},
NoResolveDeprecations: true,
}
c, err := New(opts)
assert.NoError(t, err)
assert.NotNil(t, c)

err = c.ResolveDeprecations()
assert.NoError(t, err)
}

func TestResourceTypeDeprecationsError(t *testing.T) {
logrus.AddHook(&TestGlobalHook{
t: t,
Expand Down
25 changes: 25 additions & 0 deletions pkg/config/testdata/deprecated-resources-no-filters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
regions:
- us-east-1

blocklist:
- 1234567890

resource-types:
includes:
- IAMRole

accounts:
555133742:
presets:
- "terraform"
resource-types:
includes:
- S3Bucket

presets:
terraform:
filters:
S3Bucket:
- type: glob
value: "my-statebucket-*"

0 comments on commit f564f34

Please sign in to comment.