Azure / Azure/bicep

Extract to module

Open
#14,482 2 comments 0 reactions 1 assignee Claimed by @polatengin View on GitHub
enhancement Needs: Upvote
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

Make it easy to select a section of code in a bicep file and move that code into a module and replace the selected code with the instantiation of that now module.

For example, if I have a bicep file like the below:

```bicep
param namePrefix string

resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' = {
name: '${namePrefix}${uniqueString(resourceGroup().id)}'
location: resourceGroup().location
sku: {
name: 'Premium_LRS'
}
kind: 'StorageV2'
}
```

If I highlight the storage account resource and execute an "extract to module" command, I should get something like the following:

main.bicep
```bicep
param namePrefix string

module storageDeploy 'storage.bicep' = {
params: {
namePrefix: namePrefix
}
}
```

storage.bicep (the command should ask me for this filename)
```storage.bicep
param namePrefix string

resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' = {
name: '${namePrefix}${uniqueString(resourceGroup().id)}'
location: resourceGroup().location
sku: {
name: 'Premium_LRS'
}
kind: 'StorageV2'
}
```

Note the command would have needed to notice that the `namePrefix` param was used in the resource declaration, and replicate that over to the module accordingly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.