-
Notifications
You must be signed in to change notification settings - Fork 63
Description
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:
- Create a Datadog HTTP-Action Connection with a Secret token
- Write down Integration ID
- execute the go-script from bellow
- Notice how the token field is empty
- 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:
- using the terraform provider and the datadog-api-client
- https://github.com/DataDog/datadog-api-client-go/releases/tag/v2.47.0
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