civo terraform boilerplates

This commit is contained in:
Christian 2022-03-04 17:38:14 +01:00
parent fdd48b9c70
commit cda48ece9d
6 changed files with 214 additions and 0 deletions

View File

@ -0,0 +1,9 @@
# CIVO Credentials
# ---
# Credential Variables needed for CIVO
# Civo Config
variable "civo_token" {
description = "Civo API Token"
type = string
}

View File

@ -0,0 +1,18 @@
# CIVO Kubernetes
# ---
# Templates to create a Kubernetes Cluster on CIVO
# Create a new Kubernetes Cluster
resource "civo_kubernetes_cluster" "your-kubernetes-cluster" {
name = "your-kubernetes-cluster"
applications = ""
num_target_nodes = 2
target_nodes_size = element(data.civo_size.xsmall.sizes, 0).name
}
# (Optional) Time Sleep elements for other Objects that need to wait a few seconds after the Cluster deployment
resource "time_sleep" "wait_for_kubernetes" {
depends_on = [civo_kubernetes_cluster.your-kubernetes-cluster]
create_duration = "20s"
}

View File

@ -0,0 +1,20 @@
# CIVO Provider
# ---
# Initial Provider Configuration for CIVO
terraform {
required_version = ">= 0.13.0"
required_providers {
civo = {
source = "civo/civo"
version = "~> 1.0.9"
}
}
}
provider "civo" {
token = var.civo_token
# (optional): Specify your region
# region = "FRA1"
}

139
terraform/civo/query.tf Normal file
View File

@ -0,0 +1,139 @@
# CIVO Queries
# ---
# Query commonly used cloud resources from CIVO API
# CIVO Instance Sizes
data "civo_size" "instance_xsmall" {
filter {
key = "name"
values = ["g3.xsmall"]
match_by = "re"
}
}
data "civo_size" "instance_small" {
filter {
key = "name"
values = ["g3.small"]
match_by = "re"
}
}
data "civo_size" "instance_medium" {
filter {
key = "name"
values = ["g3.medium"]
match_by = "re"
}
}
data "civo_size" "instance_large" {
filter {
key = "name"
values = ["g3.large"]
match_by = "re"
}
}
data "civo_size" "instance_xlarge" {
filter {
key = "name"
values = ["g3.xlarge"]
match_by = "re"
}
}
data "civo_size" "instance_2xlarge" {
filter {
key = "name"
values = ["g3.2xlarge"]
match_by = "re"
}
}
# CIVO Kubernetes Standard Sizes
data "civo_size" "k8s_std_xsmall" {
filter {
key = "name"
values = ["g3.k3s.xsmall"]
match_by = "re"
}
}
data "civo_size" "k8s_std_small" {
filter {
key = "name"
values = ["g3.k3s.small"]
match_by = "re"
}
}
data "civo_size" "k8s_std_medium" {
filter {
key = "name"
values = ["g3.k3s.medium"]
match_by = "re"
}
}
data "civo_size" "k8s_std_large" {
filter {
key = "name"
values = ["g3.k3s.large"]
match_by = "re"
}
}
data "civo_size" "k8s_std_xlarge" {
filter {
key = "name"
values = ["g3.k3s.xlarge"]
match_by = "re"
}
}
data "civo_size" "k8s_std_2xlarge" {
filter {
key = "name"
values = ["g3.k3s.2xlarge"]
match_by = "re"
}
}
# CIVO Instance Diskimages
data "civo_disk_image" "debian" {
filter {
key = "name"
values = ["debian-10"]
}
}
data "civo_disk_image" "debian_9" {
filter {
key = "name"
values = ["debian-9"]
}
}
data "civo_disk_image" "ubuntu" {
filter {
key = "name"
values = ["ubuntu-focal"]
}
}
data "civo_disk_image" "ubuntu_bionic" {
filter {
key = "name"
values = ["ubuntu-bionic"]
}
}
data "civo_disk_image" "centos" {
filter {
key = "name"
values = ["centos-7"]
}
}

14
terraform/civo/server.tf Normal file
View File

@ -0,0 +1,14 @@
# CIVO Servers
# ---
# Templates to create a Linux Server on CIVO
# CIVO Instance Server
resource "civo_instance" "your-server" {
hostname = "your-fqdn-server-name"
size = data.civo_size.instance_xsmall.sizes.0.name
disk_image = data.civo_disk_image.debian.diskimages.0.id
# initial_user = "your-initial-user"
# sshkey_id = data.civo_ssh_key.your-ssh-key.id
# reverse_dns = "your-server.your-domain"
}

14
terraform/civo/ssh_key.tf Normal file
View File

@ -0,0 +1,14 @@
# CIVO SSH Keys
# ---
# Query or Create SSH Keys to authenticate to Servers on CIVO
# Query existing CIVO SSH Key
data "civo_ssh_key" "your-ssh-key" {
name = "your-ssh-key-name"
}
# Create new SSH Key
resource "civo_ssh_key" "your-ssh-key"{
name = "your-ssh-key-name"
public_key = file("~/.ssh/id_rsa.pub")
}