OpenBSD - Terraform
Page content
Terraform OpenBSD & Vultr
doas pkg_add git gmake go terraform
cat << EOF
# Go, $(date)
export PATH=$PATH:$(go env GOPATH)/bin
export GOPATH=$(go env GOPATH)
EOF
mkdir -p $GOPATH/src/github.com/vultr; cd $GOPATH/src/github.com/vultr
git clone [email protected]:vultr/terraform-provider-vultr.git
cd $GOPATH/src/github.com/vultr/terraform-provider-vultr
gmake build
main.tf
cat << 'EOF' > main.tf
terraform {
required_providers {
vultr = {
source = "vultr/vultr"
version = "2.12.1"
}
}
}
resource "vultr_instance" "web" {
count = 2
plan = "vc2-1c-1gb"
region = "fra"
hostname = "web-${count.index+1}"
label = "web-${count.index+1}"
}
EOF
Init, Plan, Apply
export TF_VULTR_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
terraform init
terraform plan
terraform apply
main.tf
5 Servers in 5 Regions, each of them has got a uniqe name and the authorized_key file adjusted …
terraform {
required_providers {
vultr = {
source = "vultr/vultr"
version = "2.12.1"
}
}
}
resource "vultr_ssh_key" "my_ssh_key" {
name = "my-ssh-key"
ssh_key = "ssh-ed25519 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
variable "regions" {
type = list(string)
default = ["ewr", "lax", "syd", "fra", "sgp"]
}
resource "vultr_instance" "web" {
for_each = toset(var.regions)
region = each.value
os_id = 477
plan = "vc2-1c-1gb"
hostname = "web-${each.value}-1a"
label = "web-${each.value}-1b"
ssh_key_ids = ["6ed5xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
enable_ipv6 = true
backups = "disabled"
activation_email = false
}
and go
terraform apply -auto-approve
return List of vm/ips
cat << 'EOF' > main.tf
terraform {
required_providers {
vultr = {
source = "vultr/vultr"
version = "2.12.1"
}
}
}
resource "vultr_ssh_key" "my_ssh_key" {
name = "my-ssh-key"
ssh_key = "ssh-ed25519 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
variable "regions" {
type = list(string)
default = ["ewr", "lax", "syd", "fra", "sgp"]
}
resource "vultr_instance" "server" {
for_each = toset(var.regions)
region = each.value
os_id = 477
plan = "vc2-1c-1gb"
hostname = "debian-${each.value}-1a"
label = "debian-${each.value}-1b"
ssh_key_ids = ["6ed5xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
enable_ipv6 = true
backups = "disabled"
activation_email = false
}
output "server_ips" {
value = {
for server in vultr_instance.server :
server.region => server.main_ip
}
}
EOF
server_ips = {
"ewr" = "108.61.157.113"
"fra" = "95.179.248.125"
"lax" = "45.32.86.59"
"sgp" = "45.77.255.201"
"syd" = "149.28.169.159"
}
Any Comments ?
sha256: ff4bcc203bd0a478ecda752de23fce2607d096df473e5c098cad89fc2b210cbb