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

docs: add terraform files to deploy a vmware cluster #36

Merged
merged 6 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions terraform/vmware-cluster-deployment-tf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Hello Universe TF

This folder contains the demo code for the Deploy App Workloads with a PCG tutorial. Use the code in this directory with the tutorial.
caroldelwing marked this conversation as resolved.
Show resolved Hide resolved

To get started, review the [prerequisites](#prerequisites). Next, follow the steps in the tutorial to deploy a VMware cluster and add-on pack.
Use the [terraform.tfvars](./terraform.tfvars) file to provide the required variables.

## Prerequisites

You will need the following items before getting started:

1. A Palette API key.
2. A VMware PCG added to your Palette account.
3. A public SSH key that will be used to access the cluster nodes.
caroldelwing marked this conversation as resolved.
Show resolved Hide resolved

> [!NOTE]
> This Terraform code will deploy the resources specified in the template to **VMware vSphere**.

## Requirements

| Name | Version |
| --------------------------------------------------------------------------------- | --------- |
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement_spectrocloud) | >= 0.16.1 |
| <a name="requirement_vsphere"></a> [vsphere](#requirement_vsphere) | >= 2.6.1 |

## Providers

| Name | Version |
| --------------------------------------------------------------------------- | ------- |
| <a name="provider_spectrocloud"></a> [spectrocloud](#provider_spectrocloud) | 0.17.4 |

## Modules

No modules.

## Resources

| Name | Type |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| [spectrocloud_cluster_profile.profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource |
| [spectrocloud_cluster_vsphere.cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_vsphere) | resource |
| [spectrocloud_privatecloudgateway_ippool.ippool](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/privatecloudgateway_ippool) | resource |
| [spectrocloud_cloudaccount_vsphere.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_vsphere) | data source |
| [spectrocloud_pack.cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.k8s](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.metallb](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_pack.ubuntu](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
| [spectrocloud_private_cloud_gateway.pcg](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/private_cloud_gateway) | 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_cluster_name"></a> [cluster_name](#input_cluster_name) | The name of the cluster. | `string` | `"pcg-tutorial-cluster"` | no |
| <a name="input_cluster_profile_description"></a> [cluster_profile_description](#input_cluster_profile_description) | Provide a description of the cluster profile. | `string` | `"My cluster profile as part of the pcg tutorial."` | no |
| <a name="input_cluster_profile_name"></a> [cluster_profile_name](#input_cluster_profile_name) | The name of the cluster profile. | `string` | `"pcg-tutorial-profile"` | no |
| <a name="input_datacenter_name"></a> [datacenter_name](#input_datacenter_name) | The name of the vsphere datacenter. | `string` | n/a | yes |
| <a name="input_datastore_name"></a> [datastore_name](#input_datastore_name) | The name of the vsphere datastore. | `string` | n/a | yes |
| <a name="input_folder_name"></a> [folder_name](#input_folder_name) | The name of the vsphere folder. | `string` | n/a | yes |
| <a name="input_ip_range_end"></a> [ip_range_end](#input_ip_range_end) | The last IP of your IP range. | `string` | n/a | yes |
| <a name="input_ip_range_start"></a> [ip_range_start](#input_ip_range_start) | The first IP of your IP range. | `string` | n/a | yes |
| <a name="input_metallb_ip"></a> [metallb_ip](#input_metallb_ip) | Provide the metallb ip. | `string` | n/a | yes |
| <a name="input_nameserver_addr"></a> [nameserver_addr](#input_nameserver_addr) | The nameserver address of your network. | `set(string)` | n/a | yes |
| <a name="input_network_gateway"></a> [network_gateway](#input_network_gateway) | The gateway of your network. | `string` | n/a | yes |
| <a name="input_network_name"></a> [network_name](#input_network_name) | The name of the vsphere network. | `string` | n/a | yes |
| <a name="input_network_prefix"></a> [network_prefix](#input_network_prefix) | The network prefix of your IP Pool. | `number` | n/a | yes |
| <a name="input_pcg_name"></a> [pcg_name](#input_pcg_name) | The name of the Vsphere PCG | `string` | n/a | yes |
| <a name="input_resource_pool_name"></a> [resource_pool_name](#input_resource_pool_name) | The name of the vsphere resource pool. | `string` | n/a | yes |
| <a name="input_ssh_key"></a> [ssh_key](#input_ssh_key) | Specify the public key that will be used to access the cluster nodes. | `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> "app:hello-universe",<br> "terraform_managed:true"<br>]</pre> | no |
| <a name="input_vsphere_cluster"></a> [vsphere_cluster](#input_vsphere_cluster) | The name of your vsphere cluster. | `string` | n/a | yes |

## Outputs

| Name | Description |
| ----------------------------------------------------------------- | ----------- |
| <a name="output_Advisory"></a> [Advisory](#output_Advisory) | n/a |
| <a name="output_profile_id"></a> [profile_id](#output_profile_id) | n/a |

<!-- END_TF_DOCS -->
87 changes: 87 additions & 0 deletions terraform/vmware-cluster-deployment-tf/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: Apache-2.0

resource "spectrocloud_cluster_vsphere" "cluster" {
name = var.cluster_name
tags = var.tags
cloud_account_id = data.spectrocloud_cloudaccount_vsphere.account.id
depends_on = [spectrocloud_cluster_profile.profile]

cloud_config {
ssh_key = var.ssh_key
datacenter = var.datacenter_name
folder = var.folder_name
static_ip = true

}

cluster_profile {
id = spectrocloud_cluster_profile.profile.id
}

scan_policy {
configuration_scan_schedule = "0 0 * * SUN"
penetration_scan_schedule = "0 0 * * SUN"
conformance_scan_schedule = "0 0 1 * *"
}

##############################
# control-plane-pool
##############################
machine_pool {
name = "control-plane-pool"
count = 1
control_plane = true
control_plane_as_worker = true

instance_type {
cpu = 4
disk_size_gb = 60
memory_mb = 8000
}

placement {
cluster = var.vsphere_cluster
datastore = var.datastore_name
network = var.network_name
resource_pool = var.resource_pool_name
static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
}

additional_labels = {
"owner" = "docs"
"purpose" = "tutorial"
"type" = "control-plane-node"
}
}

##############################
# worker-pool
##############################
machine_pool {
name = "worker-pool"
count = 1
control_plane = false

instance_type {
cpu = 4
disk_size_gb = 60
memory_mb = 8000
}

placement {
cluster = var.vsphere_cluster
datastore = var.datastore_name
network = var.network_name
resource_pool = var.resource_pool_name
static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
}

additional_labels = {
"owner" = "docs"
"purpose" = "tutorial"
"type" = "worker-node"
}
}

}
69 changes: 69 additions & 0 deletions terraform/vmware-cluster-deployment-tf/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: Apache-2.0

####################################
# Data resources for the profile
####################################
data "spectrocloud_registry" "public_registry" {
name = "Public Repo"
}

####################################
# Core Infrastructure Layers
# The following core infrastructure layers are configured for deployment to Vsphere.
# Change the name and version of the following core infrastructure layers if you want to create the profile for other cloud service providers.
####################################
data "spectrocloud_pack" "ubuntu" {
name = "ubuntu-vsphere"
version = "22.04"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "k8s" {
name = "kubernetes"
version = "1.28.3"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "cni" {
name = "cni-calico"
version = "3.26.3"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "csi" {
name = "csi-vsphere-csi"
version = "3.0.2"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "metallb" {
name = "lb-metallb"
version = "0.13.7"
caroldelwing marked this conversation as resolved.
Show resolved Hide resolved
registry_uid = data.spectrocloud_registry.public_registry.id
}

####################################
# Add-On Layers
####################################

#data "spectrocloud_pack" "hellouniverse" {
# name =
# version =
# registry_uid = data.spectrocloud_registry.public_registry.id
#}

####################################
# Data resources for the cluster
####################################
data "spectrocloud_cloudaccount_vsphere" "account" {
name = var.pcg_name
}


####################################
# Data resources for the PCG
####################################
data "spectrocloud_private_cloud_gateway" "pcg" {
name = var.pcg_name
}
149 changes: 149 additions & 0 deletions terraform/vmware-cluster-deployment-tf/inputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: Apache-2.0

####################################
# Input resources for the profile
####################################

variable "cluster_profile_name" {
type = string
description = "The name of the cluster profile."
default = "pcg-tutorial-profile"
}

variable "cluster_profile_description" {
type = string
description = "Provide a description of the cluster profile."
default = "My cluster profile as part of the PCG tutorial."
}

# ToDo
# Provide a range of IP addresses for your Metallb Load Balancer. This range must be included in the PCG's static IP pool.
variable "metallb_ip" {
type = string
description = "The IP address range for your MetalLB Load Balancer."
}

####################################
# Input resources for the cluster
####################################

variable "cluster_name" {
type = string
description = "The name of the cluster."
default = "pcg-tutorial-cluster"
}

variable "tags" {
type = list(string)
description = "The default tags to apply to Palette resources"
# Value and key must be 63 characters or less, must start and end with an alphanumeric character, and can contain only alphanumeric characters, dots, dashes or underscores.
# Slashes `\` are not allowed.
default = ["spectro-cloud-education", "app:hello-universe", "terraform_managed:true"]
caroldelwing marked this conversation as resolved.
Show resolved Hide resolved
}

#################################################
# Input resources for the cluster - Cloud config
#################################################

# ToDo
# Export the variable below as an environment variable named "TF_VAR_ssh_key".
# The value should include the public key for accessing the cluster nodes.
variable "ssh_key" {
type = string
description = "Specify the public key that will be used to access the cluster nodes."
sensitive = true
}

# ToDo
# Provide the name of the datacenter in vSphere.
variable "datacenter_name" {
type = string
description = "The name of the datacenter in vSphere.."
}

# ToDo
# Provide the name of the folder in vSphere.
variable "folder_name" {
type = string
description = "The name of the folder in vSphere."
}

#################################################
# Input resources for the cluster - Placement
#################################################

# ToDo
# Provide the cluster name for the machine pool as it appears in vSphere.
variable "vsphere_cluster" {
type = string
description = "The name of your vSphere cluster."
}

# ToDo
# Provide the datastore name for the machine pool as it appears in vSphere.
variable "datastore_name" {
type = string
description = "The name of the vSphere datastore."
}

# ToDo
# Provide the network name for the machine pool as it appears in vSphere.
variable "network_name" {
type = string
description = "The name of the vSphere network."
}

# ToDo
# Provide the resource pool name for the machine pool as it appears in vSphere.
variable "resource_pool_name" {
type = string
description = "The name of the vSphere resource pool."
}

#################################################
# Input resources for the Static IP Pool
#################################################

# ToDo
# Provide the IP address of the vSphere network gateway.
variable "network_gateway" {
type = string
description = "The IP address of the vSphere network gateway."
}

# ToDo
# Provide the prefix of your vSphere network.
# Valid values are network CIDR subnet masks from the range 0-32. Example: 18.
variable "network_prefix" {
type = number
description = "The prefix of your vSphere network."
}

# ToDo
# Provide the name of the PCG that will be used to create the static IP pool.
variable "pcg_name" {
type = string
description = "The name of the IP Pool PCG."
}

# ToDo
# Provide the first IP address of your PCG IP pool range.
variable "ip_range_start" {
type = string
description = "The first IP address of your PCG IP pool range."
}

# ToDo
# Provide the second IP address of your PCG IP pool range.
variable "ip_range_end" {
type = string
description = "The last IP address of your PCG IP pool range."
}

# ToDo
# Provide a comma-separated list of DNS name server IP addresses.
variable "nameserver_addr" {
type = set(string)
description = "The DNS nameserver IP addresses of your network."
}
Loading