Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visions of an incus made out of tofu. 🤔 #1

Merged
merged 11 commits into from
Apr 5, 2024
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
*.pyc

ansible/data/*
ansible/hosts.yaml

*.tfstate
*.tfstate.backup
.terraform*
2 changes: 2 additions & 0 deletions ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/*
hosts.yaml
4 changes: 4 additions & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.terraform/
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
66 changes: 27 additions & 39 deletions terraform/baremetal-incus/main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
terraform {
required_providers {
incus = {
source = "lxc/incus"
}
}
}

provider "incus" {
}

variable "instance_names" {
type = set(string)
default = ["server01", "server02", "server03", "server04", "server05"]
}

resource "incus_project" "project" {
name = "dev-incus-deploy"
resource "incus_project" "this" {
name = var.project_name
description = "Project used to test incus-deploy"
config = {
"features.images" = false
Expand All @@ -27,22 +11,22 @@ resource "incus_project" "project" {
}
}

resource "incus_profile" "profile" {
project = incus_project.project.name
resource "incus_profile" "this" {
project = incus_project.this.name
name = "cluster"
description = "Profile to be used by the cluster VMs"

config = {
"limits.cpu" = 4
"limits.memory" = "4GiB"
"limits.cpu" = "4"
"limits.memory" = var.memory
}

device {
type = "disk"
name = "root"

properties = {
"pool" = "default"
"pool" = var.storage_pool
"path" = "/"
}
}
Expand All @@ -62,7 +46,7 @@ resource "incus_profile" "profile" {
name = "disk4"

properties = {
"pool" = "default"
"pool" = var.storage_pool
"io.bus" = "nvme"
"source" = incus_volume.disk4.name
}
Expand All @@ -72,10 +56,10 @@ resource "incus_profile" "profile" {
resource "incus_volume" "disk1" {
for_each = var.instance_names

project = incus_project.project.name
project = incus_project.this.name
name = "${each.value}-disk1"
description = "First CEPH OSD drive"
pool = "default"
pool = var.storage_pool
content_type = "block"
config = {
"size" = "20GiB"
Expand All @@ -85,10 +69,10 @@ resource "incus_volume" "disk1" {
resource "incus_volume" "disk2" {
for_each = var.instance_names

project = incus_project.project.name
project = incus_project.this.name
name = "${each.value}-disk2"
description = "Second CEPH OSD drive"
pool = "default"
pool = var.storage_pool
content_type = "block"
config = {
"size" = "20GiB"
Expand All @@ -98,42 +82,42 @@ resource "incus_volume" "disk2" {
resource "incus_volume" "disk3" {
for_each = var.instance_names

project = incus_project.project.name
project = incus_project.this.name
name = "${each.value}-disk3"
description = "Local storage drive"
pool = "default"
pool = var.storage_pool
content_type = "block"
config = {
"size" = "50GiB"
}
}

resource "incus_volume" "disk4" {
project = incus_project.project.name
project = incus_project.this.name
name = "shared-disk"
description = "Shared block storage"
pool = "default"
pool = var.storage_pool
content_type = "block"
config = {
"size" = "50GiB"
"size" = "50GiB"
"security.shared" = "true"
}
}
resource "incus_instance" "instances" {
for_each = var.instance_names

project = incus_project.project.name
project = incus_project.this.name
name = each.value
type = "virtual-machine"
image = "images:ubuntu/22.04"
profiles = ["default", incus_profile.profile.name]
image = var.image
profiles = ["default", incus_profile.this.name]

device {
type = "disk"
name = "disk1"

properties = {
"pool" = "default"
"pool" = var.storage_pool
"io.bus" = "nvme"
"source" = incus_volume.disk1[each.key].name
}
Expand All @@ -144,7 +128,7 @@ resource "incus_instance" "instances" {
name = "disk2"

properties = {
"pool" = "default"
"pool" = var.storage_pool
"io.bus" = "nvme"
"source" = incus_volume.disk2[each.key].name
}
Expand All @@ -155,9 +139,13 @@ resource "incus_instance" "instances" {
name = "disk3"

properties = {
"pool" = "default"
"pool" = var.storage_pool
"io.bus" = "nvme"
"source" = incus_volume.disk3[each.key].name
}
}

lifecycle {
ignore_changes = [ running ]
}
}
Comment on lines +148 to +150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does that do exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prevents Tofu from turning on and off the instances when the state is controlled externally to Tofu.I prefer to do that with different tooling. In my case, I would use the Incus CLI.

The AWS, etc. providers offer the ability to control the on off state of instances, but it is opt in and discouraged.

Ideally the incus provider would work the same way. Then we would not need to disable it.

But what does it do exactly? It tells Tofu to ignore that part of the state file.

19 changes: 19 additions & 0 deletions terraform/baremetal-incus/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "project_name" {
type = string
}

variable "instance_names" {
type = set(string)
}

variable "image" {
type = string
}

variable "memory" {
type = string
}

variable "storage_pool" {
type = string
}
9 changes: 9 additions & 0 deletions terraform/baremetal-incus/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">=1.5.7"
required_providers {
incus = {
source = "lxc/incus"
version = ">=0.1.1"
}
}
}
18 changes: 18 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module "baremetal" {
source = "./baremetal-incus"

project_name = "dev-incus-deploy"
instance_names = ["server01", "server02", "server03", "server04", "server05"]
image = "images:ubuntu/22.04"
memory = "4GiB"
storage_pool = "default"
}

module "services" {
source = "./services"

project_name = "dev-incus-deploy-services"
instance_names = ["ceph-mds01", "ceph-mds02", "ceph-mds03", "ceph-mgr01", "ceph-mgr02", "ceph-mgr03", "ceph-rgw01", "ceph-rgw02", "ceph-rgw03"]
image = "images:ubuntu/22.04"
storage_pool = "default"
}
40 changes: 14 additions & 26 deletions terraform/services/main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
terraform {
required_providers {
incus = {
source = "lxc/incus"
}
}
}

provider "incus" {
}

variable "instance_names" {
type = set(string)
default = ["ceph-mds01", "ceph-mds02", "ceph-mds03", "ceph-mgr01", "ceph-mgr02", "ceph-mgr03", "ceph-rgw01", "ceph-rgw02", "ceph-rgw03"]
}

resource "incus_project" "project" {
name = "dev-incus-deploy-services"
resource "incus_project" "this" {
name = var.project_name
description = "Project used to test incus-deploy services"
config = {
"features.images" = false
Expand All @@ -27,14 +11,14 @@ resource "incus_project" "project" {
}
}

resource "incus_profile" "profile" {
project = incus_project.project.name
resource "incus_profile" "this" {
project = incus_project.this.name
name = "services"
description = "Profile to be used by the service containers"

config = {
"limits.cpu" = 1
"limits.memory" = "1GiB"
"limits.cpu" = "1"
"limits.memory" = "1GiB"
"limits.processes" = "1000"
}

Expand All @@ -43,7 +27,7 @@ resource "incus_profile" "profile" {
name = "root"

properties = {
"pool" = "default"
"pool" = var.storage_pool
"path" = "/"
}
}
Expand All @@ -62,9 +46,13 @@ resource "incus_profile" "profile" {
resource "incus_instance" "instances" {
for_each = var.instance_names

project = incus_project.project.name
project = incus_project.this.name
name = each.value
type = "container"
image = "images:ubuntu/22.04"
profiles = ["default", incus_profile.profile.name]
image = var.image
profiles = ["default", incus_profile.this.name]

lifecycle {
ignore_changes = [ running ]
}
}
15 changes: 15 additions & 0 deletions terraform/services/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
variable "project_name" {
type = string
}

variable "instance_names" {
type = set(string)
}

variable "image" {
type = string
}

variable "storage_pool" {
type = string
}
9 changes: 9 additions & 0 deletions terraform/services/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">=1.5.7"
required_providers {
incus = {
source = "lxc/incus"
version = ">=0.1.1"
}
}
}
12 changes: 12 additions & 0 deletions terraform/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_version = ">=1.5.7"
required_providers {
incus = {
source = "lxc/incus"
version = ">=0.1.1"
}
}
}

provider "incus" {
}
Loading