Skip to content

Extract to module #14482

@alex-frankel

Description

@alex-frankel

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:

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

param namePrefix string

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

storage.bicep (the command should ask me for this filename)

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.

Metadata

Metadata

Assignees

Labels

Needs: UpvoteThis issue requires more votes to be consideredenhancementNew feature or request

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions