This command lets you upload Terraform runtime artifacts (plan and state JSON files) to the Datadog CI intake endpoint for enhanced cloud-to-code mapping and policy evaluation.
datadog-ci terraform upload [plan|state] <path/to/terraform-file.json> [additional-files...]planorstate: The type of Terraform artifact being uploaded<path>: Path to one or more Terraform JSON files (space-separated)
--repo-id(optional): Repository identifier override (e.g., github.com/datadog/my-repo)--expected-plans(optional): Total number of plans the pipeline uploads for this commit, across all jobs combined. Only valid forplanuploads. Defaults to the number of plan files passed to the command, which is correct when a single command uploads every plan of the commit. If the plans are uploaded by several commands (for example, one per job), pass the same total to every command. If the value is lower than the number of plan files passed to the command, the number of files is used instead (with a warning).--dry-run(default:false): Run the command without uploading any data to Datadog--verbose(default:false): Enable verbose logging--skip-git-metadata-upload(default:false): Skip the upload of git metadata
The following environment variables are required:
DD_API_KEY: the API key to use
Optional environment variables:
DD_SITE: the Datadog site (default:datadoghq.com)DD_GIT_REPOSITORY_URL: Override for repository URLDD_REPOSITORY_URL: Alternative override for repository URL
# Upload a single Terraform plan file
datadog-ci terraform upload plan ./terraform-plan.json
# Upload multiple Terraform plan files
datadog-ci terraform upload plan ./plan1.json ./plan2.json ./plan3.json
# Upload multiple plan files using glob expansion
datadog-ci terraform upload plan ./plans/*.json
# Upload a Terraform state file
datadog-ci terraform upload state ./terraform.tfstate
# Upload with manual repo-id override
datadog-ci terraform upload plan ./terraform-plan.json --repo-id "github.com/my-org/my-repo"
# Declare that the pipeline uploads 3 plans in total for this commit (for example, one per job) using the flag
datadog-ci terraform upload plan ./terraform-plan.json --expected-plans 3
# In a shared CI template (sh/bash), forward an optional pipeline variable as the flag
datadog-ci terraform upload plan ./terraform-plan.json ${EXPECTED_PLANS:+--expected-plans "$EXPECTED_PLANS"}
# Dry run mode
datadog-ci terraform upload plan ./terraform-plan.json --dry-run
# Upload multiple files with verbose logging
datadog-ci terraform upload plan ./plan1.json ./plan2.json --verboseThe Git context is resolved in the following order of priority:
- CI environment variables
- Current Git repository metadata
- Override environment variables (
DD_GIT_*variables)
The repository identifier (repo_id) is resolved in this order:
--repo-idflag valueDD_GIT_REPOSITORY_URLorDD_REPOSITORY_URLenvironment variable- Git metadata from the current repository
To test locally, run:
yarn launch terraform upload plan /path/to/terraform-plan.json- The command accepts one or more files per invocation. All files must be of the same artifact type (plan or state).
- Files are automatically gzipped before upload.
- The command computes a SHA256 hash of each file's content.
- No client-side validation or filtering of file content is performed (as per RFC requirements).
- Git metadata is synced only once per invocation, even when uploading multiple files.