mirror of
https://github.com/actions/runner-images.git
synced 2025-12-10 02:46:51 +00:00
Cleanup json formatted packer template references (#9165)
This commit is contained in:
committed by
GitHub
parent
5ee9ae1e60
commit
4d310f0a59
@@ -28,7 +28,7 @@ Function CreateAzureVMFromPackerTemplate {
|
||||
The location where the Azure virtual machine will be provisioned. Example: "eastus"
|
||||
|
||||
.EXAMPLE
|
||||
CreateAzureVMFromPackerTemplate -SubscriptionId {YourSubscriptionId} -ResourceGroupName {ResourceGroupName} -TemplateFile "C:\BuildVmImages\temporaryTemplate.json" -VirtualMachineName "testvm1" -AdminUsername "shady1" -AdminPassword "SomeSecurePassword1" -AzureLocation "eastus"
|
||||
CreateAzureVMFromPackerTemplate -SubscriptionId {SubscriptionId} -ResourceGroupName {ResourceGroupName} -VirtualMachineName "testvm1" -ManagedImageName {ManagedImageName} -AdminUsername "shady1" -AdminPassword "SomeSecurePassword1" -AzureLocation "eastus"
|
||||
#>
|
||||
param (
|
||||
[Parameter(Mandatory = $True)]
|
||||
|
||||
@@ -176,7 +176,6 @@ Function GenerateResourcesAndImage {
|
||||
}
|
||||
|
||||
Write-Host "Access to packer generated VM will be restricted to agent IP Address: $AgentIp."
|
||||
if ($TemplatePath.Contains("pkr.hcl")) {
|
||||
if ($PSVersionTable.PSVersion.Major -eq 5) {
|
||||
Write-Verbose "PowerShell 5 detected. Replacing double quotes with escaped double quotes in allowed inbound IP addresses."
|
||||
$AllowedInboundIpAddresses = '[\"{0}\"]' -f $AgentIp
|
||||
@@ -190,17 +189,8 @@ Function GenerateResourcesAndImage {
|
||||
}
|
||||
}
|
||||
else {
|
||||
$AllowedInboundIpAddresses = $AgentIp
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($TemplatePath.Contains("pkr.hcl")) {
|
||||
$AllowedInboundIpAddresses = "[]"
|
||||
}
|
||||
else {
|
||||
$AllowedInboundIpAddresses = ""
|
||||
}
|
||||
}
|
||||
Write-Debug "Allowed inbound IP addresses: $AllowedInboundIpAddresses."
|
||||
|
||||
# Prepare tags
|
||||
@@ -216,16 +206,6 @@ Function GenerateResourcesAndImage {
|
||||
$TagsJson = $TagsJson -replace '"', '\"'
|
||||
}
|
||||
Write-Debug "Tags JSON: $TagsJson."
|
||||
if ($TemplatePath.Contains(".json")) {
|
||||
Write-Verbose "Injecting tags into packer template."
|
||||
if ($Tags) {
|
||||
$BuilderScriptPathInjected = $TemplatePath.Replace(".json", "-temp.json")
|
||||
$PackerTemplateContent = Get-Content -Path $TemplatePath | ConvertFrom-Json
|
||||
$PackerTemplateContent.builders | Add-Member -Name "azure_tags" -Value $Tags -MemberType NoteProperty
|
||||
$PackerTemplateContent | ConvertTo-Json -Depth 3 | Out-File -Encoding Ascii $BuilderScriptPathInjected
|
||||
$TemplatePath = $BuilderScriptPathInjected
|
||||
}
|
||||
}
|
||||
|
||||
$InstallPassword = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper()
|
||||
|
||||
|
||||
@@ -69,14 +69,7 @@ jobs:
|
||||
$TemplateDirectoryPath = Join-Path "images" $TemplateDirectoryName | Resolve-Path
|
||||
|
||||
$TemplateFileName = "${{ parameters.image_template_name }}"
|
||||
if ($TemplateFileName) {
|
||||
$TemplatePath = Join-Path $TemplateDirectoryPath $TemplateFileName
|
||||
} else {
|
||||
$TemplatePath = Join-Path $TemplateDirectoryPath "$ImageType.pkr.hcl"
|
||||
if ( -not (Test-Path $TemplatePath) ) {
|
||||
$TemplatePath = Join-Path $TemplateDirectoryPath "$ImageType.json"
|
||||
}
|
||||
}
|
||||
Write-Host "##vso[task.setvariable variable=TemplateDirectoryPath;]$TemplateDirectoryPath"
|
||||
Write-Host "##vso[task.setvariable variable=TemplatePath;]$TemplatePath"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user