Skip to content

Conversation

surajdubey08
Copy link

This PR resolves #3131 by fixing the value conversion error that occurs when using parse_test_options with the datadog_synthetics_global_variable resource.

Problem

When configuring parse_test_options with the synthetics global variable resource, Terraform returns the following error:

Error: Value Conversion Error
...
Received unknown value, however the target type cannot handle unknown values.
Path: parse_test_options
Target Type: []fwprovider.syntheticsGlobalVariableParseTestOptionsModel
Suggested Type: basetypes.ListValue

This occurs because the resource model uses raw Go slices for nested attributes ([]Model) instead of the proper Terraform Framework types (types.List). In the Terraform Framework, nested attributes must use Framework types to correctly handle unknown values and type conversions during planning and state management.

Solution

I've implemented the following changes to resolve this issue:

  1. Updated the model to use types.List for ParseTestOptions and Options fields instead of Go slices
  2. Defined proper attribute types for the nested object structures
  3. Added conversion helpers to transform between Terraform Framework types and API types
  4. Updated Create, Read, and Update methods to properly use these conversions
  5. Added comprehensive test coverage specifically for the parse_test_options functionality

This implementation follows the patterns established in other recently fixed resources (such as #1765 and #1783) and adheres to Terraform Framework best practices for handling nested attributes.

Testing

I've added a new acceptance test that validates the parse_test_options functionality works as expected:

resource "datadog_synthetics_global_variable" "test" {
  name  = "test_variable"
  value = "test_value"
  secure = true
  
  parse_test_options {
    field = "auth_token"
    type  = "http_header"
    parser {
      type  = "regex"
      value = "token=([a-f0-9]+)"
    }
  }
}

The test:

  • Creates a global variable with parse_test_options configuration
  • Verifies all nested attributes are correctly set and persisted
  • Tests updating the configuration
  • Would have failed with the previous implementation but now passes

Additional context

This fix enables users to properly configure global variables that extract values from synthetic test responses, which is essential for many monitoring workflows. The issue particularly affects users who need to extract authentication tokens or other dynamic values from test responses.

I've reviewed the Terraform Framework documentation on nested attributes and ensured this implementation follows the recommended patterns. If there are any adjustments needed or if I've missed something in my approach, I would appreciate your feedback and am happy to make any necessary changes.

Thank you for your time and consideration of this contribution. I appreciate the work you do maintaining this provider and look forward to your feedback.

Best regards

@surajdubey08 surajdubey08 requested a review from a team as a code owner August 30, 2025 19:06
@surajdubey08
Copy link
Author

Hello @AntoineDona ,
I came across this issue when we were updating our Datadog terraform version and took upon the task of fixing it, as it was blocking our work and I was not sure when will this be fixed by someone. I have raised a PR, please take a look at the PR and let me know if the changes work.

@AntoineDona AntoineDona requested a review from a team September 8, 2025 09:07
Matt-Cam added a commit that referenced this pull request Sep 19, 2025
…cs │

│                                                                                                            │
│   - Fix error handling: properly propagate conversion errors instead of ignoring them                      │
│   - Fix recursive diagnostics appending (diags.Append(diags...))                                           │
│   - Prevent potential nil pointer panic in convertApiParseTestOptions                                      │
│   - Remove unused struct definitions (dead code)                                                           │
│   - Update updateState method to return diagnostics properly                                               │
│   - Fix API method name (NewSyntheticsVariableParserWithDefaults)
Matt-Cam added a commit that referenced this pull request Sep 19, 2025
- Fix error handling: properly propagate conversion errors instead of ignoring them
- Fix recursive diagnostics appending (diags.Append(diags...))
- Remove unused struct definitions (dead code)
- Update updateState method to return diagnostics properly
- Fix API method name (NewSyntheticsVariableParserWithDefaults)
Matt-Cam added a commit that referenced this pull request Sep 19, 2025
- Fix error handling: properly propagate conversion errors instead of ignoring them
- Fix recursive diagnostics appending (diags.Append(diags...))
- Remove unused struct definitions (dead code)
- Update updateState method to return diagnostics properly
- Fix API method name (NewSyntheticsVariableParserWithDefaults)
@surajdubey08
Copy link
Author

Hey @Matt-Cam , I would have appreciated it if you could have at least dropped a comment on the PR before adding your changes as your additional change might nullify my work on the issue 😀.

@Matt-Cam
Copy link
Contributor

Hey @Matt-Cam , I would have appreciated it if you could have at least dropped a comment on the PR before adding your changes as your additional change might nullify my work on the issue 😀.

Hi @surajdubey08 I'm experimenting with some other approaches on separate branches. I have not added any changes to your branch!

Matt-Cam added a commit that referenced this pull request Sep 22, 2025
…Error

- Remove complex helper functions from PR #3195
- Use simple struct building + types.ListValueFrom() pattern
- Keep existing logic with ElementsAs() for clean conversions
- Add global type definitions matching Datadog codebase patterns
Matt-Cam added a commit that referenced this pull request Sep 22, 2025
Keep only core resource fix and user's DynamicBlocks test
Matt-Cam added a commit that referenced this pull request Sep 22, 2025
Keep only core resource fix and user's DynamicBlocks test
Matt-Cam added a commit that referenced this pull request Sep 22, 2025
Keep only core resource fix and user's DynamicBlocks test
@Matt-Cam
Copy link
Contributor

Hi @surajdubey08, I have a #3244 open based on your initial idea. I'm going to have to squash that PR down since your original commits are not signed. In the future, make sure to sign your commits so that your work is included in the commit history. Thanks for raising and working on it 🙇🏼

Matt-Cam added a commit that referenced this pull request Sep 26, 2025
…Error

- Remove complex helper functions from PR #3195
- Use simple struct building + types.ListValueFrom() pattern
- Keep existing logic with ElementsAs() for clean conversions
- Add global type definitions matching Datadog codebase patterns
Matt-Cam added a commit that referenced this pull request Sep 26, 2025
Keep only core resource fix and user's DynamicBlocks test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"parse_test_options" argument in "datadog_synthetics_global_variable" broken from Datadog provider version 3.58.0 and above.
2 participants