Skip to content

Commit

Permalink
docs: add readme DOC-1358
Browse files Browse the repository at this point in the history
  • Loading branch information
addetz committed Jan 13, 2025
1 parent f097d5e commit 9083746
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 48 deletions.
74 changes: 74 additions & 0 deletions terraform/vmo-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Deploy and Manage VMs using Palette VMO

This folder contains the demo code for the **Deploy and Manage VMs using Palette VMO** tutorial.

The Terraform code has two main toggle variables that you can use to deploy resources to [Canonical MAAS](https://maas.io/docs).

| Variable | Provider | Description | Default |
| ---------------- | -------- | ------------------------------------------------- | ------- |
| `deploy-maas` | MAAS | Enable to deploy a cluster to MAAS. | `false` |
| `deploy-maas-vm` | MAAS | Enable to deploy a VM to a deployed MAAS cluster. | `false` |


To get started, open the **terraform.tfvars** file. Toggle the provider variable as specified in the table and provide values to your cloud provider variables, replacing all instances of the string `REPLACE ME`.

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9 |
| <a name="requirement_local"></a> [local](#requirement\_local) | 2.4.1 |
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement\_spectrocloud) | >= 0.22.2 |
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | 4.0.4 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_local"></a> [local](#provider\_local) | 2.4.1 |
| <a name="provider_spectrocloud"></a> [spectrocloud](#provider\_spectrocloud) | 0.22.2 |
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.0.4 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [spectrocloud_cluster_profile.maas-vmo-profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource |
| [spectrocloud_cluster_maas.maas-cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_maas) | resource |
| [spectrocloud_virtual_machine.virtual-machine](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/virtual_machine) | resource |
| [spectrocloud_cloudaccount_maas.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_maas) | data source |
| [spectrocloud_pack.maas_vmo](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.maas_cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.maas_csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.maas_k8s](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.maas_ubuntu](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_cluster.maas_vmo_cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cluster) | data source |
| [spectrocloud_registry.public_registry](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/registry) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_deploy-maas"></a> [deploy-maas](#input\_deploy-maas) | A flag for enabling a cluster deployment on MAAS. | `bool` | n/a | yes |
| <a name="input_deploy-maas-vm"></a> [deploy-maas-vm](#input\_deploy-maas-vm) | A flag for enabling a VM creation on a MAAS cluster. | `bool` | n/a | yes |
| <a name="input_pcg-name"></a> [pcg-name](#input\_pcg-name) | The name of the PCG that will be used to deploy the cluster. | `string` | n/a | yes |
| <a name="input_maas-domain"></a> [maas-domain](#input\_maas-domain) | The MaaS domain that will be used to deploy the cluster. | `string` | n/a | yes |
| <a name="input_maas-worker-nodes"></a> [maas-worker-nodes](#input\_maas-worker-nodes) | The number of worker nodes that will be used to deploy the cluster. | `number` | 1 | yes |
| <a name="input_maas-control-plane-nodes"></a> [maas-control-plane-nodes](#input\_maas-control-plane-nodes) | The number of control plane nodes that will be used to deploy the cluster. | `number` | 1 | yes |
| <a name="input_maas-worker-resource-pool"></a> [maas-worker-resource-pool](#input\_maas-worker-resource-pool) | The resource pool to deploy the worker nodes to. | `string` | n/a | yes |
| <a name="input_maas-control-plane-resource-pool"></a> [maas-control-plane-resource-pool](#input\_maas-control-plane-resource-pool) | The resource pool to deploy the control plane nodes to. | `string` | n/a | yes |
| <a name="input_maas-worker-azs"></a> [maas-worker-azs](#input\_maas-worker-azs) | The set of availability zones to deploy the worker nodes to. | `set(string)` | n/a | yes |
| <a name="input_maas-control-plane-azs"></a> [maas-control-plane-azs](#input\_maas-control-plane-azs) | The set of availability zones to deploy the control plane nodes to. | `set(string)` | n/a | yes |
| <a name="input_maas-worker-node-tags"></a> [maas-worker-node-tags](#input\_maas-worker-node-tags) | The set of tag values that you want to apply to all nodes in the node worker pool. | `set(string)` | n/a | yes |
| <a name="input_maas-control-plane-node-tags"></a> [maas-control-plane-node-tags](#input\_maas-control-plane-node-tags) | The set of tag values that you want to apply to all nodes in the node control plane pool. | `set(string)` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | The default tags to apply to Palette resources. | `list(string)` | <pre>[<br> "spectro-cloud-education",<br> "spectrocloud:tutorials",<br> "terraform_managed:true",<br> "tutorial:vmo-cluster-deployment"<br>]</pre> | no |

## Outputs
No outputs.

<!-- END_TF_DOCS -->
4 changes: 2 additions & 2 deletions terraform/vmo-cluster/cluster_profiles.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

##########################
# MaaS VMO Cluster Profile
# MAAS VMO Cluster Profile
##########################
resource "spectrocloud_cluster_profile" "maas-vmo-profile" {
count = var.deploy-maas ? 1 : 0

name = "tf-maas-vmo-profile"
description = "A basic cluster profile for MaaS VMO"
description = "A basic cluster profile for MAAS VMO"
tags = concat(var.tags, ["env:maas"])
cloud = "maas"
type = "cluster"
Expand Down
4 changes: 2 additions & 2 deletions terraform/vmo-cluster/clusters.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# SPDX-License-Identifier: Apache-2.0

################
# MaaS Cluster
# MAAS Cluster
################

resource "spectrocloud_cluster_maas" "cluster" {
resource "spectrocloud_cluster_maas" "maas-cluster" {
count = var.deploy-maas ? 1 : 0

name = "vmo-cluster-maas"
Expand Down
9 changes: 3 additions & 6 deletions terraform/vmo-cluster/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ data "spectrocloud_registry" "public_registry" {
name = "Public Repo"
}

data "spectrocloud_registry" "community_registry" {
name = "Palette Community Registry"
}

######
# MaaS
# MAAS
######

data "spectrocloud_cloudaccount_maas" "account" {
Expand Down Expand Up @@ -52,7 +48,8 @@ data "spectrocloud_pack" "maas_vmo" {
}

data "spectrocloud_cluster" "maas_vmo_cluster" {
depends_on = [spectrocloud_cluster_maas.cluster]
count = var.deploy-maas-vm ? 1 : 0
depends_on = [spectrocloud_cluster_maas.maas-cluster]
name = "vmo-cluster-maas"
context = "project"
}
Expand Down
25 changes: 12 additions & 13 deletions terraform/vmo-cluster/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@ variable "tags" {
description = "The default tags to apply to Palette resources."
default = [
"spectro-cloud-education",
"app:hello-universe",
"spectrocloud:tutorials",
"terraform_managed:true",
"tutorial:vmo-cluster-deployment"
]
}

######
# MaaS
# MAAS
######

variable "deploy-maas" {
type = bool
description = "A flag for enabling a deployment on MaaS."
description = "A flag for enabling a deployment on MAAS."
}

variable "deploy-maas-vm" {
type = bool
description = "A flag for enabling a VM creation on the MaaS cluster."
description = "A flag for enabling a VM creation on the MAAS cluster."
}

variable "pcg-name" {
Expand All @@ -52,17 +51,17 @@ variable "pcg-name" {

validation {
condition = var.deploy-maas ? var.pcg-name != "REPLACE ME" && var.pcg-name != "" : true
error_message = "Provide the correct MaaS PCG name."
error_message = "Provide the correct MAAS PCG name."
}
}

variable "maas-domain" {
type = string
description = "MaaS domain"
description = "MAAS domain"

validation {
condition = var.deploy-maas ? var.maas-domain != "REPLACE ME" && var.maas-domain != "" : true
error_message = "Provide the correct MaaS domain."
error_message = "Provide the correct MAAS domain."
}
}

Expand All @@ -79,7 +78,7 @@ variable "maas-worker-nodes" {

variable "maas-worker-resource-pool" {
type = string
description = "Resource pool for the MaaS worker nodes."
description = "Resource pool for the MAAS worker nodes."

validation {
condition = var.deploy-maas ? var.maas-worker-resource-pool != "REPLACE ME" && var.maas-worker-resource-pool != "" : true
Expand All @@ -89,7 +88,7 @@ variable "maas-worker-resource-pool" {

variable "maas-worker-azs" {
type = set(string)
description = "Set of AZs for the MaaS worker nodes."
description = "Set of AZs for the MAAS worker nodes."

validation {
condition = var.deploy-maas ? !contains(var.maas-worker-azs, "REPLACE ME") && length(var.maas-worker-azs) != 0 : true
Expand All @@ -99,7 +98,7 @@ variable "maas-worker-azs" {

variable "maas-worker-node-tags" {
type = set(string)
description = "Set of node tags for the MaaS worker nodes."
description = "Set of node tags for the MAAS worker nodes."

validation {
condition = var.deploy-maas ? !contains(var.maas-worker-node-tags, "REPLACE ME") && length(var.maas-worker-node-tags) != 0 : true
Expand All @@ -120,7 +119,7 @@ variable "maas-control-plane-nodes" {

variable "maas-control-plane-resource-pool" {
type = string
description = "Resource pool for the MaaS control plane nodes."
description = "Resource pool for the MAAS control plane nodes."

validation {
condition = var.deploy-maas ? var.maas-control-plane-resource-pool != "REPLACE ME" && var.maas-control-plane-resource-pool != "" : true
Expand All @@ -130,7 +129,7 @@ variable "maas-control-plane-resource-pool" {

variable "maas-control-plane-azs" {
type = set(string)
description = "Set of AZs for the MaaS control plane nodes."
description = "Set of AZs for the MAAS control plane nodes."

validation {
condition = var.deploy-maas ? !contains(var.maas-control-plane-azs, "REPLACE ME") && length(var.maas-control-plane-azs) != 0 : true
Expand All @@ -140,7 +139,7 @@ variable "maas-control-plane-azs" {

variable "maas-control-plane-node-tags" {
type = set(string)
description = "Set of node tags for the MaaS control plane nodes."
description = "Set of node tags for the MAAS control plane nodes."

validation {
condition = var.deploy-maas ? !contains(var.maas-control-plane-node-tags, "REPLACE ME") && length(var.maas-control-plane-node-tags) != 0 : true
Expand Down
5 changes: 0 additions & 5 deletions terraform/vmo-cluster/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ terraform {
version = "4.0.4"
}

vsphere = {
source = "hashicorp/vsphere"
version = ">= 2.6.1"
}

local = {
source = "hashicorp/local"
version = "2.4.1"
Expand Down
24 changes: 12 additions & 12 deletions terraform/vmo-cluster/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
palette-project = "Default" # The name of your project in Palette.

############################
# MaaS Deployment Settings
# MAAS Deployment Settings
############################
deploy-maas = false # Set to true to deploy to MaaS.
deploy-maas-vm = false # Set to true to create a VM on MaaS cluster once deployed.
deploy-maas = true # Set to true to deploy to MAAS.
deploy-maas-vm = false # Set to true to create a VM on MAAS cluster once deployed.

pcg-name = "REPLACE ME" # Provide the name of the PCG that will be used to deploy the Palette cluster.
maas-domain = "REPLACE ME" # Provide the MaaS domain that will be used to deploy the Palette cluster.
pcg-name = "vmo-tutorial" # Provide the name of the PCG that will be used to deploy the Palette cluster.
maas-domain = "maas.sc" # Provide the MAAS domain that will be used to deploy the Palette cluster.

maas-worker-nodes = 1 # Provide the number of worker nodes that will be used for Palette cluster.
maas-worker-resource-pool = "REPLACE ME" # Provide a resource pool for the worker nodes.
maas-worker-azs = ["REPLACE ME"] # Provide a set of availability zones for the worker nodes.
maas-worker-node-tags = ["REPLACE ME"] # Provide a set of node tags for the worker nodes.
maas-worker-resource-pool = "vm-migration" # Provide a resource pool for the worker nodes.
maas-worker-azs = ["az3"] # Provide a set of availability zones for the worker nodes.
maas-worker-node-tags = ["docs"] # Provide a set of node tags for the worker nodes.

maas-control-plane-nodes = 1 # Provide the number of control plane nodes that will be used for Palette cluster.
maas-control-plane-resource-pool = "REPLACE ME" # Provide a resource pool for the control plane nodes.
maas-control-plane-azs = ["REPLACE ME"] # Provide a set of availability zones for the control plane nodes.
maas-control-plane-node-tags = ["REPLACE ME"] # Provide a set of node tags for the control plane nodes.
maas-control-plane-nodes = 1 # Provide the number of control plane nodes that will be used for Palette cluster.
maas-control-plane-resource-pool = "picard-demo" # Provide a resource pool for the control plane nodes.
maas-control-plane-azs = ["az3"] # Provide a set of availability zones for the control plane nodes.
maas-control-plane-node-tags = ["docs-cp"] # Provide a set of node tags for the control plane nodes.
4 changes: 2 additions & 2 deletions terraform/vmo-cluster/tests/maas-cluster-vm.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: Apache-2.0
# Test case 3 - Verify MaaS profile, cluster and VM are correctly planned when values are provided.
# Test case 3 - Verify MAAS profile, cluster and VM are correctly planned when values are provided.

variables {
deploy-maas = true
Expand Down Expand Up @@ -30,7 +30,7 @@ run "verify_maas" {
}

assert {
condition = length(spectrocloud_cluster_maas.cluster) == 1
condition = length(spectrocloud_cluster_maas.maas-cluster) == 1
error_message = "No MaaS cluster was created"
}

Expand Down
4 changes: 2 additions & 2 deletions terraform/vmo-cluster/tests/maas-cluster.tftest.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: Apache-2.0
# Test case 2 - Verify MaaS profile and cluster are correctly planned when values are provided.
# Test case 2 - Verify MAAS profile and cluster are correctly planned when values are provided.

variables {
deploy-maas = true
Expand Down Expand Up @@ -30,7 +30,7 @@ run "verify_maas" {
}

assert {
condition = length(spectrocloud_cluster_maas.cluster) == 1
condition = length(spectrocloud_cluster_maas.maas-cluster) == 1
error_message = "No MaaS cluster was created"
}

Expand Down
8 changes: 4 additions & 4 deletions terraform/vmo-cluster/virtual_machines.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

##########################
# MaaS Virtual Machine
# MAAS Virtual Machine
##########################
resource "spectrocloud_virtual_machine" "virtual-machine" {
count = var.deploy-maas-vm ? 1 : 0
depends_on = [spectrocloud_cluster_maas.cluster]
depends_on = [spectrocloud_cluster_maas.maas-cluster]

cluster_uid = data.spectrocloud_cluster.maas_vmo_cluster.id
cluster_context = data.spectrocloud_cluster.maas_vmo_cluster.context
cluster_uid = data.spectrocloud_cluster.maas_vmo_cluster[0].id
cluster_context = data.spectrocloud_cluster.maas_vmo_cluster[0].context

run_on_launch = true
namespace = "default"
Expand Down

0 comments on commit 9083746

Please sign in to comment.