From c3bfecfbd51d17eb21f3c9864d2bb9c6fa30cc9d Mon Sep 17 00:00:00 2001 From: Samuel Hinton Date: Wed, 15 Jan 2025 01:56:12 +1000 Subject: [PATCH] Allowing capitals in topic regex (#418) Fix regarding support case 00098704 Fixes #419 --- internal/provider/resource_streaming_topic.go | 2 +- .../provider/resource_streaming_topic_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/provider/resource_streaming_topic.go b/internal/provider/resource_streaming_topic.go index f13d9b9..0ed5fdd 100644 --- a/internal/provider/resource_streaming_topic.go +++ b/internal/provider/resource_streaming_topic.go @@ -542,7 +542,7 @@ func (t *StreamingTopicResourceModel) generateStreamingTopicID() string { var ( streamingTopicIDPattern = `^([a-z][a-z0-9-]*):(persistent|non-persistent)://` + - `([a-z][a-z0-9-]*)/([a-z][a-z0-9-]*)/([a-z][a-z0-9-._]*)$` + `([a-z][a-z0-9-]*)/([a-z][a-z0-9-]*)/([a-zA-Z][a-zA-Z0-9-._]*)$` streamingTopicIDRegex = regexp.MustCompile(streamingTopicIDPattern) ) diff --git a/internal/provider/resource_streaming_topic_test.go b/internal/provider/resource_streaming_topic_test.go index df96571..b6eb2ce 100644 --- a/internal/provider/resource_streaming_topic_test.go +++ b/internal/provider/resource_streaming_topic_test.go @@ -93,3 +93,20 @@ func TestParseStreamingTopicID(t *testing.T) { assert.True(t, topic.Partitioned.ValueBool()) assert.Equal(t, "non-persistent://my-tenant/my-namespace/topic1", topic.getTopicFQN()) } + +func TestTopicNameValidation(t *testing.T) { + topicID := "my-cluster:persistent://my-tenant/my-namespace/this.Topic-is_valid123-DLQ" + topic, err := parseStreamingTopicID(topicID) + assert.Nil(t, err) + assert.Equal(t, "this.Topic-is_valid123-DLQ", topic.Topic.ValueString()) + + invalidTopics := []string{ + "my-cluster:persistent://my-tenant/my-namespace/this.Topic-isnt$valid123", + "my-cluster:persistent://my-tenant/my-namespace/1this.Topic-isnt_valid123", + "my-cluster:persistent://my-tenant/my-namespace/this.Topic-isnt_valid123+", + } + for _, topicID := range invalidTopics { + topic, err = parseStreamingTopicID(topicID) + assert.NotNil(t, err) + } +}