Skip to content

Commit

Permalink
Add safe type assert to required fields (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenais authored and nmuesch committed Aug 15, 2019
1 parent 6296b6d commit 99ef461
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3783,11 +3783,12 @@ func buildDatadogApmOrLogQuery(terraformQuery map[string]interface{}) *datadog.W
}
// Compute
terraformCompute := terraformQuery["compute"].(map[string]interface{})
datadogCompute := datadog.ApmOrLogQueryCompute{
Aggregation: datadog.String(terraformCompute["aggregation"].(string)),
datadogCompute := datadog.ApmOrLogQueryCompute{}
if aggr, ok := terraformCompute["aggregation"].(string); ok && len(aggr) != 0 {
datadogCompute.Aggregation = datadog.String(aggr)
}
if v, ok := terraformCompute["facet"].(string); ok && len(v) != 0 {
datadogCompute.Facet = datadog.String(v)
if facet, ok := terraformCompute["facet"].(string); ok && len(facet) != 0 {
datadogCompute.Facet = datadog.String(facet)
}
if interval, ok := terraformCompute["interval"].(string); ok && len(interval) != 0 {
if v, err := strconv.ParseInt(interval, 10, 64); err == nil {
Expand Down Expand Up @@ -3816,9 +3817,13 @@ func buildDatadogApmOrLogQuery(terraformQuery map[string]interface{}) *datadog.W
}
// Sort
if sort, ok := groupBy["sort"].(map[string]interface{}); ok && len(sort) > 0 {
datadogGroupBy.Sort = &datadog.ApmOrLogQueryGroupBySort{
Aggregation: datadog.String(sort["aggregation"].(string)),
Order: datadog.String(sort["order"].(string)),

datadogGroupBy.Sort = &datadog.ApmOrLogQueryGroupBySort{}
if aggr, ok := sort["aggregation"].(string); ok && len(aggr) > 0 {
datadogGroupBy.Sort.Aggregation = datadog.String(aggr)
}
if order, ok := sort["order"].(string); ok && len(order) > 0 {
datadogGroupBy.Sort.Order = datadog.String(order)
}
if facet, ok := sort["facet"].(string); ok && len(facet) > 0 {
datadogGroupBy.Sort.Facet = datadog.String(sort["facet"].(string))
Expand Down

0 comments on commit 99ef461

Please sign in to comment.