@@ -142,10 +142,8 @@ func (m *machineTypeDataSource) Read(ctx context.Context, req datasource.ReadReq
142
142
143
143
listMachineTypeReq := m .client .ListMachineTypes (ctx , projectId )
144
144
145
- if ! model .Filter .IsNull () && ! model .Filter .IsUnknown () {
146
- if filter := strings .TrimSpace (model .Filter .ValueString ()); filter != "" {
147
- listMachineTypeReq = listMachineTypeReq .Filter (filter )
148
- }
145
+ if ! model .Filter .IsNull () && ! model .Filter .IsUnknown () && strings .TrimSpace (model .Filter .ValueString ()) != "" {
146
+ listMachineTypeReq = listMachineTypeReq .Filter (strings .TrimSpace (model .Filter .ValueString ()))
149
147
}
150
148
151
149
apiResp , err := listMachineTypeReq .Execute ()
@@ -160,16 +158,15 @@ func (m *machineTypeDataSource) Read(ctx context.Context, req datasource.ReadReq
160
158
return
161
159
}
162
160
163
- items := apiResp .Items
164
- if items == nil || len (* items ) == 0 {
161
+ if apiResp .Items == nil || len (* apiResp .Items ) == 0 {
165
162
core .LogAndAddWarning (ctx , & resp .Diagnostics , "No machine types found" , "No matching machine types." )
166
163
return
167
164
}
168
165
169
166
// Convert items to []*iaas.MachineType
170
- machineTypes := make ([]* iaas.MachineType , len (* items ))
171
- for i := range * items {
172
- machineTypes [i ] = & (* items )[i ]
167
+ machineTypes := make ([]* iaas.MachineType , len (* apiResp . Items ))
168
+ for i := range * apiResp . Items {
169
+ machineTypes [i ] = & (* apiResp . Items )[i ]
173
170
}
174
171
175
172
sorted , err := sortMachineTypeByName (machineTypes , sortAscending )
@@ -184,11 +181,6 @@ func (m *machineTypeDataSource) Read(ctx context.Context, req datasource.ReadReq
184
181
return
185
182
}
186
183
187
- if err := mapDataSourceFields (ctx , first , & model ); err != nil {
188
- core .LogAndAddError (ctx , & resp .Diagnostics , "Mapping error" , fmt .Sprintf ("Failed to translate API response: %v" , err ))
189
- return
190
- }
191
-
192
184
resp .Diagnostics .Append (resp .State .Set (ctx , model )... )
193
185
tflog .Info (ctx , "Successfully read machine type" )
194
186
}
0 commit comments