Skip to content

Commit 4d9eb06

Browse files
committed
ADD empty config field validation
1 parent d7ccc89 commit 4d9eb06

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

sysdig/resource_sysdig_monitor_cloud_account.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,34 @@ func monitorCloudAccountFromResourceData(data *schema.ResourceData) v2.CloudAcco
217217
}
218218

219219
func monitorCloudAccountForCostFromResourceData(data *schema.ResourceData) v2.CloudAccountMonitorForCost {
220+
221+
configuration := v2.CloudCostConfiguration{}
222+
223+
if config, ok := data.Get("config").(map[string]interface{}); ok {
224+
if val, exists := config["athena_bucket_name"]; exists {
225+
configuration.AthenaBucketName = val.(string)
226+
}
227+
if val, exists := config["athena_database_name"]; exists {
228+
configuration.AthenaDatabaseName = val.(string)
229+
}
230+
if val, exists := config["athena_region"]; exists {
231+
configuration.AthenaRegion = val.(string)
232+
}
233+
if val, exists := config["athena_workgroup"]; exists {
234+
configuration.AthenaWorkgroup = val.(string)
235+
}
236+
if val, exists := config["athena_table_name"]; exists {
237+
configuration.AthenaTableName = val.(string)
238+
}
239+
if val, exists := config["spot_prices_bucket_name"]; exists {
240+
configuration.SpotPricesBucketName = val.(string)
241+
}
242+
}
243+
220244
return v2.CloudAccountMonitorForCost{
221-
Feature: "Cloud cost",
222-
Platform: data.Get("cloud_provider").(string),
223-
Configuration: v2.CloudCostConfiguration{
224-
AthenaBucketName: data.Get("config").(map[string]interface{})["athena_bucket_name"].(string),
225-
AthenaDatabaseName: data.Get("config").(map[string]interface{})["athena_database_name"].(string),
226-
AthenaRegion: data.Get("config").(map[string]interface{})["athena_region"].(string),
227-
AthenaWorkgroup: data.Get("config").(map[string]interface{})["athena_workgroup"].(string),
228-
AthenaTableName: data.Get("config").(map[string]interface{})["athena_table_name"].(string),
229-
SpotPricesBucketName: data.Get("config").(map[string]interface{})["spot_prices_bucket_name"].(string),
230-
},
245+
Feature: "Cloud cost",
246+
Platform: data.Get("cloud_provider").(string),
247+
Configuration: configuration,
231248
Credentials: v2.CloudAccountCredentialsMonitor{
232249
AccountId: data.Get("account_id").(string),
233250
RoleName: data.Get("role_name").(string),

0 commit comments

Comments
 (0)