Usage
init – Initialize Resources
Bootstrap a new project following DevEx conventions.
Generates:
- A local monorepository with dotfiles and a locked mise toolchain configuration. Publication to GitHub.com is optional.
- The GitHub Copilot coding agent setup workflow
(
.github/workflows/copilot-setup-steps.yml), which installs the toolchain and the dependencies before the agent starts and needs no secret.
Before generating anything, the command checks that Terraform and mise are installed and that the GitHub token can read the DX packages from GitHub Packages (see Installation).
If you publish the repository, keep the Terraform state in infra/repository
on this machine. Do not delete it or run terraform apply for infra/repository
from another device until the first dx add environment moves
the state to Azure.
Prompt Reference
The init command is interactive. The tables below explain what each prompt
expects and where to find the required values.
| Prompt | What to enter |
|---|---|
| Name | The GitHub repository name. Use lowercase letters and hyphens (e.g., eng-myteam-myproject). |
| GitHub owner | The GitHub organization or personal account that will own the repository. Defaults to pagopa. |
| Description | A short description of the project (optional). |
| Code owners | One or more @username or @organization/team references, separated by spaces. Required for organization repositories. A personal repository automatically includes its owner's username; additional users are optional. |
Use the repeatable --code-owner flag to supply owners without prompting:
npx @pagopa/dx-cli init --name my-project --owner pagopa \
--code-owner @pagopa/product-team \
--code-owner @pagopa/platform-team --publish
In CI or without an interactive terminal, organization initialization fails if
code owners are missing. Personal namespaces automatically include @owner.
The CLI validates account existence and team visibility and organization. Teams must belong to the repository organization and cannot own code in personal repositories.
All validated owners appear on one * line in the root CODEOWNERS file. The same
team slugs populate repository.reviewers_teams in infra/repository/main.tf.
Please, keep in mind that GitHub permits at most six distinct deployment reviewer teams.
Access grants are a separate manual step. The CLI does not grant or verify repository Write access. For PagoPA repositories, its next steps tell you to open a PR in pagopa/eng-github-authorization to register the repository, grant these same teams/users Write access (or higher), and associate the product GitHub App. For other organizations, follow their authorization process.
Code-owner review requests only become effective after access is granted and CODEOWNERS is present on the PR's base branch. Adding CODEOWNERS in the scaffold PR therefore does not automatically request its owners on that initial PR. CODEOWNERS and deployment reviewer settings do not grant repository access.
Example Usage
npx @pagopa/dx-cli init
✔ Terraform is installed!
? Name test-project
? GitHub owner pagopa-dx
? Description a custom description
? Code owners (@username or @pagopa-dx/team, separated by spaces; required) @pagopa-dx/product-team
✔ Workspace files created successfully!
✔ GitHub repository created successfully!
✔ Code pushed to GitHub successfully!
✔ Pull Request created successfully!
Workspace created successfully!
- Name: test-project
- GitHub Repository: https://github.com/pagopa-dx/test-project
Next Steps:
1. Review the Pull Request in the GitHub repository: https://github.com/pagopa-dx/test-project/pull/1
2. Visit https://dx.pagopa.it/getting-started to deploy your first project
Code ownership and access:
- Use pagopa-dx's authorization process to grant @pagopa-dx/product-team Write access (or higher) to pagopa-dx/test-project.
After the command completes, you will have a new GitHub repository with an open Pull Request to merge the initial project structure.
add - Scaffold New Components
Scaffold new components in your project following DevEx guidelines.
Currently Supported Components
| Component Type | Description |
|---|---|
environment | Add a new cloud environment to the project |
environment
Add a new cloud environment following DevEx conventions.
The command requires mise. During setup it adds the AWS and Azure CLIs (and
the uv runtime required by the Azure CLI backend) to the repository's
mise.toml, then refreshes mise.lock.
Always provisions:
- GitHub environments corresponding to the specified cloud environments
- A self-hosted GitHub Runner with permissions to perform cloud operations, in order to run workflows (GitHub Actions) that require cloud access
Additionally provisions (if no Terraform state file is detected for the project):
- A VPN to let users access private cloud resources
- Standardized network configuration
- Standardized monitoring configuration
- Infrastructure required to manage the Terraform state file (e.g., Azure Storage Account with blob locking)
This interactive command will prompt you for several inputs and then generate the project structure accordingly.
Currently, only Azure is supported as cloud provider for the add environment
command.
The first dx add environment moves local repository state to Azure
(<prefix>/<domain>/repository.tfstate) and removes the local copy after a
clean terraform plan. If neither local nor remote state exists and automatic
import fails, recover the original state or complete the imports manually
before retrying.
Before first placement, the CLI asks you to confirm the environment,
subscription, Resource Group, Storage Account, container, and key. Use --yes
to accept this placement non-interactively. The destination is permanent for the
repository: adding another environment keeps and reports the configured backend,
including existing keys created by earlier CLI versions.
Use the GitHub remote's repository name as a literal in main.tf and its owner
as a literal on the default github provider. The CLI rejects JSON
configuration, override files, and custom provider mappings.
The validate-v2 workflow plans infra/repository as bootstrapper-prod-ci.
If repository state is stored in a different subscription, the CLI does not
grant that identity cross-subscription access. Before relying on that workflow,
ask the destination subscription owner to grant the identity access to the
repository's state container, including permission to lock the state blob.
Verify access by running a CI plan; a successful migration with your own Azure
credentials does not verify CI access.
If local state and a destination blob both exist, reconcile them manually before retrying, even if the blob is empty. Do not delete or overwrite either copy to bypass the check.
Prompt Reference
The add environment command is interactive. The tables below explain what each
prompt expects and where to find the required values.
| Prompt | What to enter |
|---|---|
| Environment name | Enter prod, uat, dev, or a tenant-qualified name ending with one of them (for example ced-prod or cgn-dev). |
| Cloud provider(s) | Select Microsoft Azure (currently the only supported provider). |
| Account(s) | Select one or more Azure subscriptions belonging to your product. Contact your Engineering Leader if you are unsure which subscriptions to pick. |
| Prefix | A short identifier (2–4 characters) used in Azure resource names. It should match the prefix already in use for your product (e.g., dx, io, pn). |
| Domain | An optional sub-grouping for the project (e.g., payments). Leave empty if not needed. |
| Cost center | Select your team’s cost center. Defaults to TS000 - TECNOLOGIA & SERVIZI; --cost-center accepts only the listed choices. |
| Owner | The team or person responsible for the environment (required; free text). Use --owner when running non-interactively. |
| Business unit | The business unit or team that owns this project (free text, optional; press Enter to skip). |
| Management team | The team responsible for managing the environment (free text, optional; press Enter to skip). |
| Default location for <account> | The primary Azure region for the selected account (e.g., Italy North). Asked once per selected account. |
Valid cost centers are TS000 - TECNOLOGIA & SERVIZI, TS100 - TECNOLOGIA,
TS110 - SVILUPPO E ARCHITETTURA, TS120 - CLIENT E FRONTEND,
TS200 - SICUREZZA, TS300 - PRODOTTI E SERVIZI,
TS310 - PAGAMENTI & SERVIZI, TS320 - PIATTAFORMA NOTIFICHE DIGITALI, and
TS330 - PDND & INTEROPERABILITA', TS720 - DEV EX.
Multi-tenant environments
Use a tenant-qualified environment name when the same monorepo needs separate deployment environments for different tenants or product scopes.
npx @pagopa/dx-cli add environment \
--name ced-prod \
--prefix ced \
--account <subscription-id> \
--location <subscription-id>=italynorth \
--domain bonus \
--owner devex \
--business-unit devex \
--management-team devex
The --name and --prefix values have different purposes:
| Option | Purpose | Example |
|---|---|---|
--name | GitHub environment and infrastructure folder name. It can be dev, uat, prod, or a tenant-qualified name ending with one of them. | ced-prod |
--prefix | Short 2–4 character prefix used in Azure resource names. | ced |
The lifecycle suffix determines the Azure environment short code used by the
generated resources: *-dev maps to d, *-uat maps to u, and *-prod maps
to p. For example, --name ced-prod --prefix ced creates files under
infra/bootstrapper/ced-prod and infra/core/ced-prod, while Azure resource
names use the ced-p-... prefix convention.
Run add environment once for each tenant/environment pair you need, changing
both --name and --prefix when the tenant changes.
Repository Terraform configuration
The command updates infra/repository/main.tf in the generated
module "github_repository" by adding the environment to its
repository.environments list. When the list is absent, prod is implicit;
adding another environment also makes prod explicit. The command preserves
other HCL settings and requires a single repository module with a literal
repository object and a list of unique, literal environment names.
Existing lists are normalized only when an environment needs to be added. Lists
containing comments are left unchanged when the requested environment and prod
already exist. Otherwise, the command refuses to edit them: move the comments
outside the list or add both names manually before retrying. Comments outside
the list are preserved.
If customized HCL is rejected, restore the generated module/object layout,
replace dynamic environments expressions with a literal list, remove duplicate
names, and run terraform fmt infra/repository/main.tf. Formatting alone does
not remove comments or convert dynamic expressions.
Unsupported target shapes are rejected before writing. Changed candidates must
also pass terraform fmt - before replacing main.tf or running
terraform init and terraform apply. Terraform diagnostics are included in
validation errors, but its formatted output is not written over unrelated
source.
Updates require a regular UTF-8 main.tf file, preserve its permissions, and
use atomic replacement. Run commands sequentially and do not edit the file
during synchronization: concurrent writers in the same working copy are not
supported. After a valid edit, a later terraform init or terraform apply
failure does not roll back the edited file or any remote changes.
Initialization and Runner App credentials
The initialization confirmation and Terraform backend selection are conditional on the environment state. Runner App credentials are required whenever a new GitHub environment is configured, including when the Azure bootstrap resources already exist. For an initialized subscription, the CLI automatically reads available credentials from the environment's common Key Vault and uses them without asking for confirmation. Explicit credential flags take precedence. The CLI stores the Client ID, installation ID, and private key as GitHub environment secrets used by the bootstrapper workflow; they are not written to generated Terraform or workflow files.
The Azure CLI identity needs data-plane read access to that Key Vault, such as
Key Vault Secrets User or Key Vault Secrets Officer. If a secret is absent
or access is denied, the CLI explains the problem and prompts only for the
missing values. It never displays the private key.
Key Vaults created by older CLI versions do not contain the Client ID. When reusing the App ID and private key from such a vault, supply the Client ID once: the CLI attempts to save it to the common vault for later runs. If the identity has only read access, the command continues but the Client ID must be supplied again until it is added to the vault. When multiple subscriptions are selected, provide the Runner App credentials explicitly.
The CLI omits Runner App credentials from its JSON success result. This also
applies when CI=1 selects JSON output automatically.
| Prompt | What to enter |
|---|---|
| Initialize it now? | Confirm Yes to provision the baseline cloud infrastructure (VPN, network, monitoring, Terraform backend). |
| Cloud Account for the remote Terraform backend | Shown only when multiple accounts are selected. Pick the account that will host the Terraform state Storage Account. |
| GitHub Runner App ID | The App ID retrieved in the Prepare the GitHub App section. |
| GitHub Runner App Client ID | The Client ID retrieved in the same section. |
| GitHub Runner App Installation ID | The Installation ID retrieved in the same section. |
| GitHub Runner App Private Key | An editor will open — paste the full content of the .pem private key file, then save and close the editor. |
For non-interactive execution, the CLI also reuses available vault credentials. Provide any missing values explicitly. For a new environment, supply all four:
CI=1 npx @pagopa/dx-cli add environment \
--name prod \
--account <subscription-id> \
--location <subscription-id>=italynorth \
--prefix dx \
--domain payments \
--owner devex \
--cost-center "TS330 - PDND & INTEROPERABILITA'" \
--business-unit devex \
--management-team devex \
--runner-app-id <runner-app-id> \
--client-id <client-id> \
--installation-id <installation-id> \
--private-key-path <path-to-private-key.pem> \
-y
If any Runner App value remains missing in CI=1 mode, the command stops with
an explicit error listing the required options before configuring the GitHub
environment.
Example Usage
npx @pagopa/dx-cli add environment
✔ Terraform is installed!
✔ You are logged in to Azure (andrea.grillo@pagopa.it)
? Environment name prod
? Cloud provider(s) Microsoft Azure
? Account(s) (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
◯ DEV-ENGINEERING
◯ DEV-IO
❯◯ DEV-DEVEX
◯ UAT-DEVEX
(Move up and down to reveal more choices)
[...]
✔ Environment created successfully!
After the command completes, you will have a new GitHub repository with an open Pull Request to merge the initial project structure.
doctor – Repository Validation
Validate your repository against DevEx guidelines. Typical checks include:
- Configuration of the
@pagopa/nx-terraformplugin innx.json. nx.jsonpresence and the minimum Nx version indevDependencies.- Required monorepo scripts in
package.json. - Workspace declaration and structure.
Run the command:
npx @pagopa/dx-cli doctor
Exit code: 0 if all checks pass, 1 if one or more checks fail.
Example output:
✔ Nx Terraform Plugin ok
✔ Nx Configuration ok
✖ Monorepo Scripts missing: build, test
codemod – Repository Migrations
Codemods are scripted migrations that modify repository files to align with evolving platform standards. They aim to be safe, incremental, and repeatable.
List Available Codemods
npx @pagopa/dx-cli codemod list
You will get a brief list of migration identifiers. Use one of them with
codemod apply.
Current Codemods
| identifier | description |
|---|---|
use-pnpm | Migrate the project to use pnpm (lockfile import, workspace rewriting, workflow updates). |
use-azure-appsvc | Migrate web_app_deploy and function_app_deploy to release-azure-appsvc |
update-code-review | Update js_code_review workflow reference to latest commit with required permissions. |
Apply a Codemod
npx @pagopa/dx-cli codemod apply <id>
Arguments:
<id>: The codemod identifier from the list output.
- Always run codemods on a clean working tree (commit or stash your changes first).
- Review the diff after applying a codemod (
git diff). - Run
pnpm install(if package manager changed) and project validation scripts afterward.
Feedback
Found an issue or need a new codemod? Open an issue in the pagopa/dx repository describing the use case.