1
1
package topic
2
2
3
3
import (
4
+ "fmt"
5
+ "strings"
6
+ "time"
7
+
4
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9
+ "github.com/ydb-platform/terraform-provider-ydb/internal/helpers/topic"
5
10
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
6
11
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topictypes"
7
12
)
@@ -11,28 +16,28 @@ func flattenYDBTopicConsumerDescription(d *schema.ResourceData, desc topictypes.
11
16
// _ = d.Set("partitions_count", desc.PartitionSettings.MinActivePartitions)
12
17
// _ = d.Set("retention_period_ms", desc.RetentionPeriod.Milliseconds())
13
18
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
+ }
25
30
26
31
// consumers := topic.FlattenConsumersDescription(desc.Consumers)
27
32
// err := d.Set("consumer", consumers)
28
33
// if err != nil {
29
34
// return fmt.Errorf("failed to set consumer %+v: %w", consumers, err)
30
35
// }
31
36
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
+ }
36
41
37
42
return d .Set ("database_endpoint" , d .Get ("database_endpoint" ).(string ))
38
43
}
@@ -45,22 +50,22 @@ func prepareYDBTopicConsumerAlterSettings(
45
50
// opts = append(opts, topicoptions.AlterWithPartitionCountLimit(int64(d.Get("partitions_count").(int))))
46
51
// opts = append(opts, topicoptions.AlterWithMinActivePartitions(int64(d.Get("partitions_count").(int))))
47
52
// }
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 ))
51
56
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
+ }
64
69
65
70
// if d.HasChange("consumer") {
66
71
// additionalOpts := topic.MergeConsumerSettings(d.Get("consumer").([]interface{}), settings.Consumers)
0 commit comments