Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -7628,7 +7628,7 @@ func buildDatadogFormula(data map[string]interface{}) *datadogV1.WidgetFormula {
formula.SetStyle(*datadogFormulaStyle)
}
if number, ok := data["number_format"].([]interface{}); ok && len(number) != 0 {
datadogNumberFormat := buildNumberFormatFormulaSchema(number[0].(map[string]interface{}))
datadogNumberFormat := buildDatadogNumberFormatFormulaSchema(number[0].(map[string]interface{}))
formula.SetNumberFormat(*datadogNumberFormat)
}

Expand Down Expand Up @@ -11057,7 +11057,7 @@ func getNumberFormatFormulaSchema() map[string]*schema.Schema {
}
}

func buildNumberFormatFormulaSchema(terraformStyle map[string]interface{}) *datadogV1.WidgetNumberFormat {
func buildDatadogNumberFormatFormulaSchema(terraformStyle map[string]interface{}) *datadogV1.WidgetNumberFormat {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buildDatadog functions are on the write path (turning HCL to Datadog schema), renamed this for clarity.

if terraformStyle == nil || len(terraformStyle) == 0 {
return nil
}
Expand Down Expand Up @@ -11087,6 +11087,15 @@ func buildNumberFormatFormulaSchema(terraformStyle map[string]interface{}) *data
}
}
}
if v, ok := terraformStyle["unit_scale"].([]interface{}); ok && len(v) > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to actually create a dashboard with this field with unitScale until adding this too. Uses the same schema as below.

unitScale := v[0].(map[string]interface{})
if unitName, ok := unitScale["unit_name"].(string); ok && len(unitName) > 0 {
datadogNumber.UnitScale = *datadogV1.NewNullableNumberFormatUnitScale(&datadogV1.NumberFormatUnitScale{
Type: datadogV1.NUMBERFORMATUNITSCALETYPE_CANONICAL_UNIT.Ptr(),
UnitName: datadog.PtrString(unitName),
})
}
}
return &datadogNumber
}

Expand All @@ -11106,8 +11115,7 @@ func buildTerraformNumberFormatFormulaSchema(datadogStyle datadogV1.WidgetNumber
m["unit"] = []map[string]interface{}{unit}
}
if v, ok := datadogStyle.GetUnitScaleOk(); ok {
unitScale := map[string]interface{}{}
unitScale["unit_name"] = []map[string]interface{}{{"unit_name": v.UnitName}}
unitScale := map[string]interface{}{"unit_name": v.UnitName}
m["unit_scale"] = []map[string]interface{}{unitScale}
Copy link
Contributor Author

@brlee19 brlee19 Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema for this is:

"unit_scale": &schema.Schema{
			Description: "",
			Type:        schema.TypeList,
			MinItems:    0,
			MaxItems:    1,
			Optional:    true,
			Elem: &schema.Resource{
				Schema: map[string]*schema.Schema{
					"unit_name": &schema.Schema{
						Description: "",
						Type:        schema.TypeString,
						Required:    true,
					},
				},
			},
		},

so m["unit_scale"] is supposed to contain a list of map[string]string if I am reading this right, not another map containing "unit_name" as a key

Copy link
Contributor Author

@brlee19 brlee19 Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code appears to be the cause of the error per the CI output:

level=fatal msg="Execution failed" error="error: error generating plan: exit status 1\n\nError: widget.1.group_definition.0.widget.0.query_value_definition.0.request.0.formula.0.number_format.0.unit_scale.0.unit_name: '' expected type 'string', got unconvertible type '[]map[string]interface {}', value: '[map[unit_name:0xc0009716e0]]'\n\n with datadog_dashboard.maze_api_dashboard,\n on dashboard.tf line 1, in resource \"datadog_dashboard\" \"maze_api_dashboard\":\n 1: resource \"datadog_dashboard\" \"maze_api_dashboard\" {\n\n code: INVALID_ARGUMENT origin: terraform-invocation, action: plan, cause: USER, resource: \n"

aka it is saying that the first element of unit_scale had a []map[string]interface {}' at its unit_name key and not just a string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why the old code was working until Wednesday though this probably has something to do with the new release that day.

}
return []map[string]interface{}{m}
Expand Down
Loading