Skip to content

Commit e8f358c

Browse files
committed
fix(aws): guard GetIamPolicyDocumentContextE; remove stray rds test print
- iam.go: GetIamPolicyDocumentContextE previously dereferenced version.VersionId without a nil check and fell through with an empty defaultVersion when ListPolicyVersions returned no default, producing a confusing AWS validation error. Now guards the dereference and returns a clear error naming the policy ARN. - rds_test.go: drop a leftover fmt.Println(err) in the error-path subtests; the existing assert.EqualError is sufficient.
1 parent d8f4e29 commit e8f358c

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

modules/aws/iam.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,15 @@ func GetIamPolicyDocumentContextE(t testing.TestingT, ctx context.Context, regio
120120
var defaultVersion string
121121

122122
for _, version := range versions.Versions {
123-
if version.IsDefaultVersion {
123+
if version.IsDefaultVersion && version.VersionId != nil {
124124
defaultVersion = *version.VersionId
125125
}
126126
}
127127

128+
if defaultVersion == "" {
129+
return "", fmt.Errorf("no default version found for IAM policy %s", policyARN)
130+
}
131+
128132
document, err := iamClient.GetPolicyVersion(ctx, &iam.GetPolicyVersionInput{
129133
PolicyArn: aws.String(policyARN),
130134
VersionId: aws.String(defaultVersion),

modules/aws/rds_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package aws_test
22

33
import (
4-
"fmt"
54
"testing"
65

76
aws "github.com/gruntwork-io/terratest/modules/aws"
@@ -146,7 +145,6 @@ func TestGetRecommendedRdsInstanceTypeErrors(t *testing.T) {
146145
t.Parallel()
147146

148147
_, err := aws.GetRecommendedRdsInstanceTypeE(t, scenerio.region, scenerio.databaseEngine, scenerio.databaseEngineVersion, scenerio.instanceTypes)
149-
fmt.Println(err)
150148
assert.EqualError(t, err, aws.NoRdsInstanceTypeError{InstanceTypeOptions: scenerio.instanceTypes, DatabaseEngine: scenerio.databaseEngine, DatabaseEngineVersion: scenerio.databaseEngineVersion}.Error())
151149
})
152150
}

0 commit comments

Comments
 (0)