Skip to content

Commit 6b26334

Browse files
address comments
1 parent b12c3b9 commit 6b26334

File tree

3 files changed

+126
-42
lines changed

3 files changed

+126
-42
lines changed

fivetran/framework/core/schema/transformation.go

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
66
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
77
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
8+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
9+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
10+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
811
)
912

1013
func TransformationResource() resourceSchema.Schema {
@@ -158,6 +161,7 @@ func transformationConfigDatasourceSchema() map[string]datasourceSchema.Attribut
158161
func transformationConfigResourceSchema() map[string]resourceSchema.Attribute {
159162
return map[string]resourceSchema.Attribute{
160163
"project_id": resourceSchema.StringAttribute{
164+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
161165
Optional: true,
162166
Description: "The unique identifier for the dbt Core project within the Fivetran system",
163167
},
@@ -166,10 +170,12 @@ func transformationConfigResourceSchema() map[string]resourceSchema.Attribute {
166170
Description: "The transformation name",
167171
},
168172
"package_name": resourceSchema.StringAttribute{
173+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
169174
Optional: true,
170175
Description: `The Quickstart transformation package name`,
171176
},
172177
"connection_ids": resourceSchema.SetAttribute{
178+
PlanModifiers: []planmodifier.Set{setplanmodifier.RequiresReplace()},
173179
Optional: true,
174180
ElementType: basetypes.StringType{},
175181
Description: "The list of the connection identifiers to be used for the integrated schedule. Also used to identify package_name automatically if package_name was not specified",

fivetran/framework/resources/transformation.go

+119-40
Original file line numberDiff line numberDiff line change
@@ -56,53 +56,121 @@ func (r *transformation) Create(ctx context.Context, req resource.CreateRequest,
5656
return
5757
}
5858

59+
transformationType := data.ProjectType.ValueString()
5960
client := r.GetClient()
6061
svc := client.NewTransformationCreate()
61-
svc.ProjectType(data.ProjectType.ValueString())
62+
svc.ProjectType(transformationType)
6263
svc.Paused(data.Paused.ValueBool())
6364

6465
if !data.Config.IsNull() && !data.Config.IsUnknown() {
6566
config := fivetran.NewTransformationConfig()
6667
configAttributes := data.Config.Attributes()
68+
/* DBT_CORE */
6769
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())
6979
}
80+
7081
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+
7190
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)
72114
}
115+
116+
/* QUICKSTART */
117+
packageName := ""
73118
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)
75130
}
76131

132+
connectionIds := []string{}
77133
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+
79142
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())
81144
}
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
83156
}
84157

85158
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+
86167
evars := []string{}
87168
for _, ev := range configAttributes["excluded_models"].(basetypes.SetValue).Elements() {
88169
evars = append(evars, ev.(basetypes.StringValue).ValueString())
89170
}
90171
config.ExcludedModels(evars)
91172
}
92173

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-
106174
svc.TransformationConfig(config)
107175
}
108176

@@ -237,33 +305,28 @@ func (r *transformation) Update(ctx context.Context, req resource.UpdateRequest,
237305
if !plan.Config.IsNull() && !plan.Config.IsUnknown() {
238306
config := fivetran.NewTransformationConfig()
239307
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-
}
249308

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
254316
}
255-
config.ConnectionIds(evars)
256-
}
257317

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())
264319
}
265320

266321
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+
267330
evars := []transformations.TransformationStep{}
268331
for _, ev := range configAttributes["steps"].(basetypes.ListValue).Elements() {
269332
if element, ok := ev.(basetypes.ObjectValue); ok {
@@ -276,6 +339,22 @@ func (r *transformation) Update(ctx context.Context, req resource.UpdateRequest,
276339
config.Steps(evars)
277340
}
278341

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+
279358
svc.TransformationConfig(config)
280359
}
281360

templates/data-sources/quickstart_packages.md.tmpl

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Returns a list of available Quickstart transformation package metadata details
99
## Example Usage
1010

1111
```hcl
12-
data "fivetran_quickstart_packages" "test" {
13-
id = "id"
12+
data "fivetran_quickstart_packages" "all_packages_metadata" {
1413
}
1514
```
1615

0 commit comments

Comments
 (0)