Closed devurandom closed 5 years ago
Hello,
first of all, the selector is the label selector. You can find information about our label system here: https://docs.hetzner.cloud/#overview-label-selector
The other problem: Could you please provide a terraform file, which shows your problem?
Edit: I have reproduced it myself while looking at #72 . Solution is on the way :)
Thanks for the quick patch!
However, I am now on provider.hcloud v1.8.1 and still experience the issue.
packer-service.json:
{
"builders": [{
"type": "hcloud",
"server_type": "cx11",
"image": "centos-7",
"location": "nbg1",
"snapshot_name": "java-1.8.0-openjdk",
"snapshot_labels": {
"nodetype": "service"
},
"ssh_username": "root",
"ssh_pty": true
}],
"provisioners": [{
"type": "shell",
"inline": [
"sudo yum -y install java-1.8.0-openjdk"
]
}]
}
main.tf:
provider "hcloud" {}
data "hcloud_ssh_key" "ssh_key" {
name = "${var.ssh_key_name}"
}
data "hcloud_image" "service" {
# Snapshot, select by label
selector = "nodetype == service"
most_recent = true
}
resource "hcloud_server" "service" {
name = "service"
server_type = "cx11"
image = "${data.hcloud_image.service.id}"
ssh_keys = ["${data.hcloud_ssh_key.ssh_key.id}"]
}
packer build packer-service.json
and wait until it says ==> hcloud: Creating snapshot ...
terraform plan
creating
image
attribute of terraform plan
's output with the output of hcloud image list -o columns=id,description,status
You need to wait until the snapshot is finished, not while it is creating.
You need to wait until the snapshot is finished, not while it is creating.
Exactly that is my problem. The datasource considers images with status creating
valid images, and there is no way to restrict it to images with status available
.
Yep, but this is indeed. You can not create a snapshot and then as long as it is creating create a server from it. You can only create servers from complete snapshots (when they are available).
For your use case, you need to wait until packer is finished. This isn't a bug in the terraform provider.
This is a deployment automation project for a team of developers. One developer cannot and should not have to control the time when another developer runs Packer to create a new version of the image. Otherwise we end up with an image control shingle.
P.S. I honestly believe that having a way to restrict the hcloud_image
datasource to pick only available
images when using a selector
and most_recent
would be immensely beneficial. And that mode should be on by default, since there appears to be little one could do with an image that is not available
.
Implemented, and will be released as 1.9.0 :)
The
hcloud_image
datasource can point to images which are not available (e.g. because the image is a snapshot that is still being created). Trying to create ahcloud_server
from such an image will fail:To add insult to injury, there appears to be no way to limit the selected images to available ones. Setting
selector = "status == available"
(orselector = "hetzner.cloud/status == available"
) will error out:(Note how the name of the datasource is output twice on the same row, which appears to be a different bug.)