@@ -20,10 +20,8 @@ package cluster
20
20
import (
21
21
"context"
22
22
"fmt"
23
- "time"
24
23
25
24
controlplanev1beta2 "buf.build/gen/go/redpandadata/cloud/protocolbuffers/go/redpanda/api/controlplane/v1beta2"
26
- "github.com/hashicorp/terraform-plugin-framework/attr"
27
25
"github.com/hashicorp/terraform-plugin-framework/datasource"
28
26
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
29
27
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -86,135 +84,21 @@ func (d *DataSourceCluster) Read(ctx context.Context, req datasource.ReadRequest
86
84
}
87
85
88
86
// Convert cloud provider tags to Terraform map
89
- tags := make (map [string ]attr.Value )
90
- for k , v := range cluster .CloudProviderTags {
91
- tags [k ] = types .StringValue (v )
92
- }
93
- tagsValue , diags := types .MapValue (types .StringType , tags )
94
- if diags .HasError () {
95
- resp .Diagnostics .AddError ("unable to parse Cloud tags" , utils .DeserializeGrpcError (err ))
96
- return
97
- }
98
-
99
- // Create persistence model
100
- persist := & models.Cluster {
101
- Name : types .StringValue (cluster .Name ),
102
- ConnectionType : types .StringValue (utils .ConnectionTypeToString (cluster .ConnectionType )),
103
- CloudProvider : types .StringValue (utils .CloudProviderToString (cluster .CloudProvider )),
104
- ClusterType : types .StringValue (utils .ClusterTypeToString (cluster .Type )),
105
- RedpandaVersion : types .StringValue (cluster .RedpandaVersion ),
106
- ThroughputTier : types .StringValue (cluster .ThroughputTier ),
107
- Region : types .StringValue (cluster .Region ),
108
- ResourceGroupID : types .StringValue (cluster .ResourceGroupId ),
109
- NetworkID : types .StringValue (cluster .NetworkId ),
110
- ID : types .StringValue (cluster .Id ),
111
- Tags : tagsValue ,
112
- Zones : utils .StringSliceToTypeList (cluster .Zones ),
113
- ReadReplicaClusterIDs : utils .StringSliceToTypeList (cluster .ReadReplicaClusterIds ),
114
- AllowDeletion : types .BoolValue (true ), // Default to true for data source
115
- State : types .StringValue (cluster .State .String ()),
116
- }
117
-
118
- if cluster .HasCreatedAt () {
119
- persist .CreatedAt = types .StringValue (cluster .CreatedAt .AsTime ().Format (time .RFC3339 ))
120
- }
121
-
122
- if cluster .HasStateDescription () {
123
- stateDescription , dg := generateModelStateDescription (cluster , diags )
124
- if dg .HasError () {
125
- resp .Diagnostics .Append (dg ... )
126
- return
127
- }
128
- persist .StateDescription = stateDescription
129
- }
130
-
131
- if cluster .HasDataplaneApi () {
132
- persist .ClusterAPIURL = types .StringValue (cluster .DataplaneApi .Url )
133
- }
134
-
135
- kafkaAPI , dg := generateModelKafkaAPI (cluster , diags )
136
- if dg .HasError () {
137
- resp .Diagnostics .Append (dg ... )
138
- return
139
- }
140
- persist .KafkaAPI = kafkaAPI
141
-
142
- httpProxy , dg := generateModelHTTPProxy (cluster , diags )
143
- if dg .HasError () {
144
- resp .Diagnostics .Append (dg ... )
145
- return
146
- }
147
- persist .HTTPProxy = httpProxy
148
-
149
- schemaRegistry , dg := generateModelSchemaRegistry (cluster , diags )
150
- if dg .HasError () {
151
- resp .Diagnostics .Append (dg ... )
152
- return
153
- }
154
- persist .SchemaRegistry = schemaRegistry
155
-
156
- console , dg := generateModelRedpandaConsole (cluster , diags )
157
- if dg .HasError () {
158
- resp .Diagnostics .Append (dg ... )
159
- return
160
- }
161
- persist .RedpandaConsole = console
162
-
163
- prometheus , dg := generateModelPrometheus (cluster , diags )
164
- if dg .HasError () {
165
- resp .Diagnostics .Append (dg ... )
166
- return
167
- }
168
- persist .Prometheus = prometheus
169
-
170
- window , dg := generateModelMaintenanceWindow (cluster , diags )
171
- if dg .HasError () {
172
- resp .Diagnostics .Append (dg ... )
173
- return
174
- }
175
- persist .MaintenanceWindowConfig = window
176
-
177
- awsPrivateLink , dg := generateModelAWSPrivateLink (cluster , resp .Diagnostics )
178
- if dg .HasError () {
179
- resp .Diagnostics .Append (dg ... )
180
- return
181
- }
182
- persist .AwsPrivateLink = awsPrivateLink
183
-
184
- gcpPSC , dg := generateModelGCPPrivateServiceConnect (cluster , resp .Diagnostics )
185
- if dg .HasError () {
186
- resp .Diagnostics .Append (dg ... )
187
- return
188
- }
189
- persist .GcpPrivateServiceConnect = gcpPSC
190
-
191
- azurePrivateLink , dg := generateModelAzurePrivateLink (cluster , resp .Diagnostics )
192
- if dg .HasError () {
193
- resp .Diagnostics .Append (dg ... )
194
- return
195
- }
196
- persist .AzurePrivateLink = azurePrivateLink
197
-
198
- connectivity , dg := generateModelConnectivity (cluster , resp .Diagnostics )
199
- if dg .HasError () {
200
- resp .Diagnostics .Append (dg ... )
201
- return
202
- }
203
- persist .Connectivity = connectivity
204
-
205
- kafkaConnect , dg := generateModelKafkaConnect (cluster , resp .Diagnostics )
206
- if dg .HasError () {
207
- resp .Diagnostics .Append (dg ... )
87
+ tags , err := utils .StringMapToTypesMap (cluster .GetCloudProviderTags ())
88
+ if err != nil {
89
+ resp .Diagnostics .AddError ("error converting tags to MapType" , err .Error ())
208
90
return
209
91
}
210
- persist .KafkaConnect = kafkaConnect
211
92
212
- cmr , dg := generateModelCMR (cluster , resp .Diagnostics )
93
+ persist , dg := generateModel (cluster , modelOrAPI {
94
+ RedpandaVersion : types .StringValue (cluster .RedpandaVersion ),
95
+ Tags : tags ,
96
+ }, resp .Diagnostics )
213
97
if dg .HasError () {
98
+ resp .Diagnostics .AddError ("error generating model" , "failed to generate model in cluster datasource read" )
214
99
resp .Diagnostics .Append (dg ... )
215
100
return
216
101
}
217
- persist .CustomerManagedResources = cmr
218
102
219
103
resp .Diagnostics .Append (resp .State .Set (ctx , persist )... )
220
104
}
0 commit comments