Terraform support for UpCloud (#7360)

* terraform support for UpCloud

* terraform support for UpCloud

* terraform support for UpCloud

* terraform support for UpCloud

* terraform support for UpCloud

* terraform support for UpCloud

* terraform support for UpCloud

* Updates to README.md and main.tf files

* formatting and updating readme

* added a .terraform_validate CI job

* fixed format issue

* added sample inventory

* added symbolic link to group_vars

* added missing tf variables and minor fixes

* added text formatting

* minor formatting fixes
This commit is contained in:
Ewnetu Bayuh Lakew
2021-03-15 09:41:04 +01:00
committed by GitHub
parent 5dba53a223
commit 5c5bf41afe
14 changed files with 475 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
resource "upcloud_server" "master" {
for_each = {
for name, machine in var.machines :
name => machine
if machine.node_type == "master"
}
hostname = "${each.key}.${var.hostname}"
cpu = each.value.cpu
mem = each.value.mem
zone = var.zone
template {
storage = var.template_name
size = each.value.disk_size
}
# Network interfaces
network_interface {
type = "public"
}
network_interface {
type = "utility"
}
# Include at least one public SSH key
login {
user = var.username
keys = var.ssh_public_keys
create_password = false
}
}
resource "upcloud_server" "worker" {
for_each = {
for name, machine in var.machines :
name => machine
if machine.node_type == "worker"
}
hostname = "${each.key}.${var.hostname}"
cpu = each.value.cpu
mem = each.value.mem
zone = var.zone
template {
storage = var.template_name
size = each.value.disk_size
}
# Network interfaces
network_interface {
type = "public"
}
# Include at least one public SSH key
login {
user = var.username
keys = var.ssh_public_keys
create_password = false
}
}

View File

@@ -0,0 +1,14 @@
output "master_ip" {
value = {
for instance in upcloud_server.master :
instance.hostname => instance.network_interface[0].ip_address
}
}
output "worker_ip" {
value = {
for instance in upcloud_server.worker :
instance.hostname => instance.network_interface[0].ip_address
}
}

View File

@@ -0,0 +1,25 @@
variable "zone" {
type = string
}
variable "hostname"{
default ="example.com"
}
variable "template_name"{}
variable "username"{}
variable "machines" {
description = "Cluster machines"
type = map(object({
node_type = string
cpu = string
mem = string
disk_size = number
}))
}
variable "ssh_public_keys" {
type = list(string)
}

View File

@@ -0,0 +1,10 @@
terraform {
required_providers {
upcloud = {
source = "UpCloudLtd/upcloud"
version = "~>2.0.0"
}
}
required_version = ">= 0.13"
}