Making use of Outputs in deployment scripts #3688
Answered
by
deniscooper
deniscooper
asked this question in
Q&A
Replies: 2 comments 5 replies
-
Do you mind sharing the entire template? |
Beta Was this translation helpful? Give feedback.
1 reply
-
param location string = resourceGroup().location
param subnetName string = 'PROD-BROM-SUB-INT-SERVERS'
param virtualNetworkID string = '/subscriptions/15fae3c7-14e6-47e4-8610-f9d56afb5aad/resourceGroups/PROD-RG-S2SVPN/providers/Microsoft.Network/virtualNetworks/PROD-BROM-VNET01'
param virtualMachineName string
param osDiskType string = 'Premium_LRS'
param virtualMachineSize string = 'Standard_DS1_v2'
param adminUserName string
@secure()
param adminPassword string
var vnetID = virtualNetworkID
var subnetRef = '${vnetID}/subnets/${subnetName}'
var networkInterfaceName = '${virtualMachineName}-NIC'
var ipconfig1 = '${virtualMachineName}-ipConfig'
var groupName = 'APP-D-RDS-${virtualMachineName}'
var serverFQDN = '${virtualMachineName}.bromford.net'
var ipAddress = '10.44.3.99'
resource networkInterface 'Microsoft.Network/networkInterfaces@2021-02-01' = {
name: networkInterfaceName
location: location
properties: {
ipConfigurations: [
{
name: ipconfig1
properties: {
subnet: {
id: subnetRef
}
privateIPAllocationMethod: 'Dynamic'
}
}
]
}
}
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-03-01' = {
name: virtualMachineName
location: location
properties: {
hardwareProfile: {
vmSize: virtualMachineSize
}
storageProfile: {
osDisk: {
createOption: 'FromImage'
name: '${virtualMachineName}-osDisk'
managedDisk: {
storageAccountType: osDiskType
}
}
imageReference: {
publisher: 'MicrosoftWindowsServer'
offer: 'WindowsServer'
sku: '2016-Datacenter'
version: 'latest'
}
}
networkProfile: {
networkInterfaces: [
{
id: networkInterface.id
}
]
}
osProfile: {
computerName: virtualMachineName
adminUsername: adminUserName
adminPassword: adminPassword
windowsConfiguration: {
enableAutomaticUpdates: true
provisionVMAgent: true
}
}
}
}
resource deploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'createOnPremResources'
kind: 'AzurePowerShell'
location: location
properties: {
azPowerShellVersion: '5.0'
scriptContent: '''
param (
[parameter(mandatory=$true)]
$groupName,
[parameter(mandatory=$true)]
$serverFQDN,
[parameter(mandatory=$true)]
$serverIP
)
$funcURI = 'https://prod-func-.azurewebsites.net/?'
$DeploymentScriptOutputs["output"] = Invoke-WebRequest -Method Get -Uri "$($funcURI)&groupName=$groupName&serverFQDN=$serverFQDN&ipAddress=$serverIP"
'''
arguments: '-groupName ${groupName} -serverFQDN ${serverFQDN} -serverIP ${ipAddress}'
cleanupPreference: 'OnSuccess' //when to cleanup the storage account and ACI instance or OnExpiration, Always
retentionInterval: 'PT4H' //keep the deployment script resource for this duration (ISO 8601 format) and ACI/SA if OnExpiration cleanuppreference
//forceUpdateTag: c // ensures script runs every time
}
}
output networkDetails array = networkInterface.properties.ipConfigurations
output scriptOutput string = deploymentScript.properties.outputs.output
// Add tag values
// Add admin password and username from keyvault |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
anthony-c-martin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Thanks to some help i've got my template working exactly as needed. The template builds a new azure vm, then runs a deployment script within the template to setup some on-premises resources, such as a local ad account and group. I need it to also update the IP address in DNS. The deployment script is running with PowerShell from the template. Im passing in parameters into the script from the rest of the template, but for the IP address, i need it to pass in the IP which is produced in the output networkDetails
output networkDetails string = networkInterface.properties.ipConfigurations[0].properties.privateIPAddress
i tried to create a variable from the output but it says you can't do that, so im not sure how i can pass the IP address from the output into my deployment script.
Beta Was this translation helpful? Give feedback.
All reactions