From 5a0f96d367fb414f33ecec182263b7f32bcb300c Mon Sep 17 00:00:00 2001 From: Carolina Delwing Rosa Date: Fri, 31 May 2024 17:05:26 -0400 Subject: [PATCH] docs: add tf files for the getting started tutorial --- README.md | 2 + .../getting-started-deployment-tf/README.md | 142 +++++ .../cluster_profiles.tf | 485 ++++++++++++++++++ .../getting-started-deployment-tf/clusters.tf | 215 ++++++++ .../getting-started-deployment-tf/data.tf | 173 +++++++ .../getting-started-deployment-tf/inputs.tf | 361 +++++++++++++ .../getting-started-deployment-tf/ippool.tf | 14 + .../manifests/values-3tier.yaml | 20 + .../getting-started-deployment-tf/outputs.tf | 35 ++ .../getting-started-deployment-tf/provider.tf | 34 ++ .../getting-started-deployment-tf/ssh-key.tf | 39 ++ .../terraform.tfvars | 122 +++++ 12 files changed, 1642 insertions(+) create mode 100644 terraform/getting-started-deployment-tf/README.md create mode 100644 terraform/getting-started-deployment-tf/cluster_profiles.tf create mode 100644 terraform/getting-started-deployment-tf/clusters.tf create mode 100644 terraform/getting-started-deployment-tf/data.tf create mode 100644 terraform/getting-started-deployment-tf/inputs.tf create mode 100644 terraform/getting-started-deployment-tf/ippool.tf create mode 100644 terraform/getting-started-deployment-tf/manifests/values-3tier.yaml create mode 100644 terraform/getting-started-deployment-tf/outputs.tf create mode 100644 terraform/getting-started-deployment-tf/provider.tf create mode 100644 terraform/getting-started-deployment-tf/ssh-key.tf create mode 100644 terraform/getting-started-deployment-tf/terraform.tfvars diff --git a/README.md b/README.md index 19806e4..bdbda40 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ The following tutorial code is available: - [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) +- [getting-started-deployment-tf](./terraform/getting-started-deployment-tf/README.md) - Learn how to deploy and update a cluster to AWS, Azure, GCP, and VMware vSphere with Palette. [Link](https://docs.spectrocloud.com/getting-started/terraform) + ## Docker All the tutorials are available in a Docker image that you can use to get started with the tutorials. diff --git a/terraform/getting-started-deployment-tf/README.md b/terraform/getting-started-deployment-tf/README.md new file mode 100644 index 0000000..9714489 --- /dev/null +++ b/terraform/getting-started-deployment-tf/README.md @@ -0,0 +1,142 @@ +# IaaS Cluster Deployment + +This Terraform code is explained in the [Deploy a Cluster](https://docs.spectrocloud.com/clusters/public-cloud/deploy-k8s-cluster) tutorial. + +This Terraform code has three main toggle variables that you can use to deploy to one of the following cloud providers. + +| Variable | Provider | Description | Default | +| -------------- | -------- | ------------------------------------ | ------- | +| `deploy-aws` | AWS | Enable to deploy a cluster to AWS. | `false` | +| `deploy-azure` | GCP | Enable to deploy a cluster to Azure. | `false` | +| `deploy-gcp` | Azure | Enable to deploy a cluster to GCP. | `false` | + +> You can enable as many of the providers as you want. You just need to ensure all provider's required values are specified. + +To get started, open up the file **terraform.tfvars**. Toggle the provider variable mentioned in the table and start providing values for the respective cloud provider. Make sure you specify a value to your cloud provider variables and replace all values containing the string `REPLACE ME`. + +## Requirements + +| Name | Version | +| --------------------------------------------------------------------------------- | ------------- | +| [terraform](#requirement_terraform) | >= 1.5 | +| [local](#requirement_local) | 2.4.1 | +| [spectrocloud](#requirement_spectrocloud) | >= 0.19.0-pre | +| [tls](#requirement_tls) | 4.0.4 | +| [vsphere](#requirement_vsphere) | >= 2.6.1 | + +## Providers + +| Name | Version | +| --------------------------------------------------------------------------- | ------- | +| [local](#provider_local) | 2.4.1 | +| [spectrocloud](#provider_spectrocloud) | 0.19.2 | +| [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_aws.aws-cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_aws) | resource | +| [spectrocloud_cluster_azure.azure-cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_azure) | resource | +| [spectrocloud_cluster_gcp.gcp-cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_gcp) | resource | +| [spectrocloud_cluster_profile.aws-profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.aws-profile-new](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.azure-profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.azure-profile-new](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.gcp-profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.gcp-profile-new](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.vmware-profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_profile.vmware-profile-new](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_cluster_vsphere.vmware-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 | +| [tls_private_key.tutorial_ssh_key_azure](https://registry.terraform.io/providers/hashicorp/tls/4.0.4/docs/resources/private_key) | resource | +| [spectrocloud_cloudaccount_aws.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_aws) | data source | +| [spectrocloud_cloudaccount_azure.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_azure) | data source | +| [spectrocloud_cloudaccount_gcp.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_gcp) | data source | +| [spectrocloud_cloudaccount_vsphere.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_vsphere) | data source | +| [spectrocloud_pack.aws_cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.aws_csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.aws_k8s](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.aws_ubuntu](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.azure_cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.azure_csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.azure_k8s](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.azure_ubuntu](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.gcp_cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.gcp_csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.gcp_k8s](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.gcp_ubuntu](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.kubecost](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.vmware_cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.vmware_csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.vmware_k8s](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.vmware_metallb](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | +| [spectrocloud_pack.vmware_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 | +| ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | +| [app_namespace](#input_app_namespace) | The namespace in which the application will be deployed. | `string` | n/a | yes | +| [app_port](#input_app_port) | The cluster port number on which the service will listen for incoming traffic. | `number` | n/a | yes | +| [auth_token](#input_auth_token) | The base64 encoded auth token for the API connection. | `string` | n/a | yes | +| [aws-cloud-account-name](#input_aws-cloud-account-name) | The name of your AWS account as assigned in Palette. | `string` | `""` | no | +| [aws-key-pair-name](#input_aws-key-pair-name) | The name of the AWS key pair to use for SSH access to the cluster. | `string` | `""` | no | +| [aws-region](#input_aws-region) | AWS region | `string` | `"us-east-1"` | no | +| [aws_control_plane_nodes](#input_aws_control_plane_nodes) | AWS control plane nodes configuration. |
object({
count = string
control_plane = bool
instance_type = string
disk_size_gb = string
availability_zones = list(string)
})
|
{
"availability_zones": [
"us-east-1a"
],
"control_plane": true,
"count": "1",
"disk_size_gb": "60",
"instance_type": "m4.2xlarge"
}
| no | +| [aws_worker_nodes](#input_aws_worker_nodes) | AWS worker nodes configuration. |
object({
count = string
control_plane = bool
instance_type = string
disk_size_gb = string
availability_zones = list(string)
})
|
{
"availability_zones": [
"us-east-1a"
],
"control_plane": false,
"count": "1",
"disk_size_gb": "60",
"instance_type": "m4.2xlarge"
}
| no | +| [azure-cloud-account-name](#input_azure-cloud-account-name) | The name of your Azure account as assigned in Palette. | `string` | `""` | no | +| [azure-region](#input_azure-region) | Azure region. | `string` | `"eastus"` | no | +| [azure-use-azs](#input_azure-use-azs) | A flag for configuring whether to use Azure Availability Zones. Check if your Azure region supports availability zones by reviewing the [Azure Regions and Availability Zones](https://learn.microsoft.com/en-us/azure/reliability/availability-zones-service-support#azure-regions-with-availability-zone-support) resource. | `bool` | n/a | yes | +| [azure_control_plane_nodes](#input_azure_control_plane_nodes) | Azure control plane nodes configuration. |
object({
count = string
control_plane = bool
instance_type = string
disk_size_gb = string
azs = list(string)
is_system_node_pool = bool
})
|
{
"azs": [
"1"
],
"control_plane": true,
"count": "1",
"disk_size_gb": "60",
"instance_type": "Standard_A8_v2",
"is_system_node_pool": false
}
| no | +| [azure_resource_group](#input_azure_resource_group) | Azure resource group. | `string` | `""` | no | +| [azure_subscription_id](#input_azure_subscription_id) | Azure subscription ID. | `string` | `""` | no | +| [azure_worker_nodes](#input_azure_worker_nodes) | Azure worker nodes configuration. |
object({
count = string
control_plane = bool
instance_type = string
disk_size_gb = string
azs = list(string)
is_system_node_pool = bool
})
|
{
"azs": [
"1"
],
"control_plane": false,
"count": "1",
"disk_size_gb": "60",
"instance_type": "Standard_A8_v2",
"is_system_node_pool": false
}
| no | +| [datacenter_name](#input_datacenter_name) | The name of the datacenter in vSphere.. | `string` | n/a | yes | +| [datastore_name](#input_datastore_name) | The name of the vSphere datastore. | `string` | n/a | yes | +| [db_password](#input_db_password) | The base64 encoded database password to connect to the API database. | `string` | n/a | yes | +| [deploy-aws](#input_deploy-aws) | A flag for enabling a deployment on AWS. | `bool` | n/a | yes | +| [deploy-aws-new](#input_deploy-aws-new) | A flag for enabling a deployment on AWS with Kubecost. | `bool` | n/a | yes | +| [deploy-azure](#input_deploy-azure) | A flag for enabling a deployment on Azure. | `bool` | n/a | yes | +| [deploy-azure-new](#input_deploy-azure-new) | A flag for enabling a deployment on Azure with Kubecost. | `bool` | n/a | yes | +| [deploy-gcp](#input_deploy-gcp) | A flag for enabling a deployment on GCP. | `bool` | n/a | yes | +| [deploy-gcp-new](#input_deploy-gcp-new) | A flag for enabling a deployment on GCP with Kubecost. | `bool` | n/a | yes | +| [deploy-vmware](#input_deploy-vmware) | A flag for enabling a deployment on VMware. | `bool` | n/a | yes | +| [deploy-vmware-new](#input_deploy-vmware-new) | A flag for enabling a deployment on VMware with Kubecost. | `bool` | n/a | yes | +| [folder_name](#input_folder_name) | The name of the folder in vSphere. | `string` | n/a | yes | +| [gcp-cloud-account-name](#input_gcp-cloud-account-name) | The name of your GCP account as assigned in Palette. | `string` | `""` | no | +| [gcp-region](#input_gcp-region) | GCP region | `string` | `"us-central1"` | no | +| [gcp_control_plane_nodes](#input_gcp_control_plane_nodes) | GCP control plane nodes configuration. |
object({
count = string
control_plane = bool
instance_type = string
disk_size_gb = string
availability_zones = list(string)
})
|
{
"availability_zones": [
"us-central1-a"
],
"control_plane": true,
"count": "1",
"disk_size_gb": "60",
"instance_type": "n1-standard-4"
}
| no | +| [gcp_project_name](#input_gcp_project_name) | The name of your GCP project. | `string` | `""` | no | +| [gcp_worker_nodes](#input_gcp_worker_nodes) | GCP worker nodes configuration. |
object({
count = string
control_plane = bool
instance_type = string
disk_size_gb = string
availability_zones = list(string)
})
|
{
"availability_zones": [
"us-central1-a"
],
"control_plane": false,
"count": "1",
"disk_size_gb": "60",
"instance_type": "n1-standard-4"
}
| no | +| [metallb_ip](#input_metallb_ip) | The IP address range for your MetalLB load balancer. | `string` | n/a | yes | +| [network_name](#input_network_name) | The name of the vSphere network. | `string` | n/a | yes | +| [pcg_name](#input_pcg_name) | The name of the PCG that will be used to deploy the cluster. | `string` | n/a | yes | +| [replicas_number](#input_replicas_number) | The number of pods to be created. | `number` | n/a | yes | +| [resource_pool_name](#input_resource_pool_name) | The name of the vSphere resource pool. | `string` | n/a | yes | +| [search_domain](#input_search_domain) | The name of network search domain. | `string` | n/a | yes | +| [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 | +| [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 | +| [tags](#input_tags) | The default tags to apply to Palette resources. | `list(string)` |
[
"spectro-cloud-education",
"app:hello-universe",
"repository:spectrocloud:tutorials",
"terraform_managed:true",
"tutorial:getting-started-terraform"
]
| no | +| [vsphere_cluster](#input_vsphere_cluster) | The name of your vSphere cluster. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +| -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| [Advisory](#output_Advisory) | n/a | +| [ssh_connection_command](#output_ssh_connection_command) | Command to use the generated private SSH key to access the nodes. | +| [ssh_connection_command_user](#output_ssh_connection_command_user) | Command to use the user's private SSH key to access the nodes. | +| [ssh_key_location](#output_ssh_key_location) | Location of the generated private SSH key file. | +| [ssh_public_key_location](#output_ssh_public_key_location) | Location of the generated public SSH key file. | + + diff --git a/terraform/getting-started-deployment-tf/cluster_profiles.tf b/terraform/getting-started-deployment-tf/cluster_profiles.tf new file mode 100644 index 0000000..5fa635c --- /dev/null +++ b/terraform/getting-started-deployment-tf/cluster_profiles.tf @@ -0,0 +1,485 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +############################ +# AWS Cluster Profile v1.0.0 +############################ +resource "spectrocloud_cluster_profile" "aws-profile" { + count = var.deploy-aws ? 1 : 0 + + name = "tf-aws-profile" + description = "A basic cluster profile for AWS" + tags = concat(var.tags, ["env:aws"]) + cloud = "aws" + type = "cluster" + version = "1.0.0" + + pack { + name = data.spectrocloud_pack.aws_ubuntu.name + tag = data.spectrocloud_pack.aws_ubuntu.version + uid = data.spectrocloud_pack.aws_ubuntu.id + values = data.spectrocloud_pack.aws_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.aws_k8s.name + tag = data.spectrocloud_pack.aws_k8s.version + uid = data.spectrocloud_pack.aws_k8s.id + values = data.spectrocloud_pack.aws_k8s.values + } + + pack { + name = data.spectrocloud_pack.aws_cni.name + tag = data.spectrocloud_pack.aws_cni.version + uid = data.spectrocloud_pack.aws_cni.id + values = data.spectrocloud_pack.aws_cni.values + } + + pack { + name = data.spectrocloud_pack.aws_csi.name + tag = data.spectrocloud_pack.aws_csi.version + uid = data.spectrocloud_pack.aws_csi.id + values = data.spectrocloud_pack.aws_csi.values + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number + db_password = var.db_password, + auth_token = var.auth_token + }) + } +} + +############################ +# AWS Cluster Profile v1.1.0 +############################ +resource "spectrocloud_cluster_profile" "aws-profile-new" { + count = var.deploy-aws-new ? 1 : 0 + + name = "tf-aws-profile" + description = "A basic cluster profile for AWS with Kubecost" + tags = concat(var.tags, ["env:aws"]) + cloud = "aws" + type = "cluster" + version = "1.1.0" + + pack { + name = data.spectrocloud_pack.aws_ubuntu.name + tag = data.spectrocloud_pack.aws_ubuntu.version + uid = data.spectrocloud_pack.aws_ubuntu.id + values = data.spectrocloud_pack.aws_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.aws_k8s.name + tag = data.spectrocloud_pack.aws_k8s.version + uid = data.spectrocloud_pack.aws_k8s.id + values = data.spectrocloud_pack.aws_k8s.values + } + + pack { + name = data.spectrocloud_pack.aws_cni.name + tag = data.spectrocloud_pack.aws_cni.version + uid = data.spectrocloud_pack.aws_cni.id + values = data.spectrocloud_pack.aws_cni.values + } + + pack { + name = data.spectrocloud_pack.aws_csi.name + tag = data.spectrocloud_pack.aws_csi.version + uid = data.spectrocloud_pack.aws_csi.id + values = data.spectrocloud_pack.aws_csi.values + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number + db_password = var.db_password, + auth_token = var.auth_token + }) + } + + pack { + name = data.spectrocloud_pack.kubecost.name + tag = data.spectrocloud_pack.kubecost.version + uid = data.spectrocloud_pack.kubecost.id + values = data.spectrocloud_pack.kubecost.values + } +} + +############################## +# Azure Cluster Profile v1.0.0 +############################## +resource "spectrocloud_cluster_profile" "azure-profile" { + count = var.deploy-azure ? 1 : 0 + + name = "tf-azure-profile" + description = "A basic cluster profile for Azure" + tags = concat(var.tags, ["env:azure"]) + cloud = "azure" + type = "cluster" + version = "1.0.0" + + pack { + name = data.spectrocloud_pack.azure_ubuntu.name + tag = data.spectrocloud_pack.azure_ubuntu.version + uid = data.spectrocloud_pack.azure_ubuntu.id + values = data.spectrocloud_pack.azure_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.azure_k8s.name + tag = data.spectrocloud_pack.azure_k8s.version + uid = data.spectrocloud_pack.azure_k8s.id + values = data.spectrocloud_pack.azure_k8s.values + } + + pack { + name = data.spectrocloud_pack.azure_cni.name + tag = data.spectrocloud_pack.azure_cni.version + uid = data.spectrocloud_pack.azure_cni.id + values = data.spectrocloud_pack.azure_cni.values + } + + pack { + name = data.spectrocloud_pack.azure_csi.name + tag = data.spectrocloud_pack.azure_csi.version + uid = data.spectrocloud_pack.azure_csi.id + values = data.spectrocloud_pack.azure_csi.values + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number + db_password = var.db_password, + auth_token = var.auth_token + }) + } +} + +############################## +# Azure Cluster Profile v1.1.0 +############################## +resource "spectrocloud_cluster_profile" "azure-profile-new" { + count = var.deploy-azure-new ? 1 : 0 + + name = "tf-azure-profile" + description = "A basic cluster profile for Azure with Kubecost" + tags = concat(var.tags, ["env:azure"]) + cloud = "azure" + type = "cluster" + version = "1.1.0" + + pack { + name = data.spectrocloud_pack.azure_ubuntu.name + tag = data.spectrocloud_pack.azure_ubuntu.version + uid = data.spectrocloud_pack.azure_ubuntu.id + values = data.spectrocloud_pack.azure_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.azure_k8s.name + tag = data.spectrocloud_pack.azure_k8s.version + uid = data.spectrocloud_pack.azure_k8s.id + values = data.spectrocloud_pack.azure_k8s.values + } + + pack { + name = data.spectrocloud_pack.azure_cni.name + tag = data.spectrocloud_pack.azure_cni.version + uid = data.spectrocloud_pack.azure_cni.id + values = data.spectrocloud_pack.azure_cni.values + } + + pack { + name = data.spectrocloud_pack.azure_csi.name + tag = data.spectrocloud_pack.azure_csi.version + uid = data.spectrocloud_pack.azure_csi.id + values = data.spectrocloud_pack.azure_csi.values + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number + db_password = var.db_password, + auth_token = var.auth_token + }) + } + + pack { + name = data.spectrocloud_pack.kubecost.name + tag = data.spectrocloud_pack.kubecost.version + uid = data.spectrocloud_pack.kubecost.id + values = data.spectrocloud_pack.kubecost.values + } +} + + +############################ +# GCP Cluster Profile v1.0.0 +############################ +resource "spectrocloud_cluster_profile" "gcp-profile" { + count = var.deploy-gcp ? 1 : 0 + + name = "tf-gcp-profile" + description = "A basic cluster profile for GCP" + tags = concat(var.tags, ["env:GCP"]) + cloud = "gcp" + type = "cluster" + version = "1.0.0" + + pack { + name = data.spectrocloud_pack.gcp_ubuntu.name + tag = data.spectrocloud_pack.gcp_ubuntu.version + uid = data.spectrocloud_pack.gcp_ubuntu.id + values = data.spectrocloud_pack.gcp_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.gcp_k8s.name + tag = data.spectrocloud_pack.gcp_k8s.version + uid = data.spectrocloud_pack.gcp_k8s.id + values = data.spectrocloud_pack.gcp_k8s.values + } + + pack { + name = data.spectrocloud_pack.gcp_cni.name + tag = data.spectrocloud_pack.gcp_cni.version + uid = data.spectrocloud_pack.gcp_cni.id + values = data.spectrocloud_pack.gcp_cni.values + } + + pack { + name = data.spectrocloud_pack.gcp_csi.name + tag = data.spectrocloud_pack.gcp_csi.version + uid = data.spectrocloud_pack.gcp_csi.id + values = data.spectrocloud_pack.gcp_csi.values + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number + db_password = var.db_password, + auth_token = var.auth_token + }) + } +} + +############################ +# GCP Cluster Profile v1.1.0 +############################ +resource "spectrocloud_cluster_profile" "gcp-profile-new" { + count = var.deploy-gcp-new ? 1 : 0 + + name = "tf-gcp-profile" + description = "A basic cluster profile for GCP with Kubecost" + tags = concat(var.tags, ["env:GCP"]) + cloud = "gcp" + type = "cluster" + version = "1.1.0" + + pack { + name = data.spectrocloud_pack.gcp_ubuntu.name + tag = data.spectrocloud_pack.gcp_ubuntu.version + uid = data.spectrocloud_pack.gcp_ubuntu.id + values = data.spectrocloud_pack.gcp_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.gcp_k8s.name + tag = data.spectrocloud_pack.gcp_k8s.version + uid = data.spectrocloud_pack.gcp_k8s.id + values = data.spectrocloud_pack.gcp_k8s.values + } + + pack { + name = data.spectrocloud_pack.gcp_cni.name + tag = data.spectrocloud_pack.gcp_cni.version + uid = data.spectrocloud_pack.gcp_cni.id + values = data.spectrocloud_pack.gcp_cni.values + } + + pack { + name = data.spectrocloud_pack.gcp_csi.name + tag = data.spectrocloud_pack.gcp_csi.version + uid = data.spectrocloud_pack.gcp_csi.id + values = data.spectrocloud_pack.gcp_csi.values + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number, + db_password = var.db_password, + auth_token = var.auth_token + }) + } + + pack { + name = data.spectrocloud_pack.kubecost.name + tag = data.spectrocloud_pack.kubecost.version + uid = data.spectrocloud_pack.kubecost.id + values = data.spectrocloud_pack.kubecost.values + } +} + +################################ +# VMware Cluster Profile v.1.0.0 +################################ +resource "spectrocloud_cluster_profile" "vmware-profile" { + count = var.deploy-vmware ? 1 : 0 + + name = "tf-vmware-profile" + description = "A basic cluster profile for VMware" + tags = concat(var.tags, ["env:VMware"]) + cloud = "vsphere" + type = "cluster" + version = "1.0.0" + + pack { + name = data.spectrocloud_pack.vmware_ubuntu.name + tag = data.spectrocloud_pack.vmware_ubuntu.version + uid = data.spectrocloud_pack.vmware_ubuntu.id + values = data.spectrocloud_pack.vmware_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.vmware_k8s.name + tag = data.spectrocloud_pack.vmware_k8s.version + uid = data.spectrocloud_pack.vmware_k8s.id + values = data.spectrocloud_pack.vmware_k8s.values + } + + pack { + name = data.spectrocloud_pack.vmware_cni.name + tag = data.spectrocloud_pack.vmware_cni.version + uid = data.spectrocloud_pack.vmware_cni.id + values = data.spectrocloud_pack.vmware_cni.values + } + + pack { + name = data.spectrocloud_pack.vmware_csi.name + tag = data.spectrocloud_pack.vmware_csi.version + uid = data.spectrocloud_pack.vmware_csi.id + values = data.spectrocloud_pack.vmware_csi.values + } + + pack { + name = data.spectrocloud_pack.vmware_metallb.name + tag = data.spectrocloud_pack.vmware_metallb.version + uid = data.spectrocloud_pack.vmware_metallb.id + values = replace(data.spectrocloud_pack.vmware_metallb.values, "192.168.10.0/24", var.metallb_ip) + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number, + db_password = var.db_password, + auth_token = var.auth_token + }) + } +} + +############################### +# VMware Cluster Profile v1.1.0 +############################### +resource "spectrocloud_cluster_profile" "vmware-profile-new" { + count = var.deploy-vmware-new ? 1 : 0 + + name = "tf-vmware-profile" + description = "A basic cluster profile for VMware with Kubecost" + tags = concat(var.tags, ["env:VMware"]) + cloud = "vsphere" + type = "cluster" + version = "1.1.0" + + pack { + name = data.spectrocloud_pack.vmware_ubuntu.name + tag = data.spectrocloud_pack.vmware_ubuntu.version + uid = data.spectrocloud_pack.vmware_ubuntu.id + values = data.spectrocloud_pack.vmware_ubuntu.values + } + + pack { + name = data.spectrocloud_pack.vmware_k8s.name + tag = data.spectrocloud_pack.vmware_k8s.version + uid = data.spectrocloud_pack.vmware_k8s.id + values = data.spectrocloud_pack.vmware_k8s.values + } + + pack { + name = data.spectrocloud_pack.vmware_cni.name + tag = data.spectrocloud_pack.vmware_cni.version + uid = data.spectrocloud_pack.vmware_cni.id + values = data.spectrocloud_pack.vmware_cni.values + } + + pack { + name = data.spectrocloud_pack.vmware_csi.name + tag = data.spectrocloud_pack.vmware_csi.version + uid = data.spectrocloud_pack.vmware_csi.id + values = data.spectrocloud_pack.vmware_csi.values + } + + pack { + name = data.spectrocloud_pack.vmware_metallb.name + tag = data.spectrocloud_pack.vmware_metallb.version + uid = data.spectrocloud_pack.vmware_metallb.id + values = replace(data.spectrocloud_pack.vmware_metallb.values, "192.168.10.0/24", var.metallb_ip) + } + + pack { + name = data.spectrocloud_pack.hellouniverse.name + tag = data.spectrocloud_pack.hellouniverse.version + uid = data.spectrocloud_pack.hellouniverse.id + values = templatefile("manifests/values-3tier.yaml", { + namespace = var.app_namespace, + port = var.app_port, + replicas = var.replicas_number, + db_password = var.db_password, + auth_token = var.auth_token + }) + } + + pack { + name = data.spectrocloud_pack.kubecost.name + tag = data.spectrocloud_pack.kubecost.version + uid = data.spectrocloud_pack.kubecost.id + values = data.spectrocloud_pack.kubecost.values + } +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/clusters.tf b/terraform/getting-started-deployment-tf/clusters.tf new file mode 100644 index 0000000..972c855 --- /dev/null +++ b/terraform/getting-started-deployment-tf/clusters.tf @@ -0,0 +1,215 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +############# +# AWS Cluster +############# +resource "spectrocloud_cluster_aws" "aws-cluster" { + count = var.deploy-aws ? 1 : 0 + + name = "aws-cluster" + tags = concat(var.tags, ["env:aws"]) + cloud_account_id = data.spectrocloud_cloudaccount_aws.account[0].id + + cloud_config { + region = var.aws-region + ssh_key_name = var.aws-key-pair-name + } + + cluster_profile { + id = spectrocloud_cluster_profile.aws-profile[0].id + #id = spectrocloud_cluster_profile.aws-profile-new[0].id + } + + machine_pool { + control_plane = true + control_plane_as_worker = true + name = "control-plane-pool" + count = var.aws_control_plane_nodes.count + instance_type = var.aws_control_plane_nodes.instance_type + disk_size_gb = var.aws_control_plane_nodes.disk_size_gb + azs = var.aws_control_plane_nodes.availability_zones + } + + machine_pool { + name = "worker-pool" + count = var.aws_worker_nodes.count + instance_type = var.aws_worker_nodes.instance_type + disk_size_gb = var.aws_worker_nodes.disk_size_gb + azs = var.aws_worker_nodes.availability_zones + } + + timeouts { + create = "30m" + delete = "15m" + } +} +############### +# Azure Cluster +############### +resource "spectrocloud_cluster_azure" "azure-cluster" { + count = var.deploy-azure ? 1 : 0 + + name = "azure-cluster" + tags = concat(var.tags, ["env:azure"]) + cloud_account_id = data.spectrocloud_cloudaccount_azure.account[0].id + + cloud_config { + subscription_id = var.azure_subscription_id + resource_group = var.azure_resource_group + region = var.azure-region + ssh_key = tls_private_key.tutorial_ssh_key_azure[0].public_key_openssh + } + + cluster_profile { + #id = spectrocloud_cluster_profile.azure-profile[0].id + id = spectrocloud_cluster_profile.azure-profile-new[0].id + } + + machine_pool { + control_plane = true + control_plane_as_worker = true + name = "control-plane-pool" + count = var.azure_control_plane_nodes.count + instance_type = var.azure_control_plane_nodes.instance_type + azs = var.azure_control_plane_nodes.azs + is_system_node_pool = var.azure_control_plane_nodes.is_system_node_pool + disk { + size_gb = var.azure_control_plane_nodes.disk_size_gb + type = "Standard_LRS" + } + } + + machine_pool { + name = "worker-basic" + count = var.azure_worker_nodes.count + instance_type = var.azure_worker_nodes.instance_type + azs = var.azure_worker_nodes.azs + is_system_node_pool = var.azure_worker_nodes.is_system_node_pool + } + + timeouts { + create = "30m" + delete = "15m" + } +} + +############# +# GCP Cluster +############# +resource "spectrocloud_cluster_gcp" "gcp-cluster" { + count = var.deploy-gcp ? 1 : 0 + + name = "gcp-cluster" + tags = concat(var.tags, ["env:gcp"]) + cloud_account_id = data.spectrocloud_cloudaccount_gcp.account[0].id + + cloud_config { + project = var.gcp_project_name + region = var.gcp-region + } + + cluster_profile { + id = spectrocloud_cluster_profile.gcp-profile[0].id + #id = spectrocloud_cluster_profile.gcp-profile-new[0].id + } + + machine_pool { + control_plane = true + control_plane_as_worker = true + name = "control-plane-pool" + count = var.gcp_control_plane_nodes.count + instance_type = var.gcp_control_plane_nodes.instance_type + disk_size_gb = var.gcp_control_plane_nodes.disk_size_gb + azs = var.gcp_control_plane_nodes.availability_zones + } + + machine_pool { + name = "worker-pool" + count = var.gcp_worker_nodes.count + instance_type = var.gcp_worker_nodes.instance_type + disk_size_gb = var.gcp_worker_nodes.disk_size_gb + azs = var.gcp_worker_nodes.availability_zones + } + + timeouts { + create = "30m" + delete = "15m" + } +} + +################ +# VMware Cluster +################ + +resource "spectrocloud_cluster_vsphere" "vmware-cluster" { + count = var.deploy-vmware ? 1 : 0 + + name = "vmware-cluster" + tags = concat(var.tags, ["env:vmware"]) + cloud_account_id = data.spectrocloud_cloudaccount_vsphere.account[0].id + + 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.vmware-profile[0].id + #id = spectrocloud_cluster_profile.vmware-profile-new[0].id + } + + scan_policy { + configuration_scan_schedule = "0 0 * * SUN" + penetration_scan_schedule = "0 0 * * SUN" + conformance_scan_schedule = "0 0 1 * *" + } + + 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 + } + + } + + 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 + } + } + +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/data.tf b/terraform/getting-started-deployment-tf/data.tf new file mode 100644 index 0000000..8a1e2ce --- /dev/null +++ b/terraform/getting-started-deployment-tf/data.tf @@ -0,0 +1,173 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +######################################## +# Data resources for the cluster profile +######################################## +data "spectrocloud_registry" "public_registry" { + name = "Public Repo" +} + +data "spectrocloud_registry" "community_registry" { + name = "Palette Community Registry" +} + +############# +# AWS +############# +data "spectrocloud_cloudaccount_aws" "account" { + count = var.deploy-aws ? 1 : 0 + name = var.aws-cloud-account-name +} + +data "spectrocloud_pack" "aws_csi" { + name = "csi-aws-ebs" + version = "1.26.1" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "aws_cni" { + name = "cni-calico" + version = "3.27.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "aws_k8s" { + name = "kubernetes" + version = "1.29.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "aws_ubuntu" { + name = "ubuntu-aws" + version = "22.04" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +############# +# Azure +############# +data "spectrocloud_cloudaccount_azure" "account" { + count = var.deploy-azure ? 1 : 0 + name = var.azure-cloud-account-name +} + +data "spectrocloud_pack" "azure_csi" { + name = "csi-azure" + version = "1.28.3" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "azure_cni" { + name = "cni-calico-azure" + version = "3.26.1" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "azure_k8s" { + name = "kubernetes" + version = "1.27.5" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "azure_ubuntu" { + name = "ubuntu-azure" + version = "22.04" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +############# +# GCP +############# +data "spectrocloud_cloudaccount_gcp" "account" { + count = var.deploy-gcp ? 1 : 0 + name = var.gcp-cloud-account-name +} + +data "spectrocloud_pack" "gcp_csi" { + name = "csi-gcp-driver" + version = "1.12.4" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "gcp_cni" { + name = "cni-calico" + version = "3.27.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "gcp_k8s" { + name = "kubernetes" + version = "1.28.3" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "gcp_ubuntu" { + name = "ubuntu-gcp" + version = "22.04" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +############# +# VMware +############# + +data "spectrocloud_cloudaccount_vsphere" "account" { + count = var.deploy-vmware ? 1 : 0 + name = var.pcg_name +} + +data "spectrocloud_pack" "vmware_ubuntu" { + name = "ubuntu-vsphere" + version = "22.04" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "vmware_k8s" { + name = "kubernetes" + version = "1.28.3" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "vmware_cni" { + name = "cni-calico" + version = "3.26.3" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "vmware_csi" { + name = "csi-vsphere-csi" + version = "3.0.2" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "vmware_metallb" { + name = "lb-metallb-helm" + version = "0.13.11" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +# Required for static IP placement +# data "spectrocloud_private_cloud_gateway" "pcg" { +# name = var.pcg_name +# } + +##################### +# Hello Universe Pack +##################### + +data "spectrocloud_pack" "hellouniverse" { + name = "hello-universe" + version = "1.1.2" + registry_uid = data.spectrocloud_registry.community_registry.id +} + +##################### +# Kubecost Pack +##################### + +data "spectrocloud_pack" "kubecost" { + name = "cost-analyzer" + version = "1.103.3" + registry_uid = data.spectrocloud_registry.community_registry.id +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/inputs.tf b/terraform/getting-started-deployment-tf/inputs.tf new file mode 100644 index 0000000..ac570ad --- /dev/null +++ b/terraform/getting-started-deployment-tf/inputs.tf @@ -0,0 +1,361 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +####### +# AWS +####### +variable "aws-cloud-account-name" { + type = string + description = "The name of your AWS account as assigned in Palette." + default = "" +} + +variable "deploy-aws" { + type = bool + description = "A flag for enabling a deployment on AWS." +} + +variable "deploy-aws-new" { + type = bool + description = "A flag for enabling a deployment on AWS with Kubecost." +} + +variable "aws-region" { + type = string + description = "AWS region" + default = "us-east-1" +} + +variable "aws-key-pair-name" { + type = string + description = "The name of the AWS key pair to use for SSH access to the cluster." + default = "" +} + +variable "aws_control_plane_nodes" { + type = object({ + count = string + control_plane = bool + instance_type = string + disk_size_gb = string + availability_zones = list(string) + }) + default = { + count = "1" + control_plane = true + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1a"] + } + description = "AWS control plane nodes configuration." +} +variable "aws_worker_nodes" { + type = object({ + count = string + control_plane = bool + instance_type = string + disk_size_gb = string + availability_zones = list(string) + }) + default = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1a"] + } + description = "AWS worker nodes configuration." +} + +####### +# Azure +####### +variable "azure-cloud-account-name" { + type = string + description = "The name of your Azure account as assigned in Palette." + default = "" +} + +variable "deploy-azure" { + type = bool + description = "A flag for enabling a deployment on Azure." +} + +variable "deploy-azure-new" { + type = bool + description = "A flag for enabling a deployment on Azure with Kubecost." +} + +variable "azure_subscription_id" { + type = string + description = "Azure subscription ID." + default = "" +} + +variable "azure_resource_group" { + type = string + description = "Azure resource group." + default = "" +} + +variable "azure-use-azs" { + type = bool + description = "A flag for configuring whether to use Azure Availability Zones. Check if your Azure region supports availability zones by reviewing the [Azure Regions and Availability Zones](https://learn.microsoft.com/en-us/azure/reliability/availability-zones-service-support#azure-regions-with-availability-zone-support) resource." +} + +variable "azure-region" { + type = string + description = "Azure region." + default = "eastus" +} + +variable "azure_control_plane_nodes" { + type = object({ + count = string + control_plane = bool + instance_type = string + disk_size_gb = string + azs = list(string) + is_system_node_pool = bool + }) + default = { + count = "1" + control_plane = true + instance_type = "Standard_A8_v2" + disk_size_gb = "60" + azs = ["1"] + is_system_node_pool = false } + description = "Azure control plane nodes configuration." +} + +variable "azure_worker_nodes" { + type = object({ + count = string + control_plane = bool + instance_type = string + disk_size_gb = string + azs = list(string) + is_system_node_pool = bool + }) + default = { + count = "1" + control_plane = false + instance_type = "Standard_A8_v2" + disk_size_gb = "60" + azs = ["1"] + is_system_node_pool = false } + description = "Azure worker nodes configuration." +} + +####### +# GCP +####### +variable "gcp-cloud-account-name" { + type = string + description = "The name of your GCP account as assigned in Palette." + default = "" +} + +variable "gcp_project_name" { + type = string + description = "The name of your GCP project." + default = "" +} + +variable "deploy-gcp" { + type = bool + description = "A flag for enabling a deployment on GCP." +} + +variable "deploy-gcp-new" { + type = bool + description = "A flag for enabling a deployment on GCP with Kubecost." +} + +variable "gcp-region" { + type = string + description = "GCP region" + default = "us-central1" +} + +variable "gcp_control_plane_nodes" { + type = object({ + count = string + control_plane = bool + instance_type = string + disk_size_gb = string + availability_zones = list(string) + }) + default = { + count = "1" + control_plane = true + instance_type = "n1-standard-4" + disk_size_gb = "60" + availability_zones = ["us-central1-a"] } + description = "GCP control plane nodes configuration." +} + +variable "gcp_worker_nodes" { + type = object({ + count = string + control_plane = bool + instance_type = string + disk_size_gb = string + availability_zones = list(string) + }) + default = { + count = "1" + control_plane = false + instance_type = "n1-standard-4" + disk_size_gb = "60" + availability_zones = ["us-central1-a"] } + description = "GCP worker nodes configuration." +} + +variable "tags" { + type = list(string) + description = "The default tags to apply to Palette resources." + default = [ + "spectro-cloud-education", + "app:hello-universe", + "repository:spectrocloud:tutorials", + "terraform_managed:true", + "tutorial:getting-started-terraform" + ] +} + + +######## +# VMware +######## + +variable "deploy-vmware" { + type = bool + description = "A flag for enabling a deployment on VMware." +} + +variable "deploy-vmware-new" { + type = bool + description = "A flag for enabling a deployment on VMware with Kubecost." +} + +variable "metallb_ip" { + type = string + description = "The IP address range for your MetalLB load balancer." +} + +variable "ssh_key" { + type = string + description = "The path to the public key that will be added to the cluster nodes. If not provided, a new key pair will be generated." + + validation { + condition = var.ssh_key == "" ? true : fileexists(var.ssh_key) + error_message = "The provided SSH key file does not exist. Please, provide a valid path." + } +} + +variable "ssh_key_private" { + type = string + description = "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." + + validation { + condition = var.ssh_key_private == "" ? true : fileexists(var.ssh_key_private) + error_message = "The provided SSH key file does not exist. Please, provide a valid path." + } +} + +variable "datacenter_name" { + type = string + description = "The name of the datacenter in vSphere.." +} + +variable "folder_name" { + type = string + description = "The name of the folder in vSphere." +} + +variable "search_domain" { + type = string + description = "The name of network search domain." +} + +# Input resources for the cluster - Placement +variable "vsphere_cluster" { + type = string + description = "The name of your vSphere cluster." +} + +variable "datastore_name" { + type = string + description = "The name of the vSphere datastore." +} + +variable "network_name" { + type = string + description = "The name of the vSphere network." +} + +variable "resource_pool_name" { + type = string + description = "The name of the vSphere resource pool." +} + +variable "pcg_name" { + type = string + description = "The name of the PCG that will be used to deploy the cluster." +} + +# Input resources for the Static IP Pool (required for static IP placement) +# variable "network_gateway" { +# type = string +# description = "The IP address of the vSphere network gateway." +# } + +# variable "network_prefix" { +# type = number +# description = "The prefix of your vSphere network. Valid values are network CIDR subnet masks from the range 0-32. Example: 18." +# } + +# variable "ip_range_start" { +# type = string +# description = "The first 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." +# } + +# variable "nameserver_addr" { +# type = set(string) +# description = "A comma-separated list of DNS nameserver IP addresses of your network." +# } + + +############################## +# Hello Universe App Variables +############################## +variable "app_namespace" { + type = string + description = "The namespace in which the application will be deployed." +} + +variable "app_port" { + type = number + description = "The cluster port number on which the service will listen for incoming traffic." +} + +variable "replicas_number" { + type = number + description = "The number of pods to be created." +} + +variable "db_password" { + type = string + description = "The base64 encoded database password to connect to the API database." +} + +variable "auth_token" { + type = string + description = "The base64 encoded auth token for the API connection." +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/ippool.tf b/terraform/getting-started-deployment-tf/ippool.tf new file mode 100644 index 0000000..042ef14 --- /dev/null +++ b/terraform/getting-started-deployment-tf/ippool.tf @@ -0,0 +1,14 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +# Required for static IP placement. +# resource "spectrocloud_privatecloudgateway_ippool" "ippool" { +# gateway = var.network_gateway +# name = "${var.cluster_name}-ippool" +# network_type = "range" +# prefix = var.network_prefix +# private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg.id +# ip_start_range = var.ip_range_start +# ip_end_range = var.ip_range_end +# nameserver_addresses = var.nameserver_addr +# } \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/manifests/values-3tier.yaml b/terraform/getting-started-deployment-tf/manifests/values-3tier.yaml new file mode 100644 index 0000000..eddbb4a --- /dev/null +++ b/terraform/getting-started-deployment-tf/manifests/values-3tier.yaml @@ -0,0 +1,20 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +pack: + content: + images: + - image: ghcr.io/spectrocloud/hello-universe:1.1.2 + +manifests: + hello-universe: + images: + hellouniverse: ghcr.io/spectrocloud/hello-universe:1.1.2-proxy + hellouniverseapi: ghcr.io/spectrocloud/hello-universe-api:1.0.12 + hellouniversedb: ghcr.io/spectrocloud/hello-universe-db:1.0.2 + apiEnabled: true + namespace: ${namespace} + port: ${port} + replicas: ${replicas} + dbPassword: ${db_password} # Add base64 encoded password + authToken: ${auth_token} # Add base64 encoded token diff --git a/terraform/getting-started-deployment-tf/outputs.tf b/terraform/getting-started-deployment-tf/outputs.tf new file mode 100644 index 0000000..48b2286 --- /dev/null +++ b/terraform/getting-started-deployment-tf/outputs.tf @@ -0,0 +1,35 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +output "Advisory" { + value = <<-EOT + +It takes between one to three minutes for DNS to properly resolve the public load balancer URL. +We recommend waiting a few minutes before clicking on the service URL to prevent the browser from caching an unresolved DNS request. + +EOT +} + +####################### +# VMware SSH Key Output +####################### + +output "ssh_key_location" { + description = "Location of the generated private SSH key file." + value = length(tls_private_key.tutorial_ssh_key) > 0 && var.deploy-vmware == true ? "This is the location of the generated private SSH key file: ${local_sensitive_file.private_key_file[0].filename}." : null +} + +output "ssh_public_key_location" { + description = "Location of the generated public SSH key file." + value = length(tls_private_key.tutorial_ssh_key) > 0 && var.deploy-vmware == true ? "This is the location of the generated public SSH key file: ${local_file.public_key_file[0].filename}." : null +} + +output "ssh_connection_command" { + description = "Command to use the generated private SSH key to access the nodes." + value = length(tls_private_key.tutorial_ssh_key) > 0 && var.deploy-vmware == true ? "To access your nodes, use the following command, replacing with the username and with the IP address of your node: ssh -i ${local_sensitive_file.private_key_file[0].filename} @" : null +} + +output "ssh_connection_command_user" { + description = "Command to use the user's private SSH key to access the nodes." + value = var.ssh_key != "" && var.deploy-vmware == true ? "To access your nodes, use the following command, replacing with the username and with the IP address of your node: ssh -i ${var.ssh_key_private} @" : null +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/provider.tf b/terraform/getting-started-deployment-tf/provider.tf new file mode 100644 index 0000000..1d41efc --- /dev/null +++ b/terraform/getting-started-deployment-tf/provider.tf @@ -0,0 +1,34 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + spectrocloud = { + version = ">= 0.19.0-pre" + source = "spectrocloud/spectrocloud" + } + + tls = { + source = "hashicorp/tls" + version = "4.0.4" + } + + vsphere = { + source = "hashicorp/vsphere" + version = ">= 2.6.1" + } + + local = { + source = "hashicorp/local" + version = "2.4.1" + } + } + + required_version = ">= 1.5" +} + + +provider "spectrocloud" { + # API key set through the environment variable SPECTROCLOUD_APIKEY + project_name = "Default" +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/ssh-key.tf b/terraform/getting-started-deployment-tf/ssh-key.tf new file mode 100644 index 0000000..ee42343 --- /dev/null +++ b/terraform/getting-started-deployment-tf/ssh-key.tf @@ -0,0 +1,39 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +############### +# Azure SSH Key +############### + +resource "tls_private_key" "tutorial_ssh_key_azure" { + count = var.deploy-azure ? 1 : 0 + algorithm = "RSA" + rsa_bits = "4096" +} + +################ +# VMware SSH Key +################ + +resource "tls_private_key" "tutorial_ssh_key" { + count = var.ssh_key == "" && var.ssh_key_private == "" && var.deploy-vmware == true ? 1 : 0 + algorithm = "RSA" + rsa_bits = "4096" +} + +locals { + ssh_public_key = var.ssh_key != "" ? var.ssh_key : length(tls_private_key.tutorial_ssh_key) > 0 ? tls_private_key.tutorial_ssh_key[0].public_key_openssh : null +} + +resource "local_sensitive_file" "private_key_file" { + count = length(tls_private_key.tutorial_ssh_key) > 0 ? 1 : 0 + content = tls_private_key.tutorial_ssh_key[0].private_key_openssh + filename = "${path.module}/tutorial_ssh_key" + file_permission = "0600" +} + +resource "local_file" "public_key_file" { + count = length(tls_private_key.tutorial_ssh_key) > 0 ? 1 : 0 + content = tls_private_key.tutorial_ssh_key[0].public_key_openssh + filename = "${path.module}/tutorial_ssh_key.pub" +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/terraform.tfvars b/terraform/getting-started-deployment-tf/terraform.tfvars new file mode 100644 index 0000000..85d4f1a --- /dev/null +++ b/terraform/getting-started-deployment-tf/terraform.tfvars @@ -0,0 +1,122 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +############################## +# Hello Universe Configuration +############################## + +app_namespace = "hello-universe" # The namespace in which the application will be deployed. +app_port = 8080 # The cluster port number on which the service will listen for incoming traffic. +replicas_number = 1 # The number of pods to be created. +db_password = "REPLACE ME" # The base64 encoded database password to connect to the API database. +auth_token = "REPLACE ME" # The base64 encoded auth token for the API connection. + + +########################### +# AWS Deployment Settings +############################ +deploy-aws = false # Set to true to deploy to AWS. +deploy-aws-new = false # Set to true to deploy to AWS and include Kubecost to your cluster profile. + +aws-cloud-account-name = "REPLACE ME" +aws-region = "REPLACE ME" +aws-key-pair-name = "REPLACE ME" + +aws_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "m4.xlarge" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] # If you want to deploy to multiple AZs, add them here. Example: ["us-east-1a", "us-east-1b"]. +} + +aws_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.xlarge" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] # If you want to deploy to multiple AZs, add them here. Example: ["us-east-1a", "us-east-1b"]. +} + +########################### +# Azure Deployment Settings +############################ +deploy-azure = false # Set to true to deploy to Azure. +deploy-azure-new = false # Set to true to deploy to Azure and include Kubecost to your cluster profile. +azure-use-azs = true # Set to false when you deploy to a region without AZs. + +azure-cloud-account-name = "REPLACE ME" +azure-region = "REPLACE ME" +azure_subscription_id = "REPLACE ME" +azure_resource_group = "REPLACE ME" + + +azure_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "Standard_A8_v2" + disk_size_gb = "60" + azs = ["1"] # If you want to deploy to multiple AZs, add them here. + is_system_node_pool = false +} + +azure_worker_nodes = { + count = "1" + control_plane = false + instance_type = "Standard_A8_v2" + disk_size_gb = "60" + azs = ["1"] # If you want to deploy to multiple AZs, add them here. + is_system_node_pool = false +} + +########################### +# GCP Deployment Settings +############################ +deploy-gcp = false # Set to true to deploy to GCP. +deploy-gcp-new = false # Set to true to deploy to GCP and include Kubecost to your cluster profile. + +gcp-cloud-account-name = "REPLACE ME" +gcp-region = "REPLACE ME" +gcp_project_name = "REPLACE ME" + +gcp_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "n1-standard-4" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] # If you want to deploy to multiple AZs, add them here. Example: ["us-central1-a", "us-central1-b"]. +} + +gcp_worker_nodes = { + count = "1" + control_plane = false + instance_type = "n1-standard-4" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] # If you want to deploy to multiple AZs, add them here. Example: ["us-central1-a", "us-central1-b"]. +} + +############################ +# VMware Deployment Settings +############################ +deploy-vmware = false # Set to true to deploy to VMware. +deploy-vmware-new = false # Set to true to deploy to VMware and include Kubecost to your cluster profile. + +metallb_ip = "REPLACE ME" # Provide a range of IP addresses for your Metallb load balancer. This range must be included in the PCG's static IP pool range if using static IP placement. +pcg_name = "REPLACE ME" # Provide the name of the PCG that will be used to deploy the Palette cluster. +datacenter_name = "REPLACE ME" # Provide the name of the datacenter in vSphere. +folder_name = "REPLACE ME" # Provide the name of the folder in vSphere. +search_domain = "REPLACE ME" # Provide the name of the network search domain. +vsphere_cluster = "REPLACE ME" # Provide the cluster name for the machine pool as it appears in vSphere. +datastore_name = "REPLACE ME" # Provide the datastore name for the machine pool as it appears in vSphere. +network_name = "REPLACE ME" # Provide the network name for the machine pool as it appears in vSphere. +resource_pool_name = "REPLACE ME" # Provide the resource pool name for the machine pool as it appears in vSphere. +ssh_key = "" # Provide the path to your public SSH key. If not provided, a new key pair will be created. +ssh_key_private = "" # Provide the path to your private SSH key. If not provided, a new key pair will be created. + +# Static IP Pool Variables +# Required for static IP placement only. +# network_gateway = "REPLACE ME" # Provide the IP address of the vSphere network gateway. +# network_prefix = "REPLACE ME" # Provide the prefix of your vSphere network. Valid values are network CIDR subnet masks from the range 0-32. Example: 18. +# ip_range_start = "REPLACE ME" # Provide the first IP address of your PCG IP pool range. +# ip_range_end = "REPLACE ME" # Provide the second IP address of your PCG IP pool range. +# nameserver_addr = ["REPLACE ME"] # Provide a comma-separated list of DNS name server IP addresses. \ No newline at end of file