diff --git a/rules/msk_app_topics.go b/rules/msk_app_topics.go index 583f495..19601c9 100644 --- a/rules/msk_app_topics.go +++ b/rules/msk_app_topics.go @@ -153,6 +153,22 @@ func (r *MSKAppTopicsRule) reportExternalTopics( return fmt.Errorf("evaluating topic names: %w", diags) } for _, v := range val.AsValueSlice() { + if v.Type() != cty.String { + err := runner.EmitIssue( + r, + fmt.Sprintf( + "value for '%s' must be a string, not: %s", + attrName, + v.Type().FriendlyName(), + ), + topicAttr.Range, + ) + if err != nil { + return fmt.Errorf("emitting issue: %w", err) + } + continue + } + name := v.AsString() if _, ok := moduleTopicNames[name]; !ok { err := runner.EmitIssue( diff --git a/rules/msk_app_topics_test.go b/rules/msk_app_topics_test.go index e20c2f6..66c232f 100644 --- a/rules/msk_app_topics_test.go +++ b/rules/msk_app_topics_test.go @@ -89,6 +89,31 @@ module "consumer" { }, }, }, + { + name: "topic name is not string", + files: map[string]string{ + "file.tf": ` +resource "kafka_topic" "my_topic" { + name = "my_topic" +} + +module "consumer" { + consume_topics = [kafka_topic.my_topic] +} +`, + }, + expected: []*helper.Issue{ + { + Rule: rule, + Message: "value for 'consume_topics' must be a string, not: object", + Range: hcl.Range{ + Filename: "file.tf", + Start: hcl.Pos{Line: 7, Column: 2}, + End: hcl.Pos{Line: 7, Column: 41}, + }, + }, + }, + }, { name: "external topic defined outside of consumer/producer", files: map[string]string{