Skip to content

Commit 2892de5

Browse files
committed
Fix bicep export functionality: resolve build errors and update documentation
- Fix FileUtility.cs: Add missing XML documentation for extension parameter - Fix FileUtility.cs: Use dynamic extension parameter instead of hardcoded .json - Update ChangeLog.md: Add bicep export feature entry for upcoming release - Update Export-AzResourceGroup.md: Add OutputFormat parameter documentation and examples - Add TestExportResourceGroupBicep.json: New test recording file for bicep export tests - Update existing test recording files with latest test runs Addresses PR review feedback regarding missing documentation and changelog updates. All build errors resolved and functionality verified.
1 parent de48b2b commit 2892de5

File tree

7 files changed

+2288
-1260
lines changed

7 files changed

+2288
-1260
lines changed

src/Resources/ResourceManager/Utilities/FileUtility.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public static class FileUtility
3535
/// <param name="outputPath">The file output path</param>
3636
/// <param name="overwrite">Overrides existing file</param>
3737
/// <param name="shouldContinue">The confirmation action</param>
38+
/// <param name="extension">The file extension (defaults to .json)</param>
3839
/// <returns>The file path</returns>
39-
public static string SaveTemplateFile(string templateName, string contents, string outputPath, bool overwrite, Func<string, string, bool> shouldContinue, string extension = ".json") // Added extension parameter with default
40+
public static string SaveTemplateFile(string templateName, string contents, string outputPath, bool overwrite, Func<string, string, bool> shouldContinue, string extension = ".json")
4041
{
4142
StringBuilder finalOutputPath = new StringBuilder();
4243

@@ -48,14 +49,14 @@ public static class FileUtility
4849

4950
if (FileUtilities.IsValidDirectoryPath(outputPath))
5051
{
51-
finalOutputPath.Append(Path.Combine(outputPath, templateName + ".json"));
52+
finalOutputPath.Append(Path.Combine(outputPath, templateName + extension));
5253
}
5354
else
5455
{
5556
finalOutputPath.Append(outputPath);
56-
if (!outputPath.EndsWith(".json"))
57+
if (!outputPath.EndsWith(extension))
5758
{
58-
finalOutputPath.Append(".json");
59+
finalOutputPath.Append(extension);
5960
}
6061
}
6162

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestExportResourceGroup.json

Lines changed: 343 additions & 312 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestExportResourceGroupAsyncRoute.json

Lines changed: 524 additions & 618 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestExportResourceGroupBicep.json

Lines changed: 1014 additions & 0 deletions
Large diffs are not rendered by default.

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestExportResourceGroupWithFiltering.json

Lines changed: 368 additions & 324 deletions
Large diffs are not rendered by default.

src/Resources/Resources/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added support for exporting resource group templates as Bicep files
23+
- Added `OutputFormat` parameter to `Export-AzResourceGroup` cmdlet
24+
- Supported values: `Json` (default), `Bicep`
2225

2326
## Version 8.0.1
2427
* Fixed empty warning output issue for cmdlet `Test-AzResourceGroupDeployment` [#27888]

src/Resources/Resources/help/Export-AzResourceGroup.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ Captures a resource group as a template and saves it to a file.
1616
```
1717
Export-AzResourceGroup -ResourceGroupName <String> [-Path <String>] [-IncludeParameterDefaultValue]
1818
[-IncludeComments] [-SkipResourceNameParameterization] [-SkipAllParameterization] [-Resource <String[]>]
19-
[-Force] [-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
19+
[-OutputFormat <String>] [-Force] [-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>]
2020
[-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

2323
## DESCRIPTION
24-
The **Export-AzResourceGroup** cmdlet captures the specified resource group as a template and saves it to a JSON file.This can be useful in scenarios where you have already created some resources in your resource group, and then want to leverage the benefits of using template backed deployments.
24+
The **Export-AzResourceGroup** cmdlet captures the specified resource group as a template and saves it to a JSON or Bicep file.This can be useful in scenarios where you have already created some resources in your resource group, and then want to leverage the benefits of using template backed deployments.
2525
This cmdlet gives you an easy start by generating the template for your existing resources in the resource group.
2626
There might be some cases where this cmdlet fails to generate some parts of the template.
2727
Warning messages will inform you of the resources that failed.
@@ -53,6 +53,20 @@ Export-AzResourceGroup -ResourceGroupName "TestGroup" -SkipAllParameterization -
5353

5454
This command captures two resources from the "TestGroup" resource group as a template, and saves it to a JSON file in the current directory. The generated template will not contain any generated parameters.
5555

56+
### Example 4: Export a resource group as a Bicep file
57+
```powershell
58+
Export-AzResourceGroup -ResourceGroupName "TestGroup" -OutputFormat Bicep
59+
```
60+
61+
This command captures the resource group named TestGroup as a template, and saves it to a Bicep file in the current directory.
62+
63+
### Example 5: Export a resource group as a Bicep file with custom path
64+
```powershell
65+
Export-AzResourceGroup -ResourceGroupName "TestGroup" -OutputFormat Bicep -Path "C:\Templates\MyResourceGroup.bicep"
66+
```
67+
68+
This command captures the resource group named TestGroup as a template, and saves it to a Bicep file at the specified path.
69+
5670
## PARAMETERS
5771

5872
### -ApiVersion
@@ -146,6 +160,21 @@ Accept pipeline input: True (ByPropertyName)
146160
Accept wildcard characters: False
147161
```
148162
163+
### -OutputFormat
164+
Specifies the format of the exported template. Supported values are "Json" and "Bicep".
165+
166+
```yaml
167+
Type: System.String
168+
Parameter Sets: (All)
169+
Aliases:
170+
171+
Required: False
172+
Position: Named
173+
Default value: Json
174+
Accept pipeline input: False
175+
Accept wildcard characters: False
176+
```
177+
149178
### -Pre
150179
Indicates that this cmdlet use pre-release API versions when automatically determining which API version to use.
151180

0 commit comments

Comments
 (0)