Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract to module #14482

Open
alex-frankel opened this issue Jul 5, 2024 · 2 comments
Open

Extract to module #14482

alex-frankel opened this issue Jul 5, 2024 · 2 comments
Labels
enhancement New feature or request Needs: Upvote This issue requires more votes to be considered

Comments

@alex-frankel
Copy link
Collaborator

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.

@alex-frankel alex-frankel added the enhancement New feature or request label Jul 5, 2024
@stephaniezyen stephaniezyen added this to the Committed Backlog milestone Jul 10, 2024
@stephaniezyen stephaniezyen added Needs: Upvote This issue requires more votes to be considered and removed Needs: Triage 🔍 labels Jul 10, 2024
@alex-frankel
Copy link
Collaborator Author

Per @StephenWeatherford it could also potentially be useful to do the reverse "take this module and inline it into the current file"

@StephenWeatherford
Copy link
Contributor

Dupe of #8522, but this has more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Needs: Upvote This issue requires more votes to be considered
Projects
Status: Todo
Development

No branches or pull requests

3 participants