-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to provision an custom image and make use of user_data
#18
Comments
user_data does not work in a custom image unless you have specifically implemented it into your custom image. E.g. if you use our public template for Debian, user_data should work normally. Are you handling the user_data field somehow in your image, or is your image based on one of our public templates by any chance? If you need to implement this into your custom image, you could for example try with cloud-init & our metadata API. UpCloud has a small tutorial for the metadata API: https://upcloud.com/community/tutorials/upcloud-metadata-service/ . The metadata API needs to be enabled on server creation. Let me know if this helps 😊 |
Thanks for the reply. The base image for packer is one of your public templates I also tested |
Ahh, yeah, at least I was under the impression that it should work 😲 Weird! 😄 I will ask some UpCloudians if they know what's up & if someone could investigate this more deeply. |
Hi @jlarfors
The caveat with Debian 11 template is that there isn't a recent-enough cloud-init version available in main repository, so to get it working you might need to built cloud-init from source, or install from testing (which might have some side effects, so it's not really optimal production setup). packer {
required_plugins {
upcloud = {
version = "v1.2.0"
source = "github.com/UpCloudLtd/upcloud"
}
}
}
source "upcloud" "vault" {
username = "${var.username}"
password = "${var.password}"
zone = "fi-hel1"
storage_name = "Debian GNU/Linux 11"
template_prefix = "vault-image"
}
build {
sources = ["source.upcloud.vault"]
provisioner "shell" {
inline = [
"cp /etc/apt/sources.list /etc/apt/sources.list.bak",
"echo 'deb http://deb.debian.org/debian/ testing main' >> /etc/apt/sources.list",
"apt-get update",
"DEBIAN_FRONTEND=noninteractive apt -y install cloud-init=21.4-1",
"rm -rf /var/lib/cloud",
"cp -f /etc/apt/sources.list.bak /etc/apt/sources.list",
# ... more provisioning stuff here
]
}
} And then with Terraform: resource "upcloud_server" "vault" {
hostname = "vault-server"
zone = "fi-hel1"
plan = "1xCPU-1GB"
metadata = true
template {
# Custom image based on Debian 11
storage = var.custom_image
size = 25
}
network_interface {
type = "public"
}
login {
keys = [
"my-ssh-pub-key"
]
}
// Simple user_data test
user_data = "#!/bin/bash\ntouch /tmp/test.txt"
} Note that Please also note that default cloud-init config disables root login and creates a I hope this clears things out a bit, let us know if you have any other questions :) |
Has there been any work on supporting In our case we are just using the API. The API documentation describes We want to get rid of all SSH connections as root to our VMs for security reasons so that's not good enough for us. |
I also haven't tried with Packer, but I can confirm I've personally used UpCloud's Debian 12, Ubuntu 22 and Ubuntu 24 templates to create the custom image, and then supplied For example, here's what I've supplied to the UpCloud API to create an
|
Sorry, we are not actually using packer, I just thought that the underlying problem is the same we are having by pushing images directly via the UpCloud API. We are building from scratch our images, we use the |
Yeah, I haven't used Packer lately either 😊 If you are using Note also that you need to have metadata enabled when you create the server. |
Hello, I am building a custom image using Packer that I later want to provision with Terraform and make use of
user_data
when provisioning with Terraform.However, seems the
user_data
has no effect when provisioning with Terraform.Any way to get this to work?
Packer
We have something liek this for packer:
Terraform
And something liek this with Terraform:
The text was updated successfully, but these errors were encountered: