Open hyungl opened 1 week ago
What would the consequences if we change text_formats
from a list of lists to just a list? I suspect that may be causing the issue with requiring those explicitly set null
fields
Created a Jira ticket for Docs Team review.
Motivation
Customer has asked for Terraform support of an existing feature: Query Table text formats. Corresponding api-spec pr.
Existing dashboard schema containing
text_formats
:Fields
match
is an object containing fieldstype
,value
.replace
is an object containing fieldstype
,with
, andsubstring
.palette
is a dropdown of color options.custom_bg_color
andcustom_fg_color
are strings.text_formats is a nested array of objects
Each column of values in a query table accounts for each inner array of
text_formats
. Within each inner array, each object is a separate rule that governs the column of data.In the provider, we have to define
text_formats
as a nested arrayIn
resource_datadog_dashboard.go
, we have to define the schema like this:This seems to work, at least in terms of using terraform to manage dashboards
This example dashboard:
saves a dashboard like this:
Terraform doesn't respect that fields are defined as optional. All fields need to be specified, and given null values if unused
If any of the fields are left out in the terraform config, we see during testing ( Testing command:
RECORD=true TESTARGS="-run TestAccDatadogDashboardQueryTableWithTextFormats" op run -- make testall
, which runs this terraform command:terraform refresh -no-color -input=false -lock-timeout=0s -lock=true
) this error:This is happening when the test is trying to do
terraform refresh
of the config.Possible causes
Using logs, confirmed that the Provider function in this repo does specify the new optional fields as optional.
Example logging
To see why terraform was complaining, I had to build terraform from source and set logs in the dependency
hcl
library to see what's happening when the terraform config and schema are used.hcldec.AttrSpec instead of hcldec.BlockListSpec
The nodes of the terraform schema are handled as specs. Setting logs here confirmed that text_formats are handled as
*hcldec.AttrSpec
, not*hcldec.BlockListSpec
. Maybe this is why the optionals aren't working correctly? Another field in QueryTable.Request isconditional_formats
which is only one level of array nesting. That one is evaluated as a BlockListSpec and seems to handle Optional values correctly.Invalid Plan that is ignored
Seems terraform is being lenient with the difference between
null
and""
. Maybe this is causing issues downstream?Inner fields not Optional after decoding?
Printing out the
spec
that terraform hcl is using at this part of the code:Maybe it's not good that
Required: false
appears at the level of the entire object, but not for each nested field that is optional.Appendix - notes on testing
Since
terraform-provider-datadog
depends onterraform-plugin-testing
which depends onterraform-exec
, I replicated the test scenario by building terraform locally:git clone git@github.com:hashicorp/terraform.git
go build -ldflags "-w -s -X 'github.com/hashicorp/terraform/version.dev=no'" -o bin/ .
replace github.com/zclconf/go-cty v1.15.0 => /Users/hyung.lee/go/src/github.com/DataDog/go-cty
in: {{{{} [{{{} [{{{} map[custom_bg_color:{{{}}} custom_fg_color:{{{}}} match:{{{} map[type:{{{} 83}} value:{{{} 83}}] map[]}} palette:{{{}}} replace:{{{}}}] map[]}}]}}]}} [[map[custom_bg_color: custom_fg_color: match:map[type:is value:test] palette: replace:]]]}
in type name: tuple
want type name: list of list of object