Skip to content

[Datadog_Action_Connection] Mismatch between Client and Realworld API #3396

Description

@Marcel2603

Describe the bug
I have noticed ghost changes, if i create http action connections via terraform with httpTokens.

After debugging a while, i've noticed that the go api client asserts, that the server returns all tokens under response.Data.Attributes.Integration.HTTPIntegration.Credentials.HTTPTokenAuth.Tokens. In Reality (datadog.eu) the Server returns the token under following json path data.attributes.integration.http_tokens.

At the end, the "tokens"-field is empty and the real tokens are storend under AdditionalProperties with key "http_tokens".

I viewed the codebase, but im not sure how to fix that...

To Reproduce
Steps to reproduce the behavior:

  1. Create a Datadog HTTP-Action Connection with a Secret token
  2. Write down Integration ID
  3. execute the go-script from bellow
  4. Notice how the token field is empty
  5. compare with the curl-script

Expected behavior
All tokens from the Connection should be stored inside the token-field of "HTTPTokenAuth"

Example

resource "datadog_action_connection" "this" {
  name = "my-http-connection"

  http {
    base_url = "https://api.com/"
    token_auth {
      token {
        type  = "SECRET"
        name  = "privateToken"
        value = var.token
      }
      header {
        name  = "PRIVATE-TOKEN"
        value = "{{ privateToken }}"
      }
    }
  }
}
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	ctx := context.WithValue(
		context.Background(),
		datadog.ContextAPIKeys,
		map[string]datadog.APIKey{
			"apiKeyAuth": {
				Key: os.Getenv("DD_API_KEY"),
			},
			"appKeyAuth": {
				Key: os.Getenv("DD_APP_KEY"),
			},
		},
	)
	ctx = context.WithValue(ctx,
		datadog.ContextServerVariables,
		map[string]string{
			"site": os.Getenv("DD_SITE"),
		})
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewActionConnectionApi(apiClient)
	resp, r, err := api.GetActionConnection(ctx, os.Getenv("DD_INTEGRATION_ID"))

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `ActionConnectionApi.GetActionConnection`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	fmt.Fprintf(os.Stdout, "Response from `ActionConnectionApi.GetActionConnection`:\n%+v\n", resp.Data.Attributes.Integration.HTTPIntegration.Credentials.HTTPTokenAuth)
}

Curl-Script

# Path parameters
export connection_id="$DD_INTEGRATION_ID"
# Curl command
curl -X GET "https://api.datadoghq.eu/api/v2/actions/connections/${connection_id}" \
-H "Accept: application/json" \
-H "DD-API-KEY: $DD_API_KEY" \
-H "DD-APPLICATION-KEY: $DD_APP_KEY"

Environment and Versions (please complete the following information):
A clear and precise description of your setup:

Additional context
Also effects the terraform provider https://github.com/DataDog/terraform-provider-datadog on https://github.com/DataDog/terraform-provider-datadog/blob/master/datadog/fwprovider/resource_datadog_action_connection.go#L453

Because the Api-Tokens-Field is always empty, Terraform tries to always update the connection, even if nothing changed

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugBug related issuestaleStale - Bot reminder

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions