Skip to content

Instantly share code, notes, and snippets.

@alemonmk
Last active June 9, 2022 15:31
Show Gist options
  • Save alemonmk/7365e17ca6b57bbc4ef78311bf9332f9 to your computer and use it in GitHub Desktop.
Save alemonmk/7365e17ca6b57bbc4ef78311bf9332f9 to your computer and use it in GitHub Desktop.
job "csi-test" {
datacenters = ["@@REPLACE@@"]
region = "@@REPLACE@@"
constraint {
attribute = "$${node.unique.name}"
value = "@@REPLACE@@"
}
group "app" {
volume "vol" {
type = "csi"
access_mode = "single-node-writer"
attachment_mode = "file-system"
source = "${volume_id}"
}
task "pause" {
driver = "containerd-driver"
config {
image = "busybox"
command = "sleep"
args = ["1000000"]
}
resources {
cpu = 10
memory = 32
}
}
}
}
job "csi-vultr-controller" {
region = "@@REPLACE@@"
datacenters = ["@@REPLACE@@"]
type = "service"
group "controller" {
update {
max_parallel = 0
}
task "plugin" {
driver = "containerd-driver"
config {
image = "vultr/vultr-csi:release"
args = [
"-endpoint=unix:///csi/csi.sock",
"-token=${api_token}"
]
host_network = true
}
csi_plugin {
id = "csi-vultr-test"
type = "controller"
mount_dir = "/csi"
}
resources {
cpu = 100
memory = 64
}
}
}
}
job "csi-vultr-nodes" {
region = "@@REPLACE@@"
datacenters = ["@@REPLACE@@"]
type = "system"
group "nodes" {
task "plugin" {
driver = "containerd-driver"
config {
image = "vultr/vultr-csi:release"
args = [
"-endpoint=unix:///csi/csi.sock"
]
privileged = true
host_network = true
}
csi_plugin {
id = "csi-vultr-test"
type = "node"
mount_dir = "/csi"
}
resources {
cpu = 100
memory = 64
}
}
}
}
terraform {
required_providers {
vultr = {
source = "vultr/vultr"
version = "2.11.1"
}
nomad = {
source = "hashicorp/nomad"
version = "1.4.16"
}
}
}
variable "vultr_api_token" {
type = string
sensitive = true
}
provider "vultr" {
api_key = var.vultr_api_token
}
provider "nomad" {
address = "http://@@REPLACE@@:4646"
region = "@@REPLACE@@"
}
# Vultr CSI
resource "nomad_job" "csi_vultr_controller" {
jobspec = templatefile("${path.module}/csi-vultr-controller.hcl", { api_token = var.vultr_api_token })
hcl2 {
enabled = true
}
}
resource "nomad_job" "csi_vultr_nodes" {
jobspec = file("${path.module}/csi-vultr-nodes.hcl")
hcl2 {
enabled = true
}
}
data "nomad_plugin" "csi_vultr_test" {
plugin_id = "csi-vultr-test"
}
resource "vultr_block_storage" "test_store" {
lifecycle {
ignore_changes = [
attached_to_instance,
]
}
size_gb = 10
region = "nrt"
block_type = "high_perf"
label = "test_store"
}
resource "nomad_volume" "test_store" {
type = "csi"
name = "test_store"
volume_id = "test_store"
plugin_id = data.nomad_plugin.csi_vultr_test.id
external_id = vultr_block_storage.test_store.id
capability {
access_mode = "single-node-writer"
attachment_mode = "file-system"
}
mount_options {
fs_type = "ext4"
mount_flags = ["noatime"]
}
}
resource "nomad_job" "csi-test" {
jobspec = templatefile("${path.module}/csi-test.hcl", { volume_id = nomad_volume.test_store.id })
hcl2 {
enabled = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment