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

Set SSH keys in cloud init #10

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ module "supernode" {
prefix_ipv4_id = data.netbox_prefix.primary_ipv4.id
prefix_ipv6_id = netbox_available_prefix.domain_ipv6.id
loopback_prefix_ipv6_id = netbox_prefix.loopback_ipv6.id

vm_ssh_keys = local.ssh_keys
}
5 changes: 5 additions & 0 deletions terraform/modules/supernode/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ variable "vm_resource_pool" {
description = "Proxmox pool to create VM in"
default = "Supernodes2.0"
}

variable "vm_ssh_keys" {
type = list(string)
description = "Public keys to grant access to"
}
4 changes: 3 additions & 1 deletion terraform/modules/supernode/vm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ resource "proxmox_vm_qemu" "supernode" {
agent = 1
os_type = "cloud-init"
ipconfig0 = "ip=dhcp,ip6=${netbox_available_ip_address.management_ipv6.ip_address}"
ciuser = "admin"
sshkeys = join("\n", var.vm_ssh_keys)

define_connection_info = false

lifecycle {
ignore_changes = [
define_connection_info
define_connection_info,
]
}
}
8 changes: 8 additions & 0 deletions terraform/ssh.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data "http" "github_keys" {
for_each = toset(var.ssh_github_users)
url = "https://github.com/${each.key}.keys"
}

locals {
ssh_keys = flatten([for name, resp in data.http.github_keys : split("\n", chomp(resp.response_body))])
}
6 changes: 6 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ variable "primary_prefix_ipv6" {
description = "Prefix to issue primary IPv6 addresses from"
default = "2001:678:b7c::/48"
}

variable "ssh_github_users" {
type = list(string)
description = "Users to gather SSH public keys from GitHub for"
default = ["mraerino", "nomaster"]
}