diff --git a/cli/terraform.go b/cli/terraform.go index 16e5163..1fa2414 100644 --- a/cli/terraform.go +++ b/cli/terraform.go @@ -17,13 +17,14 @@ func parsePolicy(resource assertion.Resource, attribute string) assertion.Resour if resource.Properties != nil { properties := resource.Properties.(map[string]interface{}) if policyAttribute, hasPolicyString := properties[attribute]; hasPolicyString { - policyString := policyAttribute.(string) - var policy interface{} - err := json.Unmarshal([]byte(policyString), &policy) - if err != nil { - panic(err) + if policyString, ok := policyAttribute.(string); ok { + var policy interface{} + err := json.Unmarshal([]byte(policyString), &policy) + if err != nil { + panic(err) + } + properties[attribute] = policy } - properties[attribute] = policy } } return resource diff --git a/example-files/config/roles.tf b/example-files/config/roles.tf index e24c0b5..647e8b9 100644 --- a/example-files/config/roles.tf +++ b/example-files/config/roles.tf @@ -16,3 +16,8 @@ resource "aws_iam_role" "test_role" { } EOF } + +resource "aws_iam_role" "test_role_with_invalid_policy" { + name = "role1" + assume_role_policy = [ "foo" ] +}