How to Run Cloud Init YAML with Azure Bicep when Creating VM
source link: https://edi.wang/post/2023/3/5/how-to-run-cloud-init-yaml-with-azure-bicep-when-creating-vm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Run Cloud Init YAML with Azure Bicep when Creating VM
Original
3/5/2023, 1:47:10 AM
6 Reads
Problem
Azure document for "Create an Ubuntu Linux virtual machine using a Bicep file" did not show how to use custom data to run cloud init yaml file when creating VM.
After work 996, I finally figured out the undocumented method to run a cloud init yaml file with Azure Bicep. Let's see how to do it.
Solution
Create a YAML file for cloud init
Create a YAML file in the location where your bicep file can access. For example, I created 251.yml in the same directory with 251.bicep.
Write your cloud init content in the YAML file. For example, install docker
#cloud-config
runcmd:
- curl -fsSL https://get.docker.com | sh
Load YAML file in Bicep
Define a new variable in your bicep file.
Use loadTextContent()
to read YAML file content, and then encode it in base64()
var cloudInit = base64(loadTextContent('251.yml'))
Modify osProfile node
Find osProfile
node in your bicep file, add customData
into it.
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPassword
linuxConfiguration: null
customData: cloudInit // <-- add this line
}
Run Bicep file
Run your bicep file to test it out. Now you can see the cloud init file is working, docker is automatically installed.
Reference:
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK