@@ -56,53 +56,121 @@ func (r *transformation) Create(ctx context.Context, req resource.CreateRequest,
56
56
return
57
57
}
58
58
59
+ transformationType := data .ProjectType .ValueString ()
59
60
client := r .GetClient ()
60
61
svc := client .NewTransformationCreate ()
61
- svc .ProjectType (data . ProjectType . ValueString () )
62
+ svc .ProjectType (transformationType )
62
63
svc .Paused (data .Paused .ValueBool ())
63
64
64
65
if ! data .Config .IsNull () && ! data .Config .IsUnknown () {
65
66
config := fivetran .NewTransformationConfig ()
66
67
configAttributes := data .Config .Attributes ()
68
+ /* DBT_CORE */
67
69
if ! configAttributes ["project_id" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["project_id" ].(basetypes.StringValue ).IsUnknown () {
68
- config .ProjectId (configAttributes ["project_id" ].(basetypes.StringValue ).ValueString ())
70
+ if transformationType != "DBT_CORE" {
71
+ resp .Diagnostics .AddError (
72
+ "Unable to Create Transformation Resource." ,
73
+ fmt .Sprintf ("The parameter `%v` can be set only for DBT_CORE type transformation" , "project_id" ),
74
+ )
75
+ return
76
+ }
77
+
78
+ config .ProjectId (configAttributes ["project_id" ].(basetypes.StringValue ).ValueString ())
69
79
}
80
+
70
81
if ! configAttributes ["name" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["name" ].(basetypes.StringValue ).IsUnknown () {
82
+ if transformationType != "DBT_CORE" {
83
+ resp .Diagnostics .AddError (
84
+ "Unable to Create Transformation Resource." ,
85
+ fmt .Sprintf ("The parameter `%v` can be set only for DBT_CORE type transformation" , "name" ),
86
+ )
87
+ return
88
+ }
89
+
71
90
config .Name (configAttributes ["name" ].(basetypes.StringValue ).ValueString ())
91
+ }
92
+
93
+ if ! configAttributes ["steps" ].IsUnknown () && ! configAttributes ["steps" ].IsNull () {
94
+ if transformationType != "DBT_CORE" {
95
+ resp .Diagnostics .AddError (
96
+ "Unable to Create Transformation Resource." ,
97
+ fmt .Sprintf ("The parameter `%v` can be set only for DBT_CORE type transformation" , "steps" ),
98
+ )
99
+ return
100
+ }
101
+
102
+ evars := []transformations.TransformationStep {}
103
+
104
+ for _ , ev := range configAttributes ["steps" ].(basetypes.ListValue ).Elements () {
105
+ if element , ok := ev .(basetypes.ObjectValue ); ok {
106
+ step := transformations.TransformationStep {}
107
+ step .Name = element .Attributes ()["name" ].(basetypes.StringValue ).ValueString ()
108
+ step .Command = element .Attributes ()["command" ].(basetypes.StringValue ).ValueString ()
109
+ evars = append (evars , step )
110
+ }
111
+ }
112
+
113
+ config .Steps (evars )
72
114
}
115
+
116
+ /* QUICKSTART */
117
+ packageName := ""
73
118
if ! configAttributes ["package_name" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["package_name" ].(basetypes.StringValue ).IsUnknown () {
74
- config .PackageName (configAttributes ["package_name" ].(basetypes.StringValue ).ValueString ())
119
+ if transformationType != "QUICKSTART" {
120
+ resp .Diagnostics .AddError (
121
+ "Unable to Create Transformation Resource." ,
122
+ fmt .Sprintf ("The parameter `%v` can be set only for QUICKSTART type transformation" , "package_name" ),
123
+ )
124
+ return
125
+ }
126
+
127
+ packageName = configAttributes ["package_name" ].(basetypes.StringValue ).ValueString ()
128
+
129
+ config .PackageName (packageName )
75
130
}
76
131
132
+ connectionIds := []string {}
77
133
if ! configAttributes ["connection_ids" ].IsUnknown () && ! configAttributes ["connection_ids" ].IsNull () {
78
- evars := []string {}
134
+ if transformationType != "QUICKSTART" {
135
+ resp .Diagnostics .AddError (
136
+ "Unable to Create Transformation Resource." ,
137
+ fmt .Sprintf ("The parameter `%v` can be set only for QUICKSTART type transformation" , "connection_ids" ),
138
+ )
139
+ return
140
+ }
141
+
79
142
for _ , ev := range configAttributes ["connection_ids" ].(basetypes.SetValue ).Elements () {
80
- evars = append (evars , ev .(basetypes.StringValue ).ValueString ())
143
+ connectionIds = append (connectionIds , ev .(basetypes.StringValue ).ValueString ())
81
144
}
82
- config .ConnectionIds (evars )
145
+
146
+
147
+ config .ConnectionIds (connectionIds )
148
+ }
149
+
150
+ if len (connectionIds ) == 0 && packageName == "" && transformationType == "QUICKSTART" {
151
+ resp .Diagnostics .AddError (
152
+ "Unable to Create Transformation Resource." ,
153
+ fmt .Sprintf ("For a QUICKSTART type transformation, at least one of the `%v` or `%v` parameters must be set." , "package_name" , "connection_ids" ),
154
+ )
155
+ return
83
156
}
84
157
85
158
if ! configAttributes ["excluded_models" ].IsUnknown () && ! configAttributes ["excluded_models" ].IsNull () {
159
+ if transformationType != "QUICKSTART" {
160
+ resp .Diagnostics .AddError (
161
+ "Unable to Create Transformation Resource." ,
162
+ fmt .Sprintf ("The parameter `%v` can be set only for QUICKSTART type transformation" , "excluded_models" ),
163
+ )
164
+ return
165
+ }
166
+
86
167
evars := []string {}
87
168
for _ , ev := range configAttributes ["excluded_models" ].(basetypes.SetValue ).Elements () {
88
169
evars = append (evars , ev .(basetypes.StringValue ).ValueString ())
89
170
}
90
171
config .ExcludedModels (evars )
91
172
}
92
173
93
- if ! configAttributes ["steps" ].IsUnknown () && ! configAttributes ["steps" ].IsNull () {
94
- evars := []transformations.TransformationStep {}
95
- for _ , ev := range configAttributes ["steps" ].(basetypes.ListValue ).Elements () {
96
- if element , ok := ev .(basetypes.ObjectValue ); ok {
97
- step := transformations.TransformationStep {}
98
- step .Name = element .Attributes ()["name" ].(basetypes.StringValue ).ValueString ()
99
- step .Command = element .Attributes ()["command" ].(basetypes.StringValue ).ValueString ()
100
- evars = append (evars , step )
101
- }
102
- }
103
- config .Steps (evars )
104
- }
105
-
106
174
svc .TransformationConfig (config )
107
175
}
108
176
@@ -237,33 +305,28 @@ func (r *transformation) Update(ctx context.Context, req resource.UpdateRequest,
237
305
if ! plan .Config .IsNull () && ! plan .Config .IsUnknown () {
238
306
config := fivetran .NewTransformationConfig ()
239
307
configAttributes := plan .Config .Attributes ()
240
- if ! configAttributes ["project_id" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["project_id" ].(basetypes.StringValue ).IsUnknown () {
241
- config .ProjectId (configAttributes ["project_id" ].(basetypes.StringValue ).ValueString ())
242
- }
243
- if ! configAttributes ["name" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["name" ].(basetypes.StringValue ).IsUnknown () {
244
- config .Name (configAttributes ["name" ].(basetypes.StringValue ).ValueString ())
245
- }
246
- if ! configAttributes ["package_name" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["package_name" ].(basetypes.StringValue ).IsUnknown () {
247
- config .PackageName (configAttributes ["package_name" ].(basetypes.StringValue ).ValueString ())
248
- }
249
308
250
- if ! configAttributes ["connection_ids" ].IsUnknown () && ! configAttributes ["connection_ids" ].IsNull () {
251
- evars := []string {}
252
- for _ , ev := range configAttributes ["connection_ids" ].(basetypes.SetValue ).Elements () {
253
- evars = append (evars , ev .(basetypes.StringValue ).ValueString ())
309
+ if ! configAttributes ["name" ].(basetypes.StringValue ).IsNull () && ! configAttributes ["name" ].(basetypes.StringValue ).IsUnknown () {
310
+ if state .ProjectType .ValueString () != "DBT_CORE" {
311
+ resp .Diagnostics .AddError (
312
+ "Unable to Create Transformation Resource." ,
313
+ fmt .Sprintf ("The parameter `%v` can be set only for DBT_CORE type transformation" , "name" ),
314
+ )
315
+ return
254
316
}
255
- config .ConnectionIds (evars )
256
- }
257
317
258
- if ! configAttributes ["excluded_models" ].IsUnknown () && ! configAttributes ["excluded_models" ].IsNull () {
259
- evars := []string {}
260
- for _ , ev := range configAttributes ["excluded_models" ].(basetypes.SetValue ).Elements () {
261
- evars = append (evars , ev .(basetypes.StringValue ).ValueString ())
262
- }
263
- config .ExcludedModels (evars )
318
+ config .Name (configAttributes ["name" ].(basetypes.StringValue ).ValueString ())
264
319
}
265
320
266
321
if ! configAttributes ["steps" ].IsUnknown () && ! configAttributes ["steps" ].IsNull () {
322
+ if state .ProjectType .ValueString () != "DBT_CORE" {
323
+ resp .Diagnostics .AddError (
324
+ "Unable to Create Transformation Resource." ,
325
+ fmt .Sprintf ("The parameter `%v` can be set only for DBT_CORE type transformation" , "steps" ),
326
+ )
327
+ return
328
+ }
329
+
267
330
evars := []transformations.TransformationStep {}
268
331
for _ , ev := range configAttributes ["steps" ].(basetypes.ListValue ).Elements () {
269
332
if element , ok := ev .(basetypes.ObjectValue ); ok {
@@ -276,6 +339,22 @@ func (r *transformation) Update(ctx context.Context, req resource.UpdateRequest,
276
339
config .Steps (evars )
277
340
}
278
341
342
+ if ! configAttributes ["excluded_models" ].IsUnknown () && ! configAttributes ["excluded_models" ].IsNull () {
343
+ if state .ProjectType .ValueString () != "QUICKSTART" {
344
+ resp .Diagnostics .AddError (
345
+ "Unable to Create Transformation Resource." ,
346
+ fmt .Sprintf ("The parameter `%v` can be set only for QUICKSTART type transformation" , "excluded_models" ),
347
+ )
348
+ return
349
+ }
350
+
351
+ evars := []string {}
352
+ for _ , ev := range configAttributes ["excluded_models" ].(basetypes.SetValue ).Elements () {
353
+ evars = append (evars , ev .(basetypes.StringValue ).ValueString ())
354
+ }
355
+ config .ExcludedModels (evars )
356
+ }
357
+
279
358
svc .TransformationConfig (config )
280
359
}
281
360
0 commit comments