Terraform provides helpful Extending Terraform documentation for best practices around writing provider code. This document provides some guidelines for working with this project.
- Terraform 0.12.x and higher.
- The
tfenv
project lets you easily install and switch between terraform versions
- The
- Go 1.15 (to build the provider plugin)
- A clone of this repository and the $GOPATH environment variable set
- tfplugindocs
- gotestsum (to run project tests)
gotestsum
executable binary is installed into$GOPATH/bin
when runningmake get-test-deps
. Add the$GOPATH/bin
directory to your$PATH
All new resources should be written using Terraform Plugin Framework. See here for examples of current resources implemented using Terraform Plugin Framework. NOTE: We currently support Protocol Version 5.
The root of this project contains a GNUmakefile
with the purpose of making each development step easier. While some commands are outlined here, please see GNUmakefile for all available commands.
The Datadog Provider can be built to use the binary as a terraform plugin. This is most useful when attempting to build off a feature branch and manually run the terraform plan|apply
commands on a real HCL configuration. The steps for this approach can differ depending on the version of Terraform being used. More information can be found on the official Terraform documentation.
This provider can be built by running make build
, or just make
. This will place the binary in $GOPATH/bin
- Setup a
~/.terraformrc
file with the following content:
provider_installation {
dev_overrides {
"DataDog/datadog" = "<YOUR expanded $GOPATH/bin> directory>"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
- Create a directory to put HCL files in, for example
terraform_examples
- Create a
main.tf
file:
# terraform_examples/main.tf
terraform {
required_providers {
datadog = {
source = "DataDog/datadog"
}
}
}
provider "datadog" {
api_key = "<YOUR_API_KEY>"
app_key = "<YOUR_APP_KEY>"
}
# ... any resource config
- In your
terraform_examples
folder, runterraform init
once to initialize the directory - In the datadog terraform provider folder, run
make
, which will build and place the binary in $GOPATH/bin - Run
terraform plan|apply
in yourterraform_examples
folder to use your locally built provider. - Iterate by making changes to the provider, running
make
, and just runningterraform plan|apply
in yourterraform_examples
folder.
The Datadog terraform provider uses the standard Terraform Testing Framework to define its tests.
NOTE Use the API and APP keys for a sandbox/test organization, never an account hosting production data. This test suite will create/update/delete real resources.
DD_TEST_CLIENT_API_KEY="<api_key>" DD_TEST_CLIENT_APP_KEY=<app_key> make testall
will run the test suite against the real Datadog API.
We also use cassettes
to record API request/responses, which allows the test suite to be reliable and run very quickly. There are a few environment variables that can control this behavior (All commands are assumed to be prefixed with DD_TEST_CLIENT_API_KEY=
and DD_TEST_CLIENT_APP_KEY=
). You can configure the api url of the test suite using DD_TEST_SITE_URL="<api_url>"
.
TESTARGS
: Allows passing extra flags directly to the underlyinggo test
command. Most often used to run individual tests:- Ex:
TESTARGS="-run TestAccDatadogServiceLevelObjective_Basic" make testall
- Ex:
RECORD
: This denotes whether the test suite should interact with the real Datadog API. Available options are:RECORD=none make testall
: Run against the real Datadog API.RECORD=true make testall
: Run against the real Datadog API and record the request/response to be used later.RECORD=false make testall
: Don't interact with the real Datadog API, instead playback against the recorded cassettes.
Follow the official documentation
Documentation for this provider is autogenerated using the tfplugindocs
CLI.
- Ensure each Schema attribute in the code contains a
Description
field - Place example HCL configuration files or import scripts in the
examples
folder under your resource/data-source - Run
make docs
to retrieve thetfplugindocs
binary and generate documentation
In order to update the underlying API Clients that are used by this provider to interact with the Datadog API, run:
API_CLIENT_VERSION=vx.y.z ZORKIAN_VERSION=vx.y.z make update-go-client
where:
API_CLIENT_VERSION
is the version or commit ref of the https://github.com/DataDog/datadog-api-client-go client.ZORKIAN_VERSION
is the version or commit ref of the https://github.com/zorkian/go-datadog-api client.
NOTE If you run this command just after a release of the underlying clients, this will automatically pick up the latest tag without needing to specify the version.
To help with changelog documentation, all pull requests must be labelled properly.
It needs one changelog label (among improvement
, feature
, bugfix
, note
and no-changelog
), and one resource mentioned in the title as a prefix (if not no-changelog
) corresponding to the resource being changed (For example [datadog_dashboard] Fix issue
).