[IACP-673] Add terraform upload command for IaC artifact ingestion#2129
[IACP-673] Add terraform upload command for IaC artifact ingestion#2129vishal-joshi-datadog merged 19 commits intomasterfrom
Conversation
Implements new `datadog-ci terraform upload` command to upload Terraform plan and state JSON files to Datadog CI intake API. Key features: - Upload Terraform plan or state files to /api/v2/ciiac endpoint - Automatic git/CI metadata enrichment - SHA256 hashing and gzip compression of artifacts - Retry logic for transient failures - Dry-run and verbose modes - Optional repo-id override Architecture: - Base command in packages/base/src/commands/terraform/ - Plugin implementation in packages/plugin-terraform/ - Follows existing plugin architecture patterns (similar to coverage, sbom) - Multipart/form-data upload with event envelope + gzipped file Technical details: - Single file per invocation (users can loop for multiple files) - No client-side validation/filtering (per RFC requirements) - Event envelope includes artifact type, hash, size, and git/CI context - Supports all Datadog sites via DD_SITE environment variable Implementation plan: tf_command_plan.md RFC: /Users/vishal.joshi/Downloads/iac_artifact_rfc.md
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🔗 Commit SHA: 62496c3 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
packages/plugin-terraform/README.md
Outdated
|
|
||
| ## Development | ||
|
|
||
| When developing software, you can try with the following command: |
There was a problem hiding this comment.
| When developing software, you can try with the following command: | |
| To test locally, run: |
- Add api.test.ts with 7 tests covering multipart upload, gzip compression, and event envelope structure - Add utils.test.ts with 28 tests covering validation functions, hash computation, and repo ID resolution - Add upload.test.ts with 8 tests covering command execution, validation, and error handling - Add test fixtures for valid plan, valid state, and invalid JSON files - Mock git-related functions to prevent test timeouts All 43 tests passing
ee1ea58 to
a977efd
Compare
- Replace path with upath for Windows compatibility - Remove unused fs import - Add upath as devDependency
- Add --fips and --fips-ignore-error flags to base command - Import and call enableFips in plugin implementation - Add FIPS config from environment variables - Add terraform upload to required options in CLI tests - Add beforeEach to clear mock between tests - All FIPS tests passing ✓
ava-silver
left a comment
There was a problem hiding this comment.
overall lgtm, just a couple nits before I approve
| // Artifact type: 'plan' or 'state' | ||
| protected artifactType = Option.String({required: true}) |
There was a problem hiding this comment.
you can make validation (and typing!) easier by using typanion for validation, for example, isEnum can be used for enums here. An example of usage in this repo:
| import chalk from 'chalk' | ||
|
|
||
| import {TerraformArtifactPayload} from './interfaces' | ||
|
|
There was a problem hiding this comment.
mind at least using these constants in your renderers to keep the style consistent?
datadog-ci/packages/base/src/helpers/renderer.ts
Lines 6 to 12 in 176ebd3
and if it makes sense feel free to use the helpers in that module as you see fit
packages/plugin-terraform/README.md
Outdated
| for file in ./plans/*.json; do | ||
| datadog-ci terraform upload plan "$file" | ||
| done |
There was a problem hiding this comment.
nit: maybe worth considering adding support directly into the cli for this -- doing this in series will end up being slow if the customer has a lot of plan files
There was a problem hiding this comment.
Yes, we have multiple commands supporting glob patterns for multiple files (e.g. sourcemaps upload)
Drarig29
left a comment
There was a problem hiding this comment.
Can you follow https://github.com/DataDog/datadog-ci/blob/master/CONTRIBUTING.md#things-to-update since you are adding a new command scope?
packages/plugin-terraform/README.md
Outdated
| for file in ./plans/*.json; do | ||
| datadog-ci terraform upload plan "$file" | ||
| done |
There was a problem hiding this comment.
Yes, we have multiple commands supporting glob patterns for multiple files (e.g. sourcemaps upload)
Co-authored-by: Ava Silver <ava.silver@datadoghq.com>
ava-silver
left a comment
There was a problem hiding this comment.
one optional suggestion, but lgtm!
Summary
Implements new
datadog-ci terraform uploadcommand to upload Terraform plan and state JSON files to Datadog CI intake API for enhanced cloud-to-code mapping and policy evaluation.Changes
packages/base/src/commands/terraform/with CLI registration and command optionspackages/plugin-terraform/with full upload logic/api/v2/ciiacendpointUsage
Key Features
Technical Details
eventJSON +iac_filegzipped contentTesting
Documentation
packages/plugin-terraform/README.md🤖 Generated with Claude Code