Skip to content

Commit 28f56a6

Browse files
committed
fix
1 parent 898e67e commit 28f56a6

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

sdk/terraform/topic/consumer_structures_manual.go

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package topic
22

33
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
48
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/ydb-platform/terraform-provider-ydb/internal/helpers/topic"
510
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
611
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
712
)
@@ -11,28 +16,28 @@ func flattenYDBTopicConsumerDescription(d *schema.ResourceData, desc topictypes.
1116
// _ = d.Set("partitions_count", desc.PartitionSettings.MinActivePartitions)
1217
// _ = d.Set("retention_period_ms", desc.RetentionPeriod.Milliseconds())
1318

14-
// supportedCodecs := make([]string, 0, len(desc.SupportedCodecs))
15-
// for _, v := range desc.SupportedCodecs {
16-
// switch v {
17-
// case topictypes.CodecRaw:
18-
// supportedCodecs = append(supportedCodecs, ydbTopicCodecRAW)
19-
// case topictypes.CodecZstd:
20-
// supportedCodecs = append(supportedCodecs, ydbTopicCodecZSTD)
21-
// case topictypes.CodecGzip:
22-
// supportedCodecs = append(supportedCodecs, ydbTopicCodecGZIP)
23-
// }
24-
// }
19+
supportedCodecs := make([]string, 0, len(desc.SupportedCodecs))
20+
for _, v := range desc.SupportedCodecs {
21+
switch v {
22+
case topictypes.CodecRaw:
23+
supportedCodecs = append(supportedCodecs, ydbTopicCodecRAW)
24+
case topictypes.CodecZstd:
25+
supportedCodecs = append(supportedCodecs, ydbTopicCodecZSTD)
26+
case topictypes.CodecGzip:
27+
supportedCodecs = append(supportedCodecs, ydbTopicCodecGZIP)
28+
}
29+
}
2530

2631
// consumers := topic.FlattenConsumersDescription(desc.Consumers)
2732
// err := d.Set("consumer", consumers)
2833
// if err != nil {
2934
// return fmt.Errorf("failed to set consumer %+v: %w", consumers, err)
3035
// }
3136

32-
// err := d.Set("supported_codecs", supportedCodecs)
33-
// if err != nil {
34-
// return err
35-
// }
37+
err := d.Set("supported_codecs", supportedCodecs)
38+
if err != nil {
39+
return err
40+
}
3641

3742
return d.Set("database_endpoint", d.Get("database_endpoint").(string))
3843
}
@@ -45,22 +50,22 @@ func prepareYDBTopicConsumerAlterSettings(
4550
// opts = append(opts, topicoptions.AlterWithPartitionCountLimit(int64(d.Get("partitions_count").(int))))
4651
// opts = append(opts, topicoptions.AlterWithMinActivePartitions(int64(d.Get("partitions_count").(int))))
4752
// }
48-
// if d.HasChange("supported_codecs") {
49-
// codecs := d.Get("supported_codecs").([]interface{})
50-
// updatedCodecs := make([]topictypes.Codec, 0, len(codecs))
53+
if d.HasChange("supported_codecs") {
54+
codecs := d.Get("supported_codecs").([]interface{})
55+
updatedCodecs := make([]topictypes.Codec, 0, len(codecs))
5156

52-
// for _, c := range codecs {
53-
// cc, ok := topic.YDBTopicCodecNameToCodec[strings.ToLower(c.(string))]
54-
// if !ok {
55-
// panic(fmt.Sprintf("Unsupported codec %q found after validation", cc))
56-
// }
57-
// updatedCodecs = append(updatedCodecs, cc)
58-
// }
59-
// opts = append(opts, topicoptions.AlterWithSupportedCodecs(updatedCodecs...))
60-
// }
61-
// if d.HasChange("retention_period_ms") {
62-
// opts = append(opts, topicoptions.AlterWithRetentionPeriod(time.Duration(d.Get("retention_period_ms").(int))*time.Millisecond))
63-
// }
57+
for _, c := range codecs {
58+
cc, ok := topic.YDBTopicCodecNameToCodec[strings.ToLower(c.(string))]
59+
if !ok {
60+
panic(fmt.Sprintf("Unsupported codec %q found after validation", cc))
61+
}
62+
updatedCodecs = append(updatedCodecs, cc)
63+
}
64+
opts = append(opts, topicoptions.AlterWithSupportedCodecs(updatedCodecs...))
65+
}
66+
if d.HasChange("starting_message_timestamp_ms") {
67+
opts = append(opts, topicoptions.AlterWithRetentionPeriod(time.Duration(d.Get("starting_message_timestamp_ms").(int))*time.Millisecond))
68+
}
6469

6570
// if d.HasChange("consumer") {
6671
// additionalOpts := topic.MergeConsumerSettings(d.Get("consumer").([]interface{}), settings.Consumers)

0 commit comments

Comments
 (0)