Skip to content
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

support packer build with ipv6 only #188

Closed
kranurag7 opened this issue Jun 3, 2024 · 9 comments · Fixed by #190 or #183
Closed

support packer build with ipv6 only #188

kranurag7 opened this issue Jun 3, 2024 · 9 comments · Fixed by #190 or #183
Assignees

Comments

@kranurag7
Copy link

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

@jooola jooola self-assigned this Jun 5, 2024
@jooola jooola removed the help wanted label Jun 5, 2024
jooola added a commit that referenced this issue Jun 5, 2024
Allow disabling the server's public IPs, and use the first available IP
to connect to it (IPv4, IPv6, first private network IP).

Closes #188
jooola pushed a commit that referenced this issue Jun 5, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.5.0](v1.4.0...v1.5.0)
(2024-06-05)


### Features

* add HCP packer support
([#122](#122))
([85435ef](85435ef))
* allow disabling the server public ips
([#190](#190))
([82e6cdb](82e6cdb)),
closes
[#188](#188)


### Bug Fixes

* ensure the upgrade server type is not nil
([#182](#182))
([d297dcb](d297dcb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@kranurag7
Copy link
Author

@jooola thanks for working on it.

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

  • packer config (I'm using @apricote flatcar packer config here)
  • I've include one extra line public_ipv4_disabled = true and so far I can see that the builder doesn't get ipv4 address but it also gets ssh connection timed out.
  • In the project, I don't have any other servers running if that's required.
Details

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://github.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} ",
    ]
  }
}

  • build logs
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
Copy link
Member

jooola commented Jun 5, 2024

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

@jooola
Copy link
Member

jooola commented Jun 5, 2024

Will be fixed with #192

@kranurag7
Copy link
Author

kranurag7 commented Jun 6, 2024

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.

  • hcloud server list
$ hcloud server list
ID         NAME                                          STATUS    IPV4   IPV6                      PRIVATE NET   DATACENTER   AGE
48415982   packer-66617cbc-4945-bf22-9ad2-4319d0ac68e4   running   -      2a01:4f8:c013:3d45::/64   -             fsn1-dc14    2m

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"

  • hcloud server list for scenario 2
$ hcloud server list
ID         NAME                                          STATUS    IPV4   IPV6                      PRIVATE NET   DATACENTER   AGE
48416165   packer-66617d26-bb6b-5ddf-bbb6-185924f752c3   running   -      2a01:4f8:c013:4a59::/64   -             fsn1-dc14    1m

Extra details

  • I'm working on a fresh project, where there's no per-existing server and there's not any other hcloud resource as well. I just created a project, copy pasted the token and ran packer build.

@jooola
Copy link
Member

jooola commented Jun 6, 2024

I'll have a look.

@jooola
Copy link
Member

jooola commented Jun 6, 2024

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
Copy link
Member

jooola commented Jun 6, 2024

We will have to wait for hashicorp/packer-plugin-sdk#246 to be merged and released. Might take some time.

@jooola
Copy link
Member

jooola commented Jun 18, 2024

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

@kranurag7
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants