Add Terraform execution primitives - #1994
Conversation
Provide reusable plan-upload and apply tasks plus thin Nx executors so later release orchestration can use a tested two-phase Terraform flow with sensitive output masking. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds reusable “plan-then-apply” execution primitives for Terraform, so release workflows can upload a reviewed plan bundle and later apply that exact plan via Nx + @pagopa/dx-tasks, with configurable masking of sensitive Terraform output keys.
Changes:
- Added
terraformPlanUpload/terraformApplytasks (plus reports + masking support) to@pagopa/dx-tasks. - Added
plan-uploadandrelease-applyexecutors to@pagopa/nx-terraform-plugin, and surfaced sensitive output key configuration to the plan executor. - Updated packaging/bundled artifacts and runtime dependencies; added version plans for both packages.
Reviewed changes
Copilot reviewed 35 out of 42 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds runtime deps required by the plugin’s bundled dx-tasks code (Azure/S3 SDKs). |
| packages/nx-terraform-plugin/tsdown.config.ts | Adds build entries for the new executors. |
| packages/nx-terraform-plugin/src/project.ts | Propagates configured sensitive output keys into the plan target options. |
| packages/nx-terraform-plugin/src/options.ts | Adds plugin options for plan-upload target name and sensitive output keys. |
| packages/nx-terraform-plugin/src/executors/release-apply/schema.ts | Defines zod schema/types for release-apply executor inputs. |
| packages/nx-terraform-plugin/src/executors/release-apply/schema.json | Publishes the executor JSON schema for Nx. |
| packages/nx-terraform-plugin/src/executors/release-apply/release-apply.ts | Implements the executor that dispatches terraformApply via dx-tasks. |
| packages/nx-terraform-plugin/src/executors/release-apply/tests/release-apply.test.ts | Tests release-apply executor behavior (dispatch + dry-run handling). |
| packages/nx-terraform-plugin/src/executors/plan/schema.ts | Extends plan executor schema with sensitiveKeys. |
| packages/nx-terraform-plugin/src/executors/plan/schema.json | Documents sensitiveKeys option for the plan executor. |
| packages/nx-terraform-plugin/src/executors/plan/plan.ts | Passes sensitiveKeys through to dx-tasks terraformPlan. |
| packages/nx-terraform-plugin/src/executors/plan/tests/plan.test.ts | Updates plan executor tests for sensitiveKeys. |
| packages/nx-terraform-plugin/src/executors/plan-upload/schema.ts | Defines zod schema/types for plan-upload executor inputs. |
| packages/nx-terraform-plugin/src/executors/plan-upload/schema.json | Publishes the executor JSON schema for Nx. |
| packages/nx-terraform-plugin/src/executors/plan-upload/plan-upload.ts | Implements the executor that dispatches terraformPlanUpload via dx-tasks. |
| packages/nx-terraform-plugin/src/executors/plan-upload/tests/plan-upload.test.ts | Tests plan-upload executor behavior. |
| packages/nx-terraform-plugin/src/tests/package-manifest.test.ts | Asserts plugin declares required runtime deps for bundled dx-tasks. |
| packages/nx-terraform-plugin/src/tests/options.test.ts | Extends options parsing tests for new options. |
| packages/nx-terraform-plugin/package.json | Declares new external runtime dependencies (Azure/S3 SDKs). |
| packages/nx-terraform-plugin/executors.json | Registers the new executors for Nx consumption. |
| packages/nx-terraform-plugin/dist/index.js | Rebuilt plugin bundle reflecting option/target changes. |
| packages/nx-terraform-plugin/dist/executors/release-apply/release-apply.js | Compiled release-apply executor output. |
| packages/nx-terraform-plugin/dist/executors/publish/publish.js | Rebuilt compiled artifact (import ordering change in output). |
| packages/nx-terraform-plugin/dist/executors/plan/plan.js | Rebuilt compiled plan executor output with sensitive keys support. |
| packages/nx-terraform-plugin/dist/executors/plan-upload/plan-upload.js | Compiled plan-upload executor output. |
| packages/nx-terraform-plugin/dist/default-dispatcher-BTdenmPC.js | Bundled dx-tasks dispatcher code inside the plugin dist artifacts. |
| packages/dx-tasks/tsconfig.build.json | Adds a build tsconfig for emitting dist/ while excluding tests. |
| packages/dx-tasks/src/terraform/plan.ts | Adds sensitiveKeys to plan task payload and masking. |
| packages/dx-tasks/src/terraform/plan-upload.ts | Adds new task to plan with a fixed output and upload the bundle. |
| packages/dx-tasks/src/terraform/plan-file.ts | Defines shared fixed plan file name used by upload/apply. |
| packages/dx-tasks/src/terraform/apply.ts | Adds new task to download/apply a stored plan bundle + reporting. |
| packages/dx-tasks/src/terraform/tests/plan.test.ts | Adds test coverage for configured key masking in plan output. |
| packages/dx-tasks/src/terraform/tests/plan-upload.test.ts | Adds tests for the new plan-upload task. |
| packages/dx-tasks/src/terraform/tests/apply.test.ts | Adds tests for the new apply task and markdown/report rendering. |
| packages/dx-tasks/src/tasks.ts | Registers new task definitions for plan-upload and apply. |
| packages/dx-tasks/src/index.ts | Exposes apply report namespace and plan storage helpers from root export. |
| packages/dx-tasks/src/default-dispatcher.ts | Registers new tasks + apply report namespace in the default dispatcher. |
| packages/dx-tasks/README.md | Documents the new tasks and two-phase workflow semantics. |
| packages/dx-tasks/package.json | Switches exports to compiled dist/ entry points and adds build script. |
| nx.json | Configures global sensitive output keys for the terraform plugin. |
| .nx/version-plans/version-plan-1784226769468.md | Version plan for @pagopa/nx-terraform-plugin minor bump. |
| .nx/version-plans/version-plan-1784226768872.md | Version plan for @pagopa/dx-tasks minor bump. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Generate the configurable plan-upload target, preserve successful applies when remote cleanup fails, and validate apply payloads with the correct schema. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…/terraform-execution-primitives
Code Review ReportTerraform Plan:
|
Why
The release workflow needs reusable, tested primitives for persisting a Terraform plan and later applying that exact reviewed plan.
What changed
terraformPlanUploadandterraformApplytasks to@pagopa/dx-tasks.plan-uploadandrelease-applyexecutors to the Terraform Nx plugin.This PR adds execution capabilities only; it does not discover releasable environments or dispatch deployments.
Validation
pnpm nx run-many -t test lint typecheck -p @pagopa/dx-tasks @pagopa/nx-terraform-pluginpnpm nx run @pagopa/nx-terraform-plugin:buildDepends on #1993.
Extracted from #1926.