Configure a VM with user data
You can add user data to a VM (Virtual Machine) to include a more customized configuration or any type of data. This user data can contain any type of information, such as a script or additional data. You can also define tags to give specific instructions on the location of the VM or its IP addresses.
User data is data associated with the VM by the user when it is created. Although the VM can access user data at any time, it is taken into account only when the VM is created. However, you can create a script in the image used to create the VM that requires user data to be taken into account on every start of the VM. This lets you modify it, then stop and restart the VM so that these changes are applied.
To obtain information about the user data of a VM, enter the following address in the terminal of the VM or in a web browser: 169.254.169.254/latest/user-data.
Permissions
This action requires the following IAM (Identity and Access Management) permissions:
- compute.vm.update
Add a script or text to user data
You can include a script or additional data in the user data of a VM. This script can contain text variables and can be configured so that the VM runs a specific action on start, for example, automatically downloading a file from a bucket. This lets you customize and automate the actions of the VM as soon as it starts.
User data must be encoded in Base64. The size of the Base64-encoded user data must not exceed 500 kibibytes (KiB).
This user data can be run on every start of the VM, if the VM contains a suitable script:
- Console
- API
- Terraform
In the "Create VM" dialog box in the Numspot console:
- From the left-hand side menu, click Compute → VM to access the list of VM;
- Click the Create a VM button at the top right of the screen to launch the VM creation wizard;
- Follow the wizard steps up to the "User Data" step;
- Enter your user data in the field provided for this purpose;
- Continue creating the VM.
For Linux VM, you must create a script that retrieves and runs the user data.
For Windows VM, you can type a script in one of the following wrappers to run it on start:
# autoexecutepowershellnopasswd
<your_script>
# autoexecutepowershellnopasswd
Runs the powershell script without init password administrator. The script is launched as the administrator user.
# autoexecutepowershell
<your_script>
# autoexecutepowershell
Runs the powershell script with init password administrator. The script is launched as the administrator user.
# autoexecutevbs
<your_script>
# autoexecutevbs
Runs the vbscript script with init password administrator. The script is launched as the administrator user.
If the start script encounters one of the wrappers above, the script is saved in a VB or in a Powershell file in its /userdata, and runs these files when the VM starts.
You can separate the commands in a script using line breaks, and thus run all the commands you want in a Windows Powershell terminal.
The Terraform documentation is available on the Numspot registry ↗.