dynatrace-oss/terraform-provider-dynatrace

`dynatrace_service_naming` - "value must be null if the operator 'EXISTS' is specified"

Closed this issue · 3 comments

Describe the bug
If the following plan is applied, the remote API complains about value not being null

  + resource "dynatrace_service_naming" "kubernetes" {
      + enabled = true
      + format  = "{ProcessGroup:KubernetesContainerName}-{HostGroup:Name}"
      + id      = (known after apply)
      + name    = "tf-k8s-lynqtech-stage"

      + conditions {
          + condition {
              + entity {
                  + operator = "EQUALS"
                }
              + key {
                  + attribute = "HOST_GROUP_ID"
                  + type      = "STATIC"
                }
            }
          + condition {
              + process_metadata {
                  + attribute   = "PROCESS_GROUP_PREDEFINED_METADATA"
                  + dynamic_key = "KUBERNETES_CONTAINER_NAME"
                }
              + string {
                  + operator = "EXISTS"
                }
            }
          + condition {
              + key {
                  + attribute = "HOST_GROUP_NAME"
                  + type      = "STATIC"
                }
              + string {
                  + operator = "EXISTS"
                }
            }
        }
    }

Error: Error: The value must be null if the operator 'EXISTS' is specified, for any other operator it must be set.

This code worked before and is rolled into a new environment right now. Used provider is 1.70, I checked down until 1.67 - same error.


I assume the error is from the backend API and the provider is not fully compatible to it :(

https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/configuration-api/automatically-applied-tags-api/models -> "The StringComparison object"

https://docs.dynatrace.com/docs/discover-dynatrace/references/dynatrace-api/configuration-api/conditional-naming/post-rule#request-body-objects

🤷

Hello @daniel-ciaglia

The issue in hour HCL code is this portion:

entity {
  operator = "EQUALS"
}

The only allowed operator within an entity block is currently EQUALS - and that operator requires to specify a value, something like this

entity {
  operator = "EQUALS"
  value = "HOST_GROUP-00000000000"
}

Of course that doesn't explain at all, why you're getting response

The value must be null if the operator 'EXISTS' is specified, for any other operator it must be set

I've tested out this use case by addressing the Dynatrace REST API directly. And I got the same response.
The Terraform Provider is indeed just a middle man. The error message definitely doesn't match with the configuration you're trying to apply. But Terraform unfortunately is only able to relay responses from the REST API.

best regards,
Reinhard

@Reinhard-Pilz-Dynatrace , thanks for the analysis, indeed this is a logical issue in our code, I fixed that.
Question: did you forward the behaviour of the API internally?

Hi @daniel-ciaglia, yes, I've reached out to R&D about that.

As it turns out, the error message isn't even wrong.

The value must be null if the operator 'EXISTS' is specified, for any other operator it must be set

It is just too generic - i.e. tries to cover as many mistakes the REST API user might have made in one sentence ... and therefore leads to misunderstandings.
Upcoming versions of the Dynatrace REST API will respond with something like Value must be set or Value must not be null.