-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support deploying Azure resources described with the Bicep language
- Loading branch information
1 parent
2eddc95
commit 084aabd
Showing
13 changed files
with
5,218 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Resources/ResourceManager/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
| ||
using Microsoft.Azure.Commands.Common.Authentication.Abstractions; | ||
using Microsoft.Azure.Commands.Common.Exceptions; | ||
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation; | ||
using Microsoft.WindowsAzure.Commands.Utilities.Common; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities | ||
{ | ||
public static class BicepUtility | ||
{ | ||
public static bool IsBicepExecutable = false; | ||
|
||
public static bool IsBicepFile(string templateFilePath) | ||
{ | ||
return ".bicep".Equals(Path.GetExtension(templateFilePath)?.ToLower()); | ||
} | ||
|
||
public delegate List<T> ScriptExecutor<T>(string script); | ||
|
||
public static bool CheckBicepExecutable(ScriptExecutor<Object> executeScript) | ||
{ | ||
try | ||
{ | ||
executeScript("get-command bicep"); | ||
} | ||
catch | ||
{ | ||
IsBicepExecutable = false; | ||
return IsBicepExecutable; | ||
} | ||
IsBicepExecutable = true; | ||
return IsBicepExecutable; | ||
} | ||
|
||
public static string BuildFile(ScriptExecutor<Object> executeScript, string bicepTemplateFilePath) | ||
{ | ||
if (!IsBicepExecutable && !CheckBicepExecutable(executeScript)) | ||
{ | ||
throw new AzPSApplicationException(Properties.Resources.NoBicepInstalled); | ||
} | ||
|
||
executeScript($"bicep build {bicepTemplateFilePath}"); | ||
|
||
string jsonTemplateFilePath = Path.Combine(Path.GetDirectoryName(bicepTemplateFilePath), | ||
Path.GetFileNameWithoutExtension(bicepTemplateFilePath) + ".json"); | ||
|
||
return jsonTemplateFilePath; | ||
} | ||
|
||
public static string BuildFileContent(ScriptExecutor<Object> executeScript, string templateContent, out string jsonTemplateFilePath) | ||
{ | ||
string tempFilePath = Path.GetTempFileName(); | ||
FileUtilities.DataStore.WriteFile(tempFilePath, templateContent); | ||
jsonTemplateFilePath = BuildFile(executeScript, tempFilePath); | ||
return FileUtilities.DataStore.ReadFileAsText(jsonTemplateFilePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.