hetznercloud / packer-plugin-hcloud

Packer plugin for Hetzner Cloud Builder
https://developer.hashicorp.com/packer/integrations/hetznercloud/hcloud
Mozilla Public License 2.0
23 stars 21 forks source link

support packer build with ipv6 only #188

Closed kranurag7 closed 3 months ago

kranurag7 commented 4 months ago

Please search the existing issues for relevant feature requests, and use the reaction feature (https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to add upvotes to pre-existing requests.

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

As of now, when I run packer build, the server gets ipv4 and ipv6 address both. I would like to avoid ipv4 here.

Use Case(s)

I'm hitting limit on my project where I cannot have more ipv4 addresses.

Could not create server: Primary IP limit exceeded (resource_limit_exceeded)

Independent of this as well I think it will be great if the project supports that.

Potential configuration

Potential References

kranurag7 commented 3 months ago

@jooola thanks for working on it.

I'm getting timed out if I use the following:

Details

```hcl packer { required_plugins { hcloud = { source = "github.com/hetznercloud/hcloud" version = "~> 1.5.0" } } } variable "hcloud_token" { type = string default = "${env("HCLOUD_TOKEN")}" sensitive = true } variable "hcloud_server_type" { type = map(string) default = { # x86 = "cx11" arm = "cax11" } } variable "channel" { type = string default = "beta" } variable "version" { type = string default = "current" } variable "labels" { // Available replacements: // $architecture // $channel // $version - if "current" was specified, this is resolved to the actual version type = map(string) default = { os = "flatcar" flatcar-channel = "$channel" version = "$version" architecture = "$architecture" } } locals { architectures = ["x86", "arm"] // If the user wants the "current" version, we still want to make the // actual version id available through labels + snapshot description // // regex matches: FLATCAR_VERSION=1234.0.0 version = regex("FLATCAR_VERSION=(\\d+\\.\\d+\\.\\d+)", data.http.version_info.body)[0] } data "http" "version_info" { // We assume that both boards have the same version url = "https://${var.channel}.release.flatcar-linux.net/amd64-usr/${var.version}/version.txt" } source "hcloud" "flatcar" { token = var.hcloud_token image = "ubuntu-22.04" location = "fsn1" rescue = "linux64" ssh_username = "root" } build { dynamic "source" { for_each = local.architectures labels = ["hcloud.flatcar"] content { name = source.value server_type = var.hcloud_server_type[source.value] snapshot_name = "flatcar-${var.channel}-${local.version}-${source.value}" public_ipv4_disabled = true snapshot_labels = { for k, v in var.labels : k => replace(replace(replace(v, "$channel", var.channel), "$version", local.version), "$architecture", source.value) } } } provisioner "shell" { inline = [ # Download script and dependencies "apt-get -y install gawk", "curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install", "chmod +x flatcar-install", # Install flatcar "./flatcar-install -s -o hetzner -C ${var.channel} -V ${var.version} ", ] } } ```


hcloud.arm: output will be in this color.

==> hcloud.arm: Validating server types: cax11
==> hcloud.arm: Validating snapshot name: flatcar-beta-3941.1.0-arm
==> hcloud.arm: Creating temporary RSA SSH key for instance...
==> hcloud.arm: Uploading temporary SSH key for instance...
==> hcloud.arm: Creating server...
    hcloud.arm: Using image '103908130'
==> hcloud.arm: Enabling Rescue Mode...
==> hcloud.arm: Rebooting server...
==> hcloud.arm: Using SSH communicator to connect: 2a01:4f8:c013:4a59::
==> hcloud.arm: Waiting for SSH to become available...
==> hcloud.arm: Timeout waiting for SSH.
==> hcloud.arm: Destroying server...
==> hcloud.arm: Deleting temporary SSH key...
Build 'hcloud.arm' errored after 5 minutes 30 seconds: Timeout waiting for SSH.

==> Wait completed after 5 minutes 30 seconds

==> Some builds didn't complete successfully and had errors:
--> hcloud.arm: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.
jooola commented 3 months ago

Hmm, the ipv6 address is not right. I'll have look.

jooola commented 3 months ago

Will be fixed with #192

kranurag7 commented 3 months ago

Hey @jooola I'm still facing this issue. I am using packer latest version and packer-plugin-hcloud is also on latest which is 1.5.1

environment details

$ packer version
Packer v1.11.0
$ packer plugins installed
/home/k7/.config/packer/plugins/github.com/hetznercloud/hcloud/packer-plugin-hcloud_v1.5.1_x5.0_linux_amd64

scenario 1

$ packer validate foo.json
The configuration is valid.
$ packer build foo.json
hcloud: output will be in this color.

==> hcloud: Validating server types: cx41
==> hcloud: Validating snapshot name: packer-1717664956
==> hcloud: Creating temporary RSA SSH key for instance...
==> hcloud: Uploading temporary SSH key for instance...
==> hcloud: Creating server...
    hcloud: Using image '67794396'
==> hcloud: Using SSH communicator to connect: 2a01:4f8:c013:3d45::1
==> hcloud: Waiting for SSH to become available...
==> hcloud: Timeout waiting for SSH.
==> hcloud: Destroying server...
==> hcloud: Deleting temporary SSH key...
Build 'hcloud' errored after 5 minutes 18 seconds: Timeout waiting for SSH.

==> Wait completed after 5 minutes 18 seconds

==> Some builds didn't complete successfully and had errors:
--> hcloud: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.

the foo.json file contains "public_ipv4_disabled": true, in builders block.

scenario 2 (using Julian's flatcar repository )

hcloud.arm: output will be in this color.

==> hcloud.arm: Validating server types: cax11
==> hcloud.arm: Validating snapshot name: flatcar-beta-3941.1.0-arm
==> hcloud.arm: Creating temporary RSA SSH key for instance...
==> hcloud.arm: Uploading temporary SSH key for instance...
==> hcloud.arm: Creating server...
    hcloud.arm: Using image '103908130'
==> hcloud.arm: Enabling Rescue Mode...
==> hcloud.arm: Rebooting server...
==> hcloud.arm: Using SSH communicator to connect: 2a01:4f8:c013:4a59::1
==> hcloud.arm: Waiting for SSH to become available...
==> hcloud.arm: Timeout waiting for SSH.
==> hcloud.arm: Destroying server...
==> hcloud.arm: Deleting temporary SSH key...
Build 'hcloud.arm' errored after 5 minutes 27 seconds: Timeout waiting for SSH.

==> Wait completed after 5 minutes 27 seconds

==> Some builds didn't complete successfully and had errors:
--> hcloud.arm: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.

Here I've included public_ipv4_disabled = true in the packer configuration and updated the required version to be version = "~> 1.5.1"

Extra details

jooola commented 3 months ago

I'll have a look.

jooola commented 3 months ago

I am having the following errors:

==> hcloud.example: Waiting for SSH to become available...
2024/06/06 10:00:10 packer-plugin-hcloud_v1.5.1_x5.0_linux_amd64 plugin: 2024/06/06 10:00:10 [DEBUG] TCP connection to SSH ip/port failed: dial tcp: address 2a01:4f9:c012:e095::1:22: too many colons in address
2024/06/06 10:00:15 packer-plugin-hcloud_v1.5.1_x5.0_linux_amd64 plugin: 2024/06/06 10:00:15 [DEBUG] TCP connection to SSH ip/port failed: dial tcp: address 2a01:4f9:c012:e095::1:22: too many colons in address
2024/06/06 10:00:20 packer-plugin-hcloud_v1.5.1_x5.0_linux_amd64 plugin: 2024/06/06 10:00:20 [DEBUG] TCP connection to SSH ip/port failed: dial tcp: address 2a01:4f9:c012:e095::1:22: too many colons in address
2024/06/06 10:00:25 packer-plugin-hcloud_v1.5.1_x5.0_linux_amd64 plugin: 2024/06/06 10:00:25 [DEBUG] TCP connection to SSH ip/port failed: dial tcp: address 2a01:4f9:c012:e095::1:22: too many colons in address

The ipv6 is not properly formatted, should be between brackets : [2a01:4f9:c012:e095::1]:22

I believe this is a packer bug. I'll dig some more on the packer side.

jooola commented 3 months ago

We will have to wait for https://github.com/hashicorp/packer-plugin-sdk/pull/246 to be merged and released. Might take some time.

jooola commented 3 months ago

I was able to build with an ipv6 only server using the new plugin release v1.5.2.

kranurag7 commented 3 months ago

Thanks very much @jooola, I've tested it and it works good on my end too.