codemod/arm-redundant-resource-dependson
Remove redundant explicit dependsOn entries from Azure Resource Manager (ARM) JSON templates when the dependency is already implied by nested resources or by reference()/references()/list*() calls that target the same resourceId().
# @codemod/arm-redundant-resource-dependson
Remove redundant explicit `dependsOn` entries from Azure Resource Manager (ARM) JSON templates when the dependency is already implied by ARM evaluation semantics.
## Installation
```bash
# Install from registry
codemod run @codemod/arm-redundant-resource-dependson
# Or run locally
codemod run -w workflow.yaml
```
## Usage
This codemod targets ARM template `.json` files and removes `dependsOn` entries in two conservative cases:
- The resource already references the same template resource via `reference(...)`, `references(...)`, or a `list* (...)` function call whose first argument is the same `resourceId(...)` expression.
- A nested child resource explicitly depends on its containing resource, even though that parent dependency is already implied by the nested resource relationship.
The codemod preserves `dependsOn` entries when it cannot prove the dependency is implicit. In particular, it leaves unrelated dependencies, non-`resourceId(...)` entries, and resources that only mention another resource ID as plain data unchanged.
Example:
```json
{
"type": "Microsoft.Web/sites/config",
"name": "[format('{0}/appsettings', parameters('siteName'))]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('siteName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
],
"properties": {
"StorageConnectionString": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2023-01-01').keys[0].value]"
}
}
```
Becomes:
```json
{
"type": "Microsoft.Web/sites/config",
"name": "[format('{0}/appsettings', parameters('siteName'))]",
"properties": {
"StorageConnectionString": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2023-01-01').keys[0].value]"
}
}
```
## Development
```bash
# Test the transformation
pnpm test
# Check TypeScript types
pnpm check-types
# Validate the workflow
codemod workflow validate -w workflow.yaml
# Publish to registry
codemod login
codemod publish
```
## License
MIT