hetznercloud / packer-plugin-hcloud

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

Attach Network to Server feature - fix Key Pair creation #30

Closed daparm closed 11 months ago

daparm commented 2 years ago

Moin,

In the first commit "025c32b", I let packer SDK take care about handling temporary SSH-Keys. So we are able to specify between key types with the parameter "temporary_key_pair_type" instead of just using default (RSA).

The second commit 15e1551 extends the plugin with the possibility to attache a private network to the created server instance, this comes in handy to overcome Network issues after imaging i.E restrict SSH access to the public network interface.

To be able to attach a network, you need to specify the "network" parameter with a private Network ID, this will attach the created Server to the provided Network.

You can specify the Private IP with the parameter "ip_address", the provided IP has to be in the correct IP Range of the corresponding Subnet. If you don't specify the Private IP, the IP assignment is the first available IP in the Network - if the Network contains multiple Subnets the assignment to a Subnet happens randomly.

To assign Alias IPs use the "alias_ips" parameter. You can assign multiple Alias IPs at once, the rules are the same as with declaring the Private IP - the declared Alias IPs has to be in the valid IP Range of the Subnet.

And then there is also the "connect_with_private_ip" parameter which can be turned to true, to override the default behavior from accessing the public network interface to use the Private IP along with "ip_address".

To call it from a packer build:

Default:

source "hcloud" "debian" {
  image        = "debian-11"
  location     = "nbg1"
  server_type  = "cx11"
  ssh_keys = [ "packer" ]
  token = "${var.hcloud_token}"
}

build {
  sources = ["source.hcloud.debian"]
}

Connect to Private Network Interface:

source "hcloud" "debian" {
  image        = "debian-11"
  location     = "nbg1"
  server_type  = "cx11"
  ssh_keys = [ "packer" ]
  token = "${var.hcloud_token}"
  ssh_username = "root"
  temporary_key_pair_type = "ed25519"
  network = "1234567"
  ip_address = "10.3.0.10"
  alias_ips  = [ "10.3.0.201", "10.3.0.222" ]
  connect_with_private_ip = true
}

build {
  sources = ["source.hcloud.debian"]
}

In last few commits I was just trying to pass the CI :+1:

hashicorp-cla commented 2 years ago

CLA assistant check
All committers have signed the CLA.

daparm commented 2 years ago

Add bunch of new features regarding snapshot lifecycle management and private networking - wrote docs for ssh connection networking and lifeccle management.

nywilken commented 11 months ago

Hi there :wave:, I'm going to close this pull request since there hasn't been any updates to it. But if you are still running into issues please feel free to leave a comment on the change and we will gladly reopen.