You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
2.8 KiB
159 lines
2.8 KiB
terraform {
|
|
required_providers {
|
|
gridscale = {
|
|
source = "gridscale/gridscale"
|
|
}
|
|
|
|
dnsimple = {
|
|
source = "dnsimple/dnsimple"
|
|
version = "0.11.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "dnsimple" {
|
|
# Configuration options
|
|
token = "${var.dnsimple_token}"
|
|
account = "${var.dnsimple_account}"
|
|
}
|
|
|
|
variable "dnsimple_token" {
|
|
type = string
|
|
default = ""
|
|
}
|
|
|
|
variable "dnsimple_account" {
|
|
type = string
|
|
default = ""
|
|
}
|
|
|
|
variable "dnsimple_domain" {
|
|
type = string
|
|
default = "example.net"
|
|
}
|
|
|
|
variable "hostname_fqdn" {
|
|
type = string
|
|
default = "my-hostname.example.net"
|
|
}
|
|
|
|
variable "hostname" {
|
|
type = string
|
|
default = "my-hostname"
|
|
}
|
|
|
|
variable "hostname_alias" {
|
|
type = string
|
|
default = "my-hostname-alias"
|
|
}
|
|
|
|
variable "cores" {
|
|
type = number
|
|
default = 2
|
|
}
|
|
|
|
variable "memory" {
|
|
type = number
|
|
default = 4
|
|
}
|
|
|
|
variable "capacity" {
|
|
type = number
|
|
default = 20
|
|
}
|
|
|
|
variable "ansible_sshkey" {
|
|
type = string
|
|
default = ""
|
|
}
|
|
|
|
data "gridscale_public_network" "pubnet" {
|
|
}
|
|
|
|
resource "gridscale_server" "server" {
|
|
name = var.hostname_fqdn
|
|
cores = var.cores
|
|
memory = var.memory
|
|
power = true
|
|
ipv4 = gridscale_ipv4.ip.id
|
|
hardware_profile = "q35"
|
|
|
|
storage {
|
|
object_uuid = gridscale_storage.storage.id
|
|
}
|
|
|
|
network {
|
|
object_uuid = data.gridscale_public_network.pubnet.id
|
|
}
|
|
}
|
|
|
|
resource "gridscale_storage" "storage" {
|
|
name = "p.hazardous.org-storage"
|
|
capacity = var.capacity
|
|
template {
|
|
template_uuid = data.gridscale_template.debian.id
|
|
hostname = var.hostname
|
|
sshkeys = [gridscale_sshkey.ssh_key.id]
|
|
}
|
|
}
|
|
|
|
resource "local_file" "ansible_inventory" {
|
|
content = "${gridscale_server.server.name} ansible_host=${gridscale_ipv4.ip.ip} ansible_user=root"
|
|
filename = "hosts"
|
|
file_permission = "0644"
|
|
}
|
|
|
|
resource "null_resource" "storage_provisioner" {
|
|
|
|
triggers = {
|
|
storage_id = gridscale_storage.storage.id
|
|
}
|
|
|
|
provisioner "remote-exec" {
|
|
inline = ["echo ${gridscale_server.server.id}"]
|
|
connection {
|
|
user = "root"
|
|
port = 22
|
|
host = gridscale_ipv4.ip.ip
|
|
timeout = "2m"
|
|
}
|
|
}
|
|
|
|
provisioner "local-exec" {
|
|
command = "ansible-playbook --ssh-common-args '-o StrictHostKeyChecking=no' --inventory hosts main.yml"
|
|
}
|
|
}
|
|
|
|
data "gridscale_template" "debian" {
|
|
name = "Debian 11"
|
|
}
|
|
|
|
resource "gridscale_sshkey" "ssh_key" {
|
|
name = "ed"
|
|
sshkey = var.ansible_sshkey
|
|
}
|
|
|
|
resource "gridscale_ipv4" "ip" {
|
|
name = "p.hazardous.org-ip"
|
|
}
|
|
|
|
output "server_ip" {
|
|
value = gridscale_ipv4.ip.ip
|
|
}
|
|
|
|
resource "dnsimple_zone_record" "foobar" {
|
|
zone_name = "${var.dnsimple_domain}"
|
|
name = var.hostname
|
|
value = gridscale_ipv4.ip.ip
|
|
type = "A"
|
|
ttl = 3600
|
|
}
|
|
|
|
resource "dnsimple_zone_record" "foobar2" {
|
|
zone_name = "${var.dnsimple_domain}"
|
|
name = var.hostname_alias
|
|
value = gridscale_ipv4.ip.ip
|
|
type = "A"
|
|
ttl = 3600
|
|
}
|