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 all 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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

# Spectro Cloud Tutorials

A collection of Spectro Cloud tutorials and their respective sample code.

<p align="center">
<img src="/static/img/spectro-wizard.png" alt="drawing" width="500"/>
</p>


The following tutorial code is available:

- [hello-universe-tf](./terraform/hello-universe-tf/README.md) - Deploy the Hello Universe application into two Palette Virtual Clusters. [Link](https://docs.spectrocloud.com/devx/apps/deploy-app) to the tutorial.

- [pack-tf](./terraform/pack-tf/README.md) - Learn how to create a custom pack. [Link](https://docs.spectrocloud.com/registries-and-packs/deploy-pack)
Expand All @@ -19,9 +20,11 @@ The following tutorial code is available:

- [Deploy an Edge cluster on VMware](./edge/vmware/README.md) - Learn how to deploy an Edge cluster on VMware. [Link](https://docs.spectrocloud.com/clusters/edge/site-deployment/deploy-cluster)

- [vmware-cluster-deployment-tf](./terraform/vmware-cluster-deployment-tf/README.md) - Learn how to deploy a VMware cluster and the Hello Universe application as a part of the Deploy App Workloads with a PCG tutorial. [Link](https://docs.spectrocloud.com/clusters/pcg/deploy-app-pcg)

## Docker

All the tutorials are available in a Docker image that you can use to get started with the tutorials.
All the tutorials are available in a Docker image that you can use to get started with the tutorials.
Review the [Docker steps](./docs/docker.md) to get started with the Docker image.

## Image Verification
Expand Down
87 changes: 87 additions & 0 deletions terraform/vmware-cluster-deployment-tf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Hello Universe TF

This folder contains the demo code for the [Deploy App Workloads with a PCG](https://docs.spectrocloud.com/clusters/pcg/deploy-app-pcg) tutorial. Use the code in this directory with the tutorial.

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. If not provided, a new key pair will be generated.

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

## Requirements

| Name | Version |
| --------------------------------------------------------------------------------- | --------- |
| <a name="requirement_local"></a> [local](#requirement_local) | 2.4.1 |
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement_spectrocloud) | >= 0.16.1 |
| <a name="requirement_tls"></a> [tls](#requirement_tls) | 4.0.4 |
| <a name="requirement_vsphere"></a> [vsphere](#requirement_vsphere) | >= 2.6.1 |

## Providers

| Name | Version |
| --------------------------------------------------------------------------- | ------- |
| <a name="provider_local"></a> [local](#provider_local) | 2.4.1 |
| <a name="provider_spectrocloud"></a> [spectrocloud](#provider_spectrocloud) | 0.17.4 |
| <a name="provider_tls"></a> [tls](#provider_tls) | 4.0.4 |

## Modules

No modules.

## Resources

| Name | Type |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- |
| [local_file.public_key_file](https://registry.terraform.io/providers/hashicorp/local/2.4.1/docs/resources/file) | resource |
| [local_sensitive_file.private_key_file](https://registry.terraform.io/providers/hashicorp/local/2.4.1/docs/resources/sensitive_file) | resource |
| [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 |
| [tls_private_key.tutorial_ssh_key](https://registry.terraform.io/providers/hashicorp/tls/4.0.4/docs/resources/private_key) | 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.hellouniverse](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_registry.community_registry](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/registry) | 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 datacenter in vSphere.. | `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 folder in vSphere. | `string` | n/a | yes |
| <a name="input_metallb_ip"></a> [metallb_ip](#input_metallb_ip) | The IP address range for your MetalLB Load Balancer. | `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_pcg_name"></a> [pcg_name](#input_pcg_name) | The name of the 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_search_domain"></a> [search_domain](#input_search_domain) | The name of network search domain. | `string` | n/a | yes |
| <a name="input_ssh_key"></a> [ssh_key](#input_ssh_key) | The path to the public key that will be added to the cluster nodes. If not provided, a new key pair will be generated. | `string` | n/a | yes |
| <a name="input_ssh_key_private"></a> [ssh_key_private](#input_ssh_key_private) | The path to the private key that will be used to access the cluster nodes. If not provided, a new key pair will be generated. | `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> "repository:spectrocloud:tutorials",<br> "tutorial:DEPLOY_APP_WORKLOADS_WITH_A_PCG"<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_ssh_connection_command"></a> [ssh_connection_command](#output_ssh_connection_command) | Command to use the generated private SSH key to access the nodes. |
| <a name="output_ssh_connection_command_user"></a> [ssh_connection_command_user](#output_ssh_connection_command_user) | Command to use the user's private SSH key to access the nodes. |
| <a name="output_ssh_key_location"></a> [ssh_key_location](#output_ssh_key_location) | Location of the generated private SSH key file |
| <a name="output_ssh_public_key_location"></a> [ssh_public_key_location](#output_ssh_public_key_location) | Location of the generated public SSH key file |
89 changes: 89 additions & 0 deletions terraform/vmware-cluster-deployment-tf/cluster.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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 = local.ssh_public_key
datacenter = var.datacenter_name
folder = var.folder_name
static_ip = false # If true, the cluster will use static IP placement. If false, the cluster will use DDNS.
network_search_domain = var.search_domain
}

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
# Required for static IP placement.
#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
# Required for static IP placement.
#static_ip_pool_id = resource.spectrocloud_privatecloudgateway_ippool.ippool.id
}

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

}
Loading
Loading