|
| 1 | +# Using Dry Run |
| 2 | + |
| 3 | +The Auth0 Deploy CLI supports a "dry run" mode that allows you to preview all potential changes to your Auth0 tenant without actually applying them. This feature provides a safety net for validating configurations and understanding the impact of deployments before they occur. |
| 4 | + |
| 5 | +[Discussions thread](https://github.com/auth0/auth0-deploy-cli/discussions/1092?sort=new) |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +### Command Line Interface |
| 10 | + |
| 11 | +Add the `--dry_run` flag to your import command: |
| 12 | + |
| 13 | +```bash |
| 14 | +a0deploy import --config_file=config.json --input_file=./tenant.yaml --dry_run |
| 15 | +``` |
| 16 | + |
| 17 | +Or use the shorter form: |
| 18 | + |
| 19 | +```bash |
| 20 | +a0deploy import -c config.json -i ./tenant-directory --dry_run |
| 21 | +``` |
| 22 | + |
| 23 | +### Node Module |
| 24 | + |
| 25 | +Set the `AUTH0_DRY_RUN` configuration property to `true`: |
| 26 | + |
| 27 | +```javascript |
| 28 | +import { deploy } from 'auth0-deploy-cli'; |
| 29 | + |
| 30 | +deploy({ |
| 31 | + input_file: './local/tenant.yaml', |
| 32 | + config: { |
| 33 | + AUTH0_DOMAIN: process.env.AUTH0_DOMAIN, |
| 34 | + AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID, |
| 35 | + AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET, |
| 36 | + AUTH0_DRY_RUN: true, |
| 37 | + }, |
| 38 | +}) |
| 39 | + .then(() => { |
| 40 | + console.log('Dry run completed successfully'); |
| 41 | + }) |
| 42 | + .catch((err) => { |
| 43 | + console.log('Error during dry run:', err); |
| 44 | + }); |
| 45 | +``` |
| 46 | + |
| 47 | +**Note**: Using `AUTH0_DRY_RUN` will present an interactive prompt to select options after displaying the dry run preview. |
| 48 | + |
| 49 | +### Environment Variable |
| 50 | + |
| 51 | +You can also enable dry run mode using an environment variable: |
| 52 | + |
| 53 | +```bash |
| 54 | +export AUTH0_DRY_RUN=true |
| 55 | +a0deploy import -c config.json -i ./tenant.yaml |
| 56 | +``` |
| 57 | + |
| 58 | +## Understanding the Output |
| 59 | + |
| 60 | +Dry run mode provides a detailed preview of all proposed changes in a table format: |
| 61 | + |
| 62 | +```text |
| 63 | +Auth0 Deploy CLI - Dry Run Preview |
| 64 | +
|
| 65 | +Tenant: example-tenant.auth0.com |
| 66 | +Input: local/tenant.yaml |
| 67 | +
|
| 68 | +Simulating deployment... The following changes are proposed: |
| 69 | +
|
| 70 | +| Resource | Status | Name / Identifier | |
| 71 | +|---------------|---------|----------------------------------| |
| 72 | +| Actions | CREATE | Post-Login User Enrichment | |
| 73 | +| | CREATE | Pre-Registration Validation | |
| 74 | +| | DELETE* | Deprecated Action | |
| 75 | +| Clients | CREATE | New SPA Application | |
| 76 | +| | UPDATE | Existing M2M Application | |
| 77 | +| Connections | UPDATE | Username-Password-Authentication | |
| 78 | +
|
| 79 | +* Requires AUTH0_ALLOW_DELETE to be enabled |
| 80 | +
|
| 81 | +Dry Run completed successfully. No changes have been made to your Auth0 tenant. |
| 82 | +
|
| 83 | +┌ dry-run |
| 84 | +│ |
| 85 | +◆ What would you like to do? |
| 86 | +│ ○ Apply changes |
| 87 | +│ ○ Export changes in a file (No Apply) |
| 88 | +│ ○ Exit |
| 89 | +└ |
| 90 | +``` |
| 91 | + |
| 92 | +## Interactive Options |
| 93 | + |
| 94 | +After displaying the dry run preview, the CLI presents interactive options: |
| 95 | + |
| 96 | +- **Apply changes**: Proceed to apply all the changes shown in the preview |
| 97 | +- **Export changes in a file**: Save the changes to a `dry-run-diff-log.json` file without applying them |
| 98 | +- **Exit**: Cancel the operation without making any changes |
| 99 | + |
| 100 | +## Resource Deletion Preview |
| 101 | + |
| 102 | +When `AUTH0_ALLOW_DELETE` is enabled, dry run will show which resources would be deleted: |
| 103 | + |
| 104 | +```bash |
| 105 | +# Enable deletions in your config |
| 106 | +export AUTH0_ALLOW_DELETE=true |
| 107 | +a0deploy import -c config.json -i ./tenant.yaml --dry_run |
| 108 | +``` |
| 109 | + |
| 110 | +Resources marked for deletion will appear in the output with `DELETE*` status, and the asterisk note will explain that `AUTH0_ALLOW_DELETE` must be enabled for deletions to occur. |
| 111 | + |
| 112 | +## Validation and Error Handling |
| 113 | + |
| 114 | +Dry run performs the same validation as a regular deployment: |
| 115 | + |
| 116 | +- **Schema Validation**: Ensures all resources conform to Auth0's expected structure |
| 117 | +- **Business Rule Validation**: Checks for conflicts, required fields, and logical constraints |
| 118 | +- **Configuration Validation**: Validates keyword replacements and file references |
| 119 | + |
| 120 | +If validation errors are found, dry run will report them without making any changes: |
| 121 | + |
| 122 | +```text |
| 123 | +Validation Error: Rule "My Rule" - Names must be unique |
| 124 | +Error: Configuration validation failed. No changes made. |
| 125 | +``` |
| 126 | + |
| 127 | +## No Changes Detected |
| 128 | + |
| 129 | +If no changes are detected between your configuration and the current tenant state, dry run will display: |
| 130 | + |
| 131 | +```text |
| 132 | +Auth0 Deploy CLI - Dry Run Preview |
| 133 | +
|
| 134 | +Tenant: example-tenant.auth0.com |
| 135 | +Input: ./tenant-config/ |
| 136 | +
|
| 137 | +Simulating deployment... The following changes are proposed: |
| 138 | +
|
| 139 | +No changes detected. |
| 140 | +
|
| 141 | +Dry Run completed successfully. No changes have been made to your Auth0 tenant. |
| 142 | +``` |
| 143 | + |
| 144 | +## Best Practices |
| 145 | + |
| 146 | +1. **Always Dry Run First**: Make dry run a standard part of your deployment workflow, especially for production environments. |
| 147 | + |
| 148 | +2. **Review All Changes**: Carefully examine the proposed changes, paying special attention to deletions and updates to critical resources. |
| 149 | + |
| 150 | +3. **Validate in Stages**: For large configuration changes, consider breaking them into smaller deployments and dry running each stage. |
| 151 | + |
| 152 | +4. **Check Dependencies**: Ensure that resource dependencies (like client grants referencing specific clients) are properly configured. |
| 153 | + |
| 154 | +5. **Environment Consistency**: Use dry run to verify that keyword replacements produce the expected values for your target environment. |
| 155 | + |
| 156 | +## Limitations and Considerations |
| 157 | + |
| 158 | +- **State Changes**: The actual tenant state may change between running a dry run and the actual deployment. The dry run reflects the state at the time it was executed. |
| 159 | + |
| 160 | +- **API Limitations**: Some validation can only be performed during actual API calls. Dry run performs as much validation as possible without making changes. |
| 161 | + |
| 162 | +- **Resource Dependencies**: Complex dependencies between resources might only be fully validated during actual deployment. |
| 163 | + |
| 164 | +- **External Factors**: Changes made by other users or processes to the Auth0 tenant are not reflected in the dry run results. |
| 165 | + |
| 166 | +## Troubleshooting |
| 167 | + |
| 168 | +### Common Issues |
| 169 | + |
| 170 | +**Configuration Errors**: If you see configuration-related errors, verify your keyword replacement mappings and file paths. |
| 171 | + |
| 172 | +**Authentication Issues**: Ensure your Auth0 client has the necessary scopes to read all resources you're trying to manage. |
| 173 | + |
| 174 | +**File Not Found**: Check that all referenced files (scripts, templates, etc.) exist and are accessible. |
| 175 | + |
| 176 | +**Format Mismatches**: Verify that your input format matches your configuration. Using YAML format with JSON-specific dry run configurations may cause issues, and vice versa. Ensure consistency between your input file format and configuration settings. |
| 177 | + |
| 178 | +### Getting Help |
| 179 | + |
| 180 | +If you encounter issues with dry run mode: |
| 181 | + |
| 182 | +1. Enable debug logging: `--debug` flag or `AUTH0_DEBUG=true` |
| 183 | +2. Check the [troubleshooting guide](./troubleshooting.md) |
| 184 | +3. Review your configuration against the [documentation](./configuring-the-deploy-cli.md) |
| 185 | +4. Open an issue on the [GitHub repository](https://github.com/auth0/auth0-deploy-cli/issues) |
0 commit comments