Question

Is it possible to provide userdata as a mime multi part archive?

Posted August 20, 2021 86 views
TerraformDigitalOcean Droplets

The cloud-init docs state that userdata can be provided as a gzipped mime multipart archive: https://cloudinit.readthedocs.io/en/latest/topics/format.html#mime-multi-part-archive

I would like to make use of this as I have several userdata ‘modules’ that I can mix-and-match depending on the kind of host I’m building.

I’m building the userdata archive using terraform’s built in cloud-init provider, here: https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs

To send the archive to the droplet I’m grabbing the rendered version from the datasource and passing it in as the user-data property on the droplet.

Something like this:

data "cloudinit_config" "app_server_config" {
  part {
    content_type = "text/cloud-config"
    content = templatefile("${path.module}/secret_config.yml.tpl", {
      app_name = "app",
      secret_key = "foo"
    })
  }

  part {
    content_type = "text/cloud-config"
    content = templatefile("${path.module}/database_config.yml.tpl", {
      app_name = "app"
    })
  }

  part {
    content_type = "text/cloud-config"
    content = templatefile("${path.module}/puma_config.yml.tpl", {
      app_name = "app"
    })
  }
}


resource "digitalocean_droplet" "app_server" {
  ...
  user_data = data.app_server_config.rendered
  ...
}

Once the droplet is running, I can see that the gzipped version of the userdata is present through the metadata API, but the cloud-init-output log warns with the following:

2021-08-20 17:58:17,248 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'b'H4sIAAAAAAAA/9xWS2/bRhC+'...'

Should this be working? I’m unsure why cloud-init isn’t interpreting the provided archive correctly, to the best of my knowledge I’m generating it correctly.

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!