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 sshkey from templatefile #71

Merged
merged 1 commit into from
May 22, 2023

Conversation

futuretea
Copy link
Contributor

@futuretea futuretea commented Jan 31, 2023

Signed-off-by: futuretea [email protected]

Related issues
harvester/harvester#3385

Test plan

docker cp ~/.ssh/id_rsa.pub tf:/data/id_rsa.pub
  • Create a test config file in the test container
vim main.tf
resource "harvester_network" "vlan1" {
  name      = "vlan1"
  namespace = "harvester-public"

  vlan_id = 1

  route_mode           = "auto"
  route_dhcp_server_ip = ""

  cluster_network_name = "mgmt"
}


resource "harvester_image" "ubuntu" {
  name      = "ubuntu"
  namespace = "harvester-public"

  display_name = "focal-server"
  source_type  = "download"
  url          = "http://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img"
}

resource "harvester_ssh_key" "mysshkey" {
  name      = "rancher"
  namespace = "harvester-public"

  public_key = "${templatefile("id_rsa.pub", {})}"
}

resource "harvester_virtualmachine" "ubuntu" {
  count = 1
  name                 = "ubuntu"
  namespace            = "harvester-public"
  restart_after_update = true

  description = "test ubuntu"
  tags = {
    ssh-user = "ubuntu"
  }

  cpu    = 1
  memory = "1Gi"

  run_strategy = "RerunOnFailure"
  hostname     = "ubuntu"
  machine_type = "q35"

  ssh_keys = [
    harvester_ssh_key.mysshkey.id
  ]

  network_interface {
    name           = "nic-1"
    network_name = harvester_network.vlan1.id

#    wait_for_lease = true
  }

  disk {
    name       = "rootdisk"
    type       = "disk"
    size       = "10Gi"
    bus        = "virtio"
    boot_order = 1

    image       = harvester_image.ubuntu.id
    auto_delete = true
  }

  cloudinit {
    user_data    = <<-EOF
      #cloud-config
      package_update: true
      packages:
      - qemu-guest-agent
      runcmd:
      - - systemctl
        - enable
        - --now
        - qemu-guest-agent.service
      password: rancher
      chpasswd:
        expire: false
      ssh_pwauth: true
      ssh_authorized_keys:
        - >-
          ${templatefile("id_rsa.pub", {})}
      EOF
    network_data = ""
  }
}
  • apply
terraform apply -auto-approve
  • ssh to the vm

Copy link
Member

@FrankYang0529 FrankYang0529 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

Copy link

@guangbochen guangbochen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I saw duplicate ssh keys, it should be caused by the example tf file that contains both ssh_keys and templatefile config.

@futuretea
Copy link
Contributor Author

futuretea commented May 22, 2023

LGTM, I saw duplicate ssh keys, it should be caused by the example tf file that contains both ssh_keys and templatefile config.

@guangbochen I can't reproduce this issue
image

Copy link
Member

@bk201 bk201 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@futuretea futuretea merged commit c1ea667 into harvester:master May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants