61 lines
1.5 KiB
Terraform
61 lines
1.5 KiB
Terraform
|
|
provider "hcloud" {
|
||
|
|
token = var.hcloud_token
|
||
|
|
endpoint = var.hcloud_endpoint
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "random_string" "prefix" {
|
||
|
|
length = 13
|
||
|
|
special = false
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "hcloud_ssh_key" "sshpubkey" {
|
||
|
|
name = "Terraform"
|
||
|
|
public_key = file(var.ssh_pub_key)
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "hcloud_server" "node" {
|
||
|
|
name = random_string.prefix.result
|
||
|
|
image = var.image
|
||
|
|
server_type = var.server_type
|
||
|
|
#datacenter = var.datacenter # location and datacenter are mutually exclusive
|
||
|
|
location = var.location
|
||
|
|
backups = false
|
||
|
|
ssh_keys = [hcloud_ssh_key.sshpubkey.id]
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "hcloud_volume" "volume" {
|
||
|
|
name = random_string.prefix.result
|
||
|
|
size = var.volume_size_GB
|
||
|
|
#server_id = hcloud_server.node.id # server_id and location are mutually exclusive, either specify the the server it is attached to or use hcloud_volume_attachment
|
||
|
|
#automount = true # server must be provided when automount is true
|
||
|
|
location = var.location
|
||
|
|
format = "xfs"
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "hcloud_volume_attachment" "volume_attach" {
|
||
|
|
volume_id = hcloud_volume.volume.id
|
||
|
|
server_id = hcloud_server.node.id
|
||
|
|
automount = true
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "hcloud_floating_ip" "fipv6" {
|
||
|
|
type = "ipv6"
|
||
|
|
home_location = var.location
|
||
|
|
}
|
||
|
|
|
||
|
|
resource "hcloud_floating_ip_assignment" "fipv6_assign" {
|
||
|
|
floating_ip_id = hcloud_floating_ip.fipv6.id
|
||
|
|
server_id = hcloud_server.node.id
|
||
|
|
}
|
||
|
|
|
||
|
|
output "floating_ipv6_addr" {
|
||
|
|
value = hcloud_floating_ip.fipv6.ip_address
|
||
|
|
}
|
||
|
|
|
||
|
|
output "server_ipv6_addr" {
|
||
|
|
value = hcloud_server.node.ipv6_address
|
||
|
|
}
|
||
|
|
|
||
|
|
output "server_ipv4_addr" {
|
||
|
|
value = hcloud_server.node.ipv4_address
|
||
|
|
}
|