How to Update Cloud-Init User Data on a Vultr Cloud Compute Instance

How to Update Cloud-Init User Data on a Vultr Cloud Compute Instance

A guide for modifying the initialization scripts and configuration data on your Vultr instance after deployment.


Cloud-Init enables the automatic initialization and configuration of instances during the initial boot phase. It runs user data scripts to customize an instance, install applications, and configure specific packages or services.

Follow this guide to update Cloud-Init user data on a Vultr Cloud Compute instance using the Vultr Customer Portal, API, CLI, or Terraform.

Vultr Customer Portal

  1. Navigate to Products and click Compute.
  2. Click your target Vultr Cloud Compute instance to open its management page.
  3. Navigate to the User-Data tab.
  4. Enter your script or cloud config in the Cloud-Init User-Data field.
  5. Click Update to apply the changes.

Vultr API

  1. Send a GET request to the List Instances endpoint and note your target instance’s ID.
    console
    $ curl "https://api.vultr.com/v2/instances" \
      -X GET \
      -H "Authorization: Bearer ${VULTR_API_KEY}"
    
  2. Send a PATCH request to the Update Instance endpoint to update the instance’s Cloud-Init user data.
    console
    $ curl "https://api.vultr.com/v2/instances/{instance-id}" \
      -X PATCH \
      -H "Authorization: Bearer ${VULTR_API_KEY}" \
      -H "Content-Type: application/json" \
      --data '{
        "user_data" : "<cloud-init-data>",
      }'

Vultr CLI

  1. List all available instances and note your target instance’s ID.
    console
    $ vultr-cli instance list
    
  2. Upload new Cloud-Init user data to the instance from a file on your workstation.
    console
    $ vultr-cli instance user-data set <instance-id> --userdata "<script-path>"

Terraform

Cloud-Init user data can only be set during instance creation in Terraform and cannot be updated on an existing instance without recreating it.

  1. Open your Terraform configuration for the new Cloud Compute instance.
  2. Add the user_data argument to the instance resource to run a script at first boot.
    terraform
    resource "vultr_instance" "cc" {
        # ...existing fields (region, plan, os_id, label, etc.)
    
        user_data = <<-EOT
        #!/bin/bash
        apt-get update -y
        apt-get install -y nginx
        systemctl enable --now nginx
        EOT
    }
    
  3. Apply the configuration and observe the following output:
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

How to Update Cloud-Init User Data on a Vultr Cloud Compute Instance A guide for modifying the initialization scripts and configuration data on your Vultr instance after deployment. Cloud-Init enables the automatic initialization and configuration of instances during the initial boot phase. It runs user data scripts to customize an…

How to Update Cloud-Init User Data on a Vultr Cloud Compute Instance A guide for modifying the initialization scripts and configuration data on your Vultr instance after deployment. Cloud-Init enables the automatic initialization and configuration of instances during the initial boot phase. It runs user data scripts to customize an…

Leave a Reply

Your email address will not be published. Required fields are marked *