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

[Feature] - Add Nixos to ISOs / Ability to ssh with a root user or nixos user on nixos #507

Open
AOrps opened this issue Aug 5, 2024 · 1 comment

Comments

@AOrps
Copy link

AOrps commented Aug 5, 2024

Is your feature request related to a problem? Please describe.
I wish I could use Nixos.

Describe the solution you'd like
I would like to be able to ssh into the box with my ssh key. It would be a nice feature to be able to work with Nixos out of the box. Alternatively, writing the ssh authorized keys to the following place would also be wonderous: /root/.ssh/authorized_keys.

Describe alternatives you've considered
cloud-init didn't work for me. I also tried ansible_host: https://registry.terraform.io/providers/ansible/ansible/latest/docs/resources/host and no dice there either.

Additional context

# ----- main.tf
terraform {
  required_providers {
    # docs: https://registry.terraform.io/providers/vultr/vultr/latest
    vultr = {
      source  = "vultr/vultr"
      version = "2.21.0"
    }
  }
}

provider "vultr" {
  api_key     = var.vultr_api_key
  rate_limit  = 100
  retry_limit = 3
}

resource "vultr_ssh_key" "ssh_key" {
  name = "pubsshkey"
  ssh_key = var.sshkey_id
}

resource "vultr_iso_private" "nix_iso" {
  url = "https://channels.nixos.org/nixos-24.05/latest-nixos-minimal-x86_64-linux.iso"
}

resource "vultr_instance" "vultr_instance_1" {
  plan      = var.plan
  region    = var.region
  iso_id    = vultr_iso_private.nix_iso.id
  hostname  = var.hostname
  ssh_key_ids = [vultr_ssh_key.ssh_key.id]
}

# ------- variables.tf
variable "vultr_api_key" {
  description = "API Key to enable usage of vultr"
  type = string
}

variable "plan" {
  type = string
}

variable "region" {
  type = string
}

variable "hostname" {
  type = string
}

variable "sshkey_id" {
  type = string
}

# -------- prod.auto.tfvars
vultr_api_key=""
plan="vc2-1c-1gb"
region=""
hostname="vultr_instance"
sshkey_id="ssh-ed25519 .....   user@vultr"
@AOrps
Copy link
Author

AOrps commented Aug 5, 2024

This is what the main.tf file looked like after trying ansible.

terraform {
  required_providers {
    # docs: https://registry.terraform.io/providers/vultr/vultr/latest
    vultr = {
      source  = "vultr/vultr"
      version = "2.21.0"
    }

    ansible = {
      source = "ansible/ansible"
      version = "1.3.0"
    }
  }
}

provider "vultr" {
  api_key     = var.vultr_api_key
  rate_limit  = 100
  retry_limit = 3
}

resource "vultr_ssh_key" "ssh_key" {
  name = "pubsshkey"
  ssh_key = var.sshkey_id
}

resource "vultr_iso_private" "nix_iso" {
  url = "https://channels.nixos.org/nixos-24.05/latest-nixos-minimal-x86_64-linux.iso"
}

resource "ansible_host" "host" {
  name = var.hostname

  variables = {
    ansible_root = "root"
    ansible_host = vultr_instance.vultr_instance_1.main_ip
    ansible_password = "dummypassword"
  }
}

resource "vultr_instance" "vultr_instance_1" {
  plan      = var.plan
  region    = var.region
  iso_id    = vultr_iso_private.nix_iso.id
  hostname  = var.hostname
  ssh_key_ids = [vultr_ssh_key.ssh_key.id]
}

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

No branches or pull requests

1 participant