Skip to content

Commit

Permalink
Bicep deployment fix for parameter file updates (#733)
Browse files Browse the repository at this point in the history
* initial commit

* Update Strings

Co-authored-by: Jesper Fajers <jesper@fajers.se>
  • Loading branch information
daltondhcp and Jefajers authored Dec 22, 2022
1 parent 124623c commit 1755d64
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/functions/Invoke-AzOpsPush.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
$bicepTemplatePath = $fileItem.FullName -replace '.parameters.json', '.bicep'
if (Test-Path $bicepTemplatePath) {
Write-PSFMessage -Level Verbose @common -String 'Invoke-AzOpsPush.Resolve.FoundBicepTemplate' -StringValues $FilePath, $bicepTemplatePath
$result.TemplateFilePath = $bicepTemplatePath
$transpiledTemplatePath = ConvertFrom-AzOpsBicepTemplate -BicepTemplatePath $bicepTemplatePath
$result.TemplateFilePath = $transpiledTemplatePath
return $result
}
#endregion Directly Associated bicep template exists
Expand Down Expand Up @@ -249,10 +250,7 @@

# Handle Bicep templates
if ($addition.EndsWith(".bicep")) {
Assert-AzOpsBicepDependency -Cmdlet $PSCmdlet
$transpiledTemplatePath = $addition -replace '\.bicep', '.json'
Write-PSFMessage -Level Verbose @common -String 'Invoke-AzOpsPush.Resolve.ConvertBicepTemplate' -StringValues $addition, $transpiledTemplatePath
Invoke-AzOpsNativeCommand -ScriptBlock { bicep build $addition --outfile $transpiledTemplatePath }
$transpiledTemplatePath = ConvertFrom-AzOpsBicepTemplate -BicepTemplatePath $addition
$addition = $transpiledTemplatePath
}

Expand Down
6 changes: 5 additions & 1 deletion src/internal/classes/AzOpsScope.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@
break
}
Default {
Write-PSFMessage -Level Warning -String 'AzOpsScope.Input.BadData.TemplateParameterFile' -StringValues $Path -FunctionName AzOpsScope -ModuleName AzOps
# Only show warning about parameter file if parameter file doesn't have deploymentParameters schema defined
if ($resourcePath.'$schema' -notmatch 'deploymentParameters.json') {
Write-PSFMessage -Level Warning -String 'AzOpsScope.Input.BadData.TemplateParameterFile' -StringValues $Path -FunctionName AzOpsScope -ModuleName AzOps
}

Write-PSFMessage -Level Verbose -String 'AzOpsScope.InitializeMemberVariablesFromDirectory' -StringValues $Path -FunctionName AzOpsScope -ModuleName AzOps
$this.InitializeMemberVariablesFromDirectory($Path.Directory)
}
Expand Down
29 changes: 29 additions & 0 deletions src/internal/functions/ConvertFrom-AzOpsBicepTemplate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function ConvertFrom-AzOpsBicepTemplate {
<#
.SYNOPSIS
Transpiles bicep template to Azure Resource Manager (ARM) template.
The json file will be created in the same folder as the bicep file.
.PARAMETER BicepTemplatePath
BicepTemplatePath
#>

[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$BicepTemplatePath
)

begin {
# Assert bicep binaries
Assert-AzOpsBicepDependency -Cmdlet $PSCmdlet
}
process {
# Convert bicep template
$transpiledTemplatePath = $BicepTemplatePath -replace '\.bicep', '.json'
Write-PSFMessage -Level Verbose -String 'ConvertFrom-AzOpsBicepTemplate.Resolve.ConvertBicepTemplate' -StringValues $BicepTemplatePath, $transpiledTemplatePath
Invoke-AzOpsNativeCommand -ScriptBlock { bicep build $bicepTemplatePath --outfile $transpiledTemplatePath }
# Return transpiled ARM json path
return $transpiledTemplatePath
}
}
5 changes: 3 additions & 2 deletions src/localized/en-us/Strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
'AzOpsScope.InitializeMemberVariablesFromFile.resource' = 'Determine scope based on Resource Type {0} and Resource Name {1}' # ResourceType and #Resource Name
'AzOpsScope.ChildResource.InitializeMemberVariables' = 'Determine scope of Child Resource based on Resource Type {0}, Resource Name {1} and Parent ResourceID {2}' # ResourceType, Resource Name, Parent ResourceId

'ConvertFrom-AzOpsBicepTemplate.Resolve.ConvertBicepTemplate' = 'Converting Bicep template ({0}) to standard ARM Template JSON ({1})' # $BicepTemplatePath, $transpiledTemplatePath

'ConvertTo-AzOpsState.Exporting' = 'Exporting AzOpsState to {0}' # $resourceData.ObjectFilePath
'ConvertTo-AzOpsState.Exporting.Default' = 'Exporting input resource to AzOpsState to {0}' # $resourceData.ObjectFilePath
'ConvertTo-AzOpsState.File.Create' = 'AzOpsState file not found. Creating new: {0}' # $ObjectFilePath
Expand Down Expand Up @@ -185,9 +187,8 @@
'Invoke-AzOpsPush.Deployment.Required' = 'Deployment required' #
'Invoke-AzOpsPush.Dependency.Missing' = 'Missing resource dependency for successfull deletion. Error exiting runtime.'
'Invoke-AzOpsPush.DeploymentList.NotFound' = 'Expecting deploymentList object, it was not found. Error exiting runtime.'
'Invoke-AzOpsPush.Resolve.ConvertBicepTemplate' = 'Converting Bicep template ({0}) to standard ARM Template JSON ({1})' # $addition, $transpiledTemplatePath
'Invoke-AzOpsPush.Resolve.FoundTemplate' = 'Found template {1} for parameters {0}' # $FilePath, $templatePath
'Invoke-AzOpsPush.Resolve.FoundBicepTemplate' = 'Found Bicep template {1} for parameters {0}' # $FilePath, $templatePath
'Invoke-AzOpsPush.Resolve.FoundBicepTemplate' = 'Found Bicep template {1} for parameters {0}' # $FilePath, $bicepTemplatePath
'Invoke-AzOpsPush.Resolve.FromMainTemplate' = 'Determining template from main template file: {0}' # $mainTemplateItem.FullName
'Invoke-AzOpsPush.Resolve.MainTemplate.NotSupported' = 'effectiveResourceType: {0} AzOpsMainTemplate does NOT supports resource type {0} in {1}. Deployment will be ignored' # $effectiveResourceType, $AzOpsMainTemplate.FullName
'Invoke-AzOpsPush.Resolve.MainTemplate.Supported' = 'effectiveResourceType: {0} - AzOpsMainTemplate supports resource type {0} in {1}' # $effectiveResourceType, $AzOpsMainTemplate.FullName
Expand Down

0 comments on commit 1755d64

Please sign in to comment.