-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[datadog_dashboard] Add support for text_formats in query table widget requests #2587
Conversation
ad9491d
to
de35b6d
Compare
2d81d3b
to
2b0d728
Compare
63f7a44
to
5eef67b
Compare
What would the consequences if we change |
6736c3a
to
a9c7f80
Compare
if v, ok := terraformTextFormatRule["palette"].(string); ok && len(v) != 0 { | ||
datadogTextFormatRule.SetPalette(datadogV1.TableWidgetTextFormatPalette(v)) | ||
} else { | ||
datadogTextFormatRule.Palette = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is needed, otherwise the default will be selected in place of empty.
0d9a237
to
758a73f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Created a Jira ticket for Docs Team review. |
77cf686
b694ec8
to
77cf686
Compare
Motivation
PAYP-27
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.Conclusion
We decided to add a
text_format
key for each inner array.Sample terraform config:
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 [email protected]:hashicorp/terraform.git
go build -ldflags "-w -s -X 'github.com/hashicorp/terraform/version.dev=no'" -o bin/ .
dashboard.tf
file containing the config I wanted to test within a folder$DATADOG_ROOT/terraform/bin/terraform refresh -no-color -input=false -lock-timeout=0s -lock=true
Terraform seems to scan the list of list of objects correctly. A section of code translates the
text_formats
config from tuple to list of list of object: