From 77882b1cb35bc3a8c204a0df0c49757eab3533ee Mon Sep 17 00:00:00 2001 From: caroldelwing Date: Mon, 23 Sep 2024 09:54:38 -0400 Subject: [PATCH] fix: add terraform files for the getting started tutorial (#39) * docs: add tf files for the getting started tutorial * fix: address review suggestions * docs: fix azure azs issue * fix: add k9s to the container image, review grammar of docker.md * fix: add terraform tests * fix: addressed review suggestions * fix: update spectro provider version, cluster profile logic, and broken tag * fix: metallb pack type * docs: fix merge conflicts in dockerfile * docs: update pack and images version --- .github/workflows/release.yaml | 2 + .github/workflows/test.yaml | 2 + Dockerfile | 9 +- Makefile | 3 +- README.md | 2 + docs/docker.md | 11 +- .../getting-started-deployment-tf/README.md | 157 ++++++ .../cluster_profiles.tf | 531 ++++++++++++++++++ .../getting-started-deployment-tf/clusters.tf | 211 +++++++ .../getting-started-deployment-tf/data.tf | 174 ++++++ .../getting-started-deployment-tf/inputs.tf | 506 +++++++++++++++++ .../getting-started-deployment-tf/ippool.tf | 15 + .../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 | 127 +++++ .../tests/aws-kubecost.tftest.hcl | 50 ++ .../tests/aws-replace.tftest.hcl | 42 ++ .../tests/aws.tftest.hcl | 45 ++ .../tests/azure-kubecost.tftest.hcl | 37 ++ .../tests/azure-replace.tftest.hcl | 28 + .../tests/azure.tftest.hcl | 37 ++ .../tests/gcp-kubecost.tftest.hcl | 50 ++ .../tests/gcp-replace.tftest.hcl | 42 ++ .../tests/gcp.tftest.hcl | 45 ++ .../tests/pack-hello-uni.tftest.hcl | 39 ++ .../tests/project-palette.tftest.hcl | 18 + .../tests/vmware-ip-pool.tftest.hcl | 31 + .../tests/vmware-kubecost.tftest.hcl | 42 ++ .../tests/vmware-replace.tftest.hcl | 38 ++ .../tests/vmware-ssh.tftest.hcl | 44 ++ .../tests/vmware.tftest.hcl | 37 ++ 33 files changed, 2494 insertions(+), 9 deletions(-) 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 create mode 100644 terraform/getting-started-deployment-tf/tests/aws-kubecost.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/aws-replace.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/aws.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/azure-kubecost.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/azure-replace.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/azure.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/gcp-kubecost.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/gcp-replace.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/gcp.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/pack-hello-uni.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/project-palette.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/vmware-ip-pool.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/vmware-kubecost.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/vmware-replace.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/vmware-ssh.tftest.hcl create mode 100644 terraform/getting-started-deployment-tf/tests/vmware.tftest.hcl diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7aa5496..4ed3866 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,6 +13,7 @@ env: ORAS_VERSION: 1.0.0 TERRAFORM_VERSION: 1.9.0 PALETTE_REGISTRY_CLI_VERSION: 4.3.0 + K9S_VERSION: 0.32.5 jobs: docker: @@ -68,6 +69,7 @@ jobs: ORAS_VERSION=${{env.ORAS_VERSION}} TERRAFORM_VERSION=${{env.TERRAFORM_VERSION}} PALETTE_REGISTRY_CLI_VERSION=${{env.PALETTE_REGISTRY_CLI_VERSION}} + K9S_VERSION=${{env.K9S_VERSION}} platforms: linux/amd64,linux/arm64 push: true tags: ghcr.io/${{ github.repository }}:${{steps.dependencies.outputs.VERSION}} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9a14f33..d9eb5a8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,6 +13,7 @@ env: ORAS_VERSION: 1.0.0 TERRAFORM_VERSION: 1.9.0 PALETTE_REGISTRY_CLI_VERSION: 4.3.0 + K9S_VERSION: 0.32.5 concurrency: group: docker-${{ github.ref }} @@ -77,3 +78,4 @@ jobs: ORAS_VERSION=${{env.ORAS_VERSION}} TERRAFORM_VERSION=${{env.TERRAFORM_VERSION}} PALETTE_REGISTRY_CLI_VERSION=${{env.PALETTE_REGISTRY_CLI_VERSION}} + K9S_VERSION=${{env.K9S_VERSION}} diff --git a/Dockerfile b/Dockerfile index ce61c5b..5294492 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ ARG PALETTE_REGISTRY_CLI_VERSION ARG PACKER_VERSION ARG ORAS_VERSION ARG TERRAFORM_VERSION +ARG K9S_VERSION ENV REGISTRY_LOG_LEVEL=info ENV REGISTRY_AUTH=htpasswd @@ -64,16 +65,18 @@ RUN wget https://spectro-cli.s3.amazonaws.com/v$PALETTE_REGISTRY_CLI_VERSION/li rm -rf oras_${ORAS_VERSION}_*.tar.gz oras-install/ && \ git clone https://github.com/spectrocloud/CanvOS.git && \ rm -rf /var/cache/apk/* && \ + wget https://github.com/derailed/k9s/releases/download/v${K9S_VERSION}/k9s_Linux_amd64.tar.gz -O - | tar -xz -C /usr/local/bin && \ + rm -rf k9s_Linux_amd64.tar && \ wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \ unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin && \ rm -rf terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \ - mkdir -p /var/log/ && chmod 777 /var/log/ + mkdir -p /var/log/ && chmod 777 /var/log/ ADD https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip /usr/local/sbin/ RUN unzip /usr/local/sbin/packer_${PACKER_VERSION}_linux_amd64.zip -d /usr/local/sbin && \ rm -rf /usr/local/sbin/packer_${PACKER_VERSION}_linux_amd64.zip && \ - mkdir -p /home/appuser/.config/packer && mkdir /root/.spectro && \ - chown -R appuser:appuser /home/appuser/.config/packer terraform/ packs/ edge/ CanvOS/ /var/log/ /root/.spectro/ /etc/spectro/ + mkdir -p /home/appuser/.config/packer && mkdir /root/.spectro && mkdir -p /home/appuser/.config/k9s && mkdir -p /home/appuser/etc/xdg/k9s && \ + chown -R appuser:appuser /home/appuser/.config/packer terraform/ packs/ edge/ CanvOS/ /var/log/ /root/.spectro/ /etc/spectro/ /home/appuser/.config/k9s /home/appuser/etc/xdg/k9s EXPOSE 5000 USER appuser diff --git a/Makefile b/Makefile index 3c56833..3d48f9a 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,9 @@ build-docker: ## Build docker image --build-arg PALETTE_CLI_VERSION=$(PALETTE_CLI_VERION) \ --build-arg PALETTE_EDGE_VERSION=$(PALETTE_EDGE_VERSION) \ --build-arg PACKER_VERSION=$(PACKER_VERSION) \ - --build-arg ORAS_VERSION=$(PACKER_VERSION) \ + --build-arg ORAS_VERSION=$(ORAS_VERSION) \ --build-arg TERRAFORM_VERSION=$(TERRAFORM_VERSION) \ + --build-arg K9S_VERSION=$(K9S_VERSION) \ -t tutorials . 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/docs/docker.md b/docs/docker.md index 25c8061..23a2c08 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -1,6 +1,6 @@ ## Docker -To download the image issue the following commnad. Change the version tag as needed. +To download the image, issue the following command. Change the version tag as needed. ```shell docker pull ghcr.io/spectrocloud/tutorials:1.0.12 @@ -12,7 +12,7 @@ You can start the container using the following command. docker run -p 5000:5000 --rm -it ghcr.io/spectrocloud/tutorials:1.0.12 bash ``` -> The Docker file is build for a Linux environment. You can use this on a Mac and Windows. Windows users will require the usage of WSL2. +> The Docker file builds a Linux environment. You can use this image on a Mac and Windows. Windows users will require the usage of [WSL2](https://learn.microsoft.com/en-us/windows/wsl/about). The Docker image includes the following tools. @@ -41,6 +41,7 @@ The Docker image includes the following tools. | `aws-cli` | AWS command-line interface | | `oras` | Tool for pushing and pulling OCI artifacts to and from OCI registries | | `podman` | Tool for building and deploying OCI images | +| `k9s` | Tool that provides a terminal UI to interact with your Kubernetes clusters | ### Spectro Cloud Pack Registry Server @@ -50,7 +51,7 @@ The Spectro Cloud registry server has the following credentials: - `password`: `admin` -You can start the registry server by issuing the following command. +You can start the registry server by issuing the command below. Keep in mind that the registry server is started in HTTP mode. For additional guidance, review the [Registry Server documentation](https://docs.spectrocloud.com/registries-and-packs/adding-a-custom-registry). ```shell @@ -59,8 +60,8 @@ registry serve /etc/spectro/config.yml > /var/log/registry.log 2>&1 & # Local Builds -If you are wanting to build the docker image locally you must provide the the build arguments for `PALETTE_VERSION`, `PALETTE_CLI_VERSION`, `PALETTE_EDGE_VERSION`, `PACKER_VERSION`, `ORAS_VERSION` and `TERRAFORM_VERSION`. Use the following command to build a local image. Replace the versions as needed. +If you want to build the docker image locally, you must provide the build arguments for `PALETTE_VERSION`, `PALETTE_CLI_VERSION`, `PALETTE_EDGE_VERSION`, `PACKER_VERSION`, `ORAS_VERSION`, `TERRAFORM_VERSION`, and `K9S_VERSION`. Use the following command to build a local image and replace the versions as needed. ```shell -docker build --build-arg PALETTE_VERSION=4.0.2 --build-arg PALETTE_CLI_VERSION=4.4.0 --build-arg PALETTE_EDGE_VERSION=4.4.2 --build-arg PACKER_VERSION=1.11.0 --build-arg ORAS_VERSION=1.0.0 --build-arg PALETTE_REGISTRY_CLI_VERSION=4.3.0 --build-arg TERRAFORM_VERSION=1.9.0 -t tutorials . +docker build --build-arg PALETTE_VERSION=4.0.2 --build-arg PALETTE_CLI_VERSION=4.4.0 --build-arg PALETTE_EDGE_VERSION=4.4.2 --build-arg PACKER_VERSION=1.11.0 --build-arg ORAS_VERSION=1.0.0 --build-arg PALETTE_REGISTRY_CLI_VERSION=4.3.0 --build-arg TERRAFORM_VERSION=1.9.0 --build-arg K9S_VERSION=0.32.5 -t 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..1760396 --- /dev/null +++ b/terraform/getting-started-deployment-tf/README.md @@ -0,0 +1,157 @@ +# Getting Started Cluster Deployment + +This folder contains the demo code for the **Getting Started Cluster Management with Terraform** tutorials. + + + +The Terraform code has four 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` | +| `deploy-vmware` | VMware vSphere | Enable to deploy a cluster to VMware vSphere. | `false` | + +> You can enable as many providers as you want, just make sure to specify all required values for each provider. + +To get started, open the **terraform.tfvars** file. Toggle the provider variable as specified in the table and provide values to your cloud provider variables, replacing all instances of the string `REPLACE ME`. + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.9 | +| [local](#requirement\_local) | 2.4.1 | +| [spectrocloud](#requirement\_spectrocloud) | >= 0.20.6 | +| [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.20.6 | +| [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-kubecost](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-kubecost](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-kubecost](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-kubecost](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 | +| [spectrocloud_privatecloudgateway_ippool.ippool](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/privatecloudgateway_ippool) | 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_private_cloud_gateway.pcg](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/private_cloud_gateway) | 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` | n/a | yes | +| [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` | n/a | yes | +| [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-kubecost](#input\_deploy-aws-kubecost) | 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-kubecost](#input\_deploy-azure-kubecost) | 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-kubecost](#input\_deploy-gcp-kubecost) | 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-kubecost](#input\_deploy-vmware-kubecost) | A flag for enabling a deployment on VMware with Kubecost. | `bool` | n/a | yes | +| [deploy-vmware-static](#input\_deploy-vmware-static) | A flag for enabling a deployment on VMware using static IP placement. | `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 | +| [ip\_range\_end](#input\_ip\_range\_end) | The last IP address of your PCG IP pool range. | `string` | n/a | yes | +| [ip\_range\_start](#input\_ip\_range\_start) | The first IP address of your PCG IP pool range. | `string` | n/a | yes | +| [metallb\_ip](#input\_metallb\_ip) | The IP address range for your MetalLB load balancer. | `string` | n/a | yes | +| [nameserver\_addr](#input\_nameserver\_addr) | A comma-separated list of DNS nameserver IP addresses of your network. | `set(string)` | n/a | yes | +| [network\_gateway](#input\_network\_gateway) | The IP address of the vSphere network gateway. | `string` | n/a | yes | +| [network\_name](#input\_network\_name) | The name of the vSphere network. | `string` | n/a | yes | +| [network\_prefix](#input\_network\_prefix) | The prefix of your vSphere network. Valid values are network CIDR subnet masks from the range 0-32. Example: 18. | `number` | n/a | yes | +| [palette-project](#input\_palette-project) | The name of your project in Palette. | `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",
"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..cee044a --- /dev/null +++ b/terraform/getting-started-deployment-tf/cluster_profiles.tf @@ -0,0 +1,531 @@ +# 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } +} + +############################ +# AWS Cluster Profile v1.1.0 +############################ +resource "spectrocloud_cluster_profile" "aws-profile-kubecost" { + count = var.deploy-aws ? 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } + + 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 + type = "oci" + } +} + +############################## +# 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } +} + +############################## +# Azure Cluster Profile v1.1.0 +############################## +resource "spectrocloud_cluster_profile" "azure-profile-kubecost" { + count = var.deploy-azure ? 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } + + 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 + type = "oci" + } +} + + +############################ +# 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } +} + +############################ +# GCP Cluster Profile v1.1.0 +############################ +resource "spectrocloud_cluster_profile" "gcp-profile-kubecost" { + count = var.deploy-gcp ? 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } + + 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 + type = "oci" + } +} + +################################ +# 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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) + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } +} + +############################### +# VMware Cluster Profile v1.1.0 +############################### +resource "spectrocloud_cluster_profile" "vmware-profile-kubecost" { + count = var.deploy-vmware ? 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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 + type = "spectro" + } + + 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) + type = "spectro" + } + + 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 = base64encode(var.db_password), + auth_token = base64encode(var.auth_token) + }) + type = "oci" + } + + 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 + type = "oci" + } +} \ 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..5e172dc --- /dev/null +++ b/terraform/getting-started-deployment-tf/clusters.tf @@ -0,0 +1,211 @@ +# 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 = var.deploy-aws && var.deploy-aws-kubecost ? resource.spectrocloud_cluster_profile.aws-profile-kubecost[0].id : resource.spectrocloud_cluster_profile.aws-profile[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 = var.deploy-azure && var.deploy-azure-kubecost ? resource.spectrocloud_cluster_profile.azure-profile-kubecost[0].id : resource.spectrocloud_cluster_profile.azure-profile[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-use-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-use-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 = var.deploy-gcp && var.deploy-gcp-kubecost ? resource.spectrocloud_cluster_profile.gcp-profile-kubecost[0].id : resource.spectrocloud_cluster_profile.gcp-profile[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_keys = [local.ssh_public_key] + datacenter = var.datacenter_name + folder = var.folder_name + static_ip = var.deploy-vmware-static # 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 = var.deploy-vmware && var.deploy-vmware-kubecost ? resource.spectrocloud_cluster_profile.vmware-profile-kubecost[0].id : resource.spectrocloud_cluster_profile.vmware-profile[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 = var.deploy-vmware-static ? resource.spectrocloud_privatecloudgateway_ippool.ippool[0].id : null + } + + } + + 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 = var.deploy-vmware-static ? resource.spectrocloud_privatecloudgateway_ippool.ippool[0].id : null + } + } + +} \ 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..26fd122 --- /dev/null +++ b/terraform/getting-started-deployment-tf/data.tf @@ -0,0 +1,174 @@ +# 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" { + count = var.deploy-vmware-static ? 1 : 0 + name = var.pcg_name +} + +##################### +# Hello Universe Pack +##################### + +data "spectrocloud_pack" "hellouniverse" { + name = "hello-universe" + version = "1.2.0" + 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..629893d --- /dev/null +++ b/terraform/getting-started-deployment-tf/inputs.tf @@ -0,0 +1,506 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +######### +# Palette +######### + +variable "palette-project" { + type = string + description = "The name of your project in Palette." + + validation { + condition = var.palette-project != "" + error_message = "Provide the correct Palette project." + } + +} + +####### +# AWS +####### +variable "aws-cloud-account-name" { + type = string + description = "The name of your AWS account as assigned in Palette." + + validation { + condition = var.deploy-aws ? var.aws-cloud-account-name != "REPLACE ME" && var.aws-cloud-account-name != "" : true + error_message = "Provide the correct AWS cloud account name." + } +} + +variable "deploy-aws" { + type = bool + description = "A flag for enabling a deployment on AWS." +} + +variable "deploy-aws-kubecost" { + 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" + + validation { + condition = var.deploy-aws ? var.aws-region != "REPLACE ME" && var.aws-region != "" : true + error_message = "Provide the correct AWS region." + } +} + +variable "aws-key-pair-name" { + type = string + description = "The name of the AWS key pair to use for SSH access to the cluster." + + validation { + condition = var.deploy-aws ? var.aws-key-pair-name != "REPLACE ME" && var.aws-key-pair-name != "" : true + error_message = "Provide the correct AWS SSH key pair name." + } +} + +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." + + validation { + condition = var.deploy-aws ? length(var.aws_control_plane_nodes.availability_zones) > 0 && !contains(var.aws_control_plane_nodes.availability_zones, "REPLACE ME") : true + error_message = "The availability_zones parameter must be set correctly" + } +} +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." + + validation { + condition = var.deploy-aws ? length(var.aws_worker_nodes.availability_zones) > 0 && !contains(var.aws_worker_nodes.availability_zones, "REPLACE ME") : true + error_message = "The availability_zones parameter must be set correctly" + } +} + +####### +# Azure +####### +variable "azure-cloud-account-name" { + type = string + description = "The name of your Azure account as assigned in Palette." + default = "" + + validation { + condition = var.deploy-azure ? var.azure-cloud-account-name != "REPLACE ME" && var.azure-cloud-account-name != "" : true + error_message = "Provide the correct Azure cloud account name." + } +} + +variable "deploy-azure" { + type = bool + description = "A flag for enabling a deployment on Azure." +} + +variable "deploy-azure-kubecost" { + type = bool + description = "A flag for enabling a deployment on Azure with Kubecost." +} + +variable "azure_subscription_id" { + type = string + description = "Azure subscription ID." + default = "" + + validation { + condition = var.deploy-azure ? var.azure_subscription_id != "REPLACE ME" && var.azure_subscription_id != "" : true + error_message = "Provide the correct Azure subscription ID." + } +} + +variable "azure_resource_group" { + type = string + description = "Azure resource group." + default = "" + + validation { + condition = var.deploy-azure ? var.azure_resource_group != "REPLACE ME" && var.azure_resource_group != "" : true + error_message = "Provide the correct Azure resource group name." + } +} + +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" + + validation { + condition = var.deploy-azure ? var.azure-region != "REPLACE ME" && var.azure-region != "" : true + error_message = "Provide the correct Azure region name." + } +} + +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 = "" + + validation { + condition = var.deploy-gcp ? var.gcp-cloud-account-name != "REPLACE ME" && var.gcp-cloud-account-name != "" : true + error_message = "Provide the correct GCP cloud account name." + } +} + +variable "gcp_project_name" { + type = string + description = "The name of your GCP project." + default = "" + + validation { + condition = var.deploy-gcp ? var.gcp_project_name != "REPLACE ME" && var.gcp_project_name != "" : true + error_message = "Provide the correct GCP project name." + } +} + +variable "deploy-gcp" { + type = bool + description = "A flag for enabling a deployment on GCP." +} + +variable "deploy-gcp-kubecost" { + type = bool + description = "A flag for enabling a deployment on GCP with Kubecost." +} + +variable "gcp-region" { + type = string + description = "GCP region" + default = "us-central1" + + validation { + condition = var.deploy-gcp ? var.gcp-region != "REPLACE ME" && var.gcp-region != "" : true + error_message = "Provide the correct GCP region." + } +} + +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." + + validation { + condition = var.deploy-gcp ? length(var.gcp_control_plane_nodes.availability_zones) > 0 && !contains(var.gcp_control_plane_nodes.availability_zones, "REPLACE ME") : true + error_message = "The availability_zones parameter must be set correctly" + } +} + +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." + + validation { + condition = var.deploy-gcp ? length(var.gcp_worker_nodes.availability_zones) > 0 && !contains(var.gcp_worker_nodes.availability_zones, "REPLACE ME") : true + error_message = "The availability_zones parameter must be set correctly" + } +} + +variable "tags" { + type = list(string) + description = "The default tags to apply to Palette resources." + default = [ + "spectro-cloud-education", + "app:hello-universe", + "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-kubecost" { + 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." + + validation { + condition = var.deploy-vmware ? var.metallb_ip != "REPLACE ME" && var.metallb_ip != "" : true + error_message = "Provide the correct MetalLB IP." + } +} + +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." + + validation { + condition = var.deploy-vmware ? var.datacenter_name != "REPLACE ME" && var.datacenter_name != "" : true + error_message = "Provide the correct VMware vSphere datacenter name." + } +} + +variable "folder_name" { + type = string + description = "The name of the folder in vSphere." + + validation { + condition = var.deploy-vmware ? var.folder_name != "REPLACE ME" && var.folder_name != "" : true + error_message = "Provide the correct VMware vSphere folder name." + } +} + +variable "search_domain" { + type = string + description = "The name of network search domain." + + validation { + condition = var.deploy-vmware ? var.search_domain != "REPLACE ME" && var.search_domain != "" : true + error_message = "Provide the correct VMware vSphere search domain." + } +} + +# Input resources for the cluster - Placement +variable "vsphere_cluster" { + type = string + description = "The name of your vSphere cluster." + + validation { + condition = var.deploy-vmware ? var.vsphere_cluster != "REPLACE ME" && var.vsphere_cluster != "" : true + error_message = "Provide the correct VMware vSphere cluster name." + } +} + +variable "datastore_name" { + type = string + description = "The name of the vSphere datastore." + + validation { + condition = var.deploy-vmware ? var.datastore_name != "REPLACE ME" && var.datastore_name != "" : true + error_message = "Provide the correct VMware vSphere datastore name." + } +} + +variable "network_name" { + type = string + description = "The name of the vSphere network." + + validation { + condition = var.deploy-vmware ? var.network_name != "REPLACE ME" && var.network_name != "" : true + error_message = "Provide the correct VMware vSphere network name." + } +} + +variable "resource_pool_name" { + type = string + description = "The name of the vSphere resource pool." + + validation { + condition = var.deploy-vmware ? var.resource_pool_name != "REPLACE ME" && var.resource_pool_name != "" : true + error_message = "Provide the correct VMware vSphere resource pool name." + } +} + +variable "pcg_name" { + type = string + description = "The name of the PCG that will be used to deploy the cluster." + + validation { + condition = var.deploy-vmware ? var.pcg_name != "REPLACE ME" && var.pcg_name != "" : true + error_message = "Provide the correct VMware vSphere PCG name." + } +} + +# Input resources for the Static IP Pool (required for static IP placement only) +variable "deploy-vmware-static" { + type = bool + description = "A flag for enabling a deployment on VMware using 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." + sensitive = true + + validation { + condition = var.deploy-aws || var.deploy-azure || var.deploy-gcp || var.deploy-vmware ? var.db_password != "REPLACE ME" && var.db_password != "" : true + error_message = "Provide the correct database password." + } +} + +variable "auth_token" { + type = string + description = "The base64 encoded auth token for the API connection." + sensitive = true + + validation { + condition = var.deploy-aws || var.deploy-azure || var.deploy-gcp || var.deploy-vmware ? var.auth_token != "REPLACE ME" && var.auth_token != "" : true + error_message = "Provide the correct authentication token." + } +} \ 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..373cfb5 --- /dev/null +++ b/terraform/getting-started-deployment-tf/ippool.tf @@ -0,0 +1,15 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +# Required for static IP placement. +resource "spectrocloud_privatecloudgateway_ippool" "ippool" { + count = var.deploy-vmware-static ? 1 : 0 + gateway = var.network_gateway + name = "vsphere-vmware-ippool" + network_type = "range" + prefix = var.network_prefix + private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.pcg[0].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..9fef889 --- /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.2.0 + +manifests: + hello-universe: + images: + hellouniverse: ghcr.io/spectrocloud/hello-universe:1.2.0-proxy + hellouniverseapi: ghcr.io/spectrocloud/hello-universe-api:1.1.0 + hellouniversedb: ghcr.io/spectrocloud/hello-universe-db:1.1.0 + 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..977dcc6 --- /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.20.6" + 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.9" +} + + +provider "spectrocloud" { + # API key set through the environment variable SPECTROCLOUD_APIKEY + project_name = var.palette-project +} \ 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..83da6bd --- /dev/null +++ b/terraform/getting-started-deployment-tf/terraform.tfvars @@ -0,0 +1,127 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +##################### +# Palette Settings +##################### +palette-project = "Default" # The name of your project in Palette. + + +############################## +# 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 database password to connect to the API database. +auth_token = "REPLACE ME" # The auth token for the API connection. + + +########################### +# AWS Deployment Settings +############################ +deploy-aws = false # Set to true to deploy to AWS. +deploy-aws-kubecost = 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-kubecost = 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-kubecost = 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-kubecost = 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. +deploy-vmware-static = false # Set to true to deploy to VMware using static IP placement. +network_gateway = "REPLACE ME" # Provide the IP address of the vSphere network gateway. +network_prefix = 0 # 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 diff --git a/terraform/getting-started-deployment-tf/tests/aws-kubecost.tftest.hcl b/terraform/getting-started-deployment-tf/tests/aws-kubecost.tftest.hcl new file mode 100644 index 0000000..347de6b --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/aws-kubecost.tftest.hcl @@ -0,0 +1,50 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 4 + +variables { + deploy-aws = true + deploy-aws-kubecost = true + db_password = "test_password" + auth_token = "test_token" + aws-cloud-account-name = "test-account" + aws-region = "test-region" + aws-key-pair-name = "test-aws-key-pair" + aws_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } + aws_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } +} + +mock_provider "spectrocloud" { +} + +run "verify_aws_kubecost" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.aws-profile) == 1 + error_message = "No AWS cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_profile.aws-profile-kubecost) == 1 + error_message = "No AWS cluster profile with Kubecost was created" + } + + assert { + condition = length(spectrocloud_cluster_aws.aws-cluster) == 1 + error_message = "No AWS cluster was created" + } +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/tests/aws-replace.tftest.hcl b/terraform/getting-started-deployment-tf/tests/aws-replace.tftest.hcl new file mode 100644 index 0000000..374b02c --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/aws-replace.tftest.hcl @@ -0,0 +1,42 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 5 + +variables { + deploy-aws = true + db_password = "test_password" + auth_token = "test_token" + 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.2xlarge" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] + } + aws_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] + } +} + +mock_provider "spectrocloud" {} + +run "verify_aws" { + + command = plan + + expect_failures = [ + var.aws-cloud-account-name, + var.aws-key-pair-name, + var.aws-region, + var.aws_control_plane_nodes.availability_zones, + var.aws_worker_nodes.availability_zones + ] + +} diff --git a/terraform/getting-started-deployment-tf/tests/aws.tftest.hcl b/terraform/getting-started-deployment-tf/tests/aws.tftest.hcl new file mode 100644 index 0000000..69f86cf --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/aws.tftest.hcl @@ -0,0 +1,45 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 3 + +variables { + deploy-aws = true + db_password = "test_password" + auth_token = "test_token" + aws-cloud-account-name = "test-account" + aws-region = "test-region" + aws-key-pair-name = "test-aws-key-pair" + aws_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } + aws_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } +} + +mock_provider "spectrocloud" { +} + +run "verify_aws" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.aws-profile) == 1 + error_message = "No AWS cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_aws.aws-cluster) == 1 + error_message = "No AWS cluster was created" + } + +} diff --git a/terraform/getting-started-deployment-tf/tests/azure-kubecost.tftest.hcl b/terraform/getting-started-deployment-tf/tests/azure-kubecost.tftest.hcl new file mode 100644 index 0000000..b00825a --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/azure-kubecost.tftest.hcl @@ -0,0 +1,37 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 7 + +variables { + deploy-azure = true + deploy-azure-kubecost = true + db_password = "test_password" + auth_token = "test_token" + azure-cloud-account-name = "test-account" + azure-region = "test-region" + azure_subscription_id = "test-azure-subscription-id" + azure_resource_group = "test-azure-resource-group" +} + +mock_provider "spectrocloud" { +} + +run "verify_azure_kubecost" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.azure-profile) == 1 + error_message = "No Azure cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_profile.azure-profile-kubecost) == 1 + error_message = "No Azure cluster profile with Kubecost was created" + } + + assert { + condition = length(spectrocloud_cluster_azure.azure-cluster) == 1 + error_message = "No Azure cluster was created" + } +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/tests/azure-replace.tftest.hcl b/terraform/getting-started-deployment-tf/tests/azure-replace.tftest.hcl new file mode 100644 index 0000000..66fe232 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/azure-replace.tftest.hcl @@ -0,0 +1,28 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 8 + +variables { + deploy-azure = true + db_password = "test_password" + auth_token = "test_token" + azure-cloud-account-name = "REPLACE ME" + azure-region = "REPLACE ME" + azure_subscription_id = "REPLACE ME" + azure_resource_group = "REPLACE ME" +} + +mock_provider "spectrocloud" {} + +run "verify_azure_replace" { + + command = plan + + expect_failures = [ + var.azure-cloud-account-name, + var.azure-region, + var.azure_subscription_id, + var.azure_resource_group + ] + +} diff --git a/terraform/getting-started-deployment-tf/tests/azure.tftest.hcl b/terraform/getting-started-deployment-tf/tests/azure.tftest.hcl new file mode 100644 index 0000000..f84c3c9 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/azure.tftest.hcl @@ -0,0 +1,37 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 6 + +variables { + deploy-azure = true + db_password = "test_password" + auth_token = "test_token" + azure-cloud-account-name = "test-account" + azure-region = "test-region" + azure_subscription_id = "test-azure-subscription-id" + azure_resource_group = "test-azure-resource-group" +} + +mock_provider "spectrocloud" { +} + +run "verify_azure" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.azure-profile) == 1 + error_message = "No Azure cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_azure.azure-cluster) == 1 + error_message = "No Azure cluster was created" + } + + assert { + condition = length(tls_private_key.tutorial_ssh_key_azure) == 1 + error_message = "No Azure SSH key was created" + } + +} diff --git a/terraform/getting-started-deployment-tf/tests/gcp-kubecost.tftest.hcl b/terraform/getting-started-deployment-tf/tests/gcp-kubecost.tftest.hcl new file mode 100644 index 0000000..f046a88 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/gcp-kubecost.tftest.hcl @@ -0,0 +1,50 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 11 + +variables { + deploy-gcp = true + deploy-gcp-kubecost = true + db_password = "test_password" + auth_token = "test_token" + gcp-cloud-account-name = "test-account" + gcp-region = "test-region" + gcp_project_name = "test-aws-key-pair" + gcp_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } + gcp_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } +} + +mock_provider "spectrocloud" { +} + +run "verify_gcp_kubecost" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.gcp-profile) == 1 + error_message = "No GCP cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_profile.gcp-profile-kubecost) == 1 + error_message = "No GCP cluster profile with Kubecost was created" + } + + assert { + condition = length(spectrocloud_cluster_gcp.gcp-cluster) == 1 + error_message = "No GCP cluster was created" + } +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/tests/gcp-replace.tftest.hcl b/terraform/getting-started-deployment-tf/tests/gcp-replace.tftest.hcl new file mode 100644 index 0000000..d6a7721 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/gcp-replace.tftest.hcl @@ -0,0 +1,42 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 12 + +variables { + deploy-gcp = true + db_password = "test_password" + auth_token = "test_token" + 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 = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] + } + gcp_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["REPLACE ME"] + } +} + +mock_provider "spectrocloud" {} + +run "verify_gcp" { + + command = plan + + expect_failures = [ + var.gcp-cloud-account-name, + var.gcp_project_name, + var.gcp-region, + var.gcp_control_plane_nodes.availability_zones, + var.gcp_worker_nodes.availability_zones + ] + +} diff --git a/terraform/getting-started-deployment-tf/tests/gcp.tftest.hcl b/terraform/getting-started-deployment-tf/tests/gcp.tftest.hcl new file mode 100644 index 0000000..660b80a --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/gcp.tftest.hcl @@ -0,0 +1,45 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 10 + +variables { + deploy-gcp = true + db_password = "test_password" + auth_token = "test_token" + gcp-cloud-account-name = "test-account" + gcp-region = "test-region" + gcp_project_name = "test-aws-key-pair" + gcp_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } + gcp_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } +} + +mock_provider "spectrocloud" { +} + +run "verify_gcp" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.gcp-profile) == 1 + error_message = "No GCP cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_gcp.gcp-cluster) == 1 + error_message = "No GCP cluster was created" + } + +} diff --git a/terraform/getting-started-deployment-tf/tests/pack-hello-uni.tftest.hcl b/terraform/getting-started-deployment-tf/tests/pack-hello-uni.tftest.hcl new file mode 100644 index 0000000..7197a36 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/pack-hello-uni.tftest.hcl @@ -0,0 +1,39 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 2 + +variables { + deploy-aws = true + db_password = "REPLACE ME" + auth_token = "REPLACE ME" + aws-cloud-account-name = "test-account" + aws-region = "test-region" + aws-key-pair-name = "test-aws-key-pair" + aws_control_plane_nodes = { + count = "1" + control_plane = true + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } + aws_worker_nodes = { + count = "1" + control_plane = false + instance_type = "m4.2xlarge" + disk_size_gb = "60" + availability_zones = ["us-east-1"] + } +} + +mock_provider "spectrocloud" {} + +run "wrong_variables" { + + command = plan + + expect_failures = [ + var.auth_token, + var.db_password + ] + +} diff --git a/terraform/getting-started-deployment-tf/tests/project-palette.tftest.hcl b/terraform/getting-started-deployment-tf/tests/project-palette.tftest.hcl new file mode 100644 index 0000000..c8e0f96 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/project-palette.tftest.hcl @@ -0,0 +1,18 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 1 + +variables { + palette-project = "" +} + +run "project_variable" { + + command = plan + + expect_failures = [ + var.palette-project + ] + + +} diff --git a/terraform/getting-started-deployment-tf/tests/vmware-ip-pool.tftest.hcl b/terraform/getting-started-deployment-tf/tests/vmware-ip-pool.tftest.hcl new file mode 100644 index 0000000..0bbbaf2 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/vmware-ip-pool.tftest.hcl @@ -0,0 +1,31 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 17 + +variables { + deploy-vmware = true + deploy-vmware-static = true + db_password = "test_password" + auth_token = "test_token" + metallb_ip = "test_ip" + pcg_name = "test_pcg" + datacenter_name = "test_datacenter" + folder_name = "test_folder" + search_domain = "test_search_domain" + vsphere_cluster = "test_cluster" + datastore_name = "test_datastore" + network_name = "test_network" + resource_pool_name = "test_resource_pool" +} + +mock_provider "spectrocloud" {} + +run "verify_vmware" { + + command = plan + + assert { + condition = length(spectrocloud_privatecloudgateway_ippool.ippool) == 1 + error_message = "No VMware IP pool was created" + } +} diff --git a/terraform/getting-started-deployment-tf/tests/vmware-kubecost.tftest.hcl b/terraform/getting-started-deployment-tf/tests/vmware-kubecost.tftest.hcl new file mode 100644 index 0000000..635f8ef --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/vmware-kubecost.tftest.hcl @@ -0,0 +1,42 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 14 + +variables { + deploy-vmware = true + deploy-vmware-kubecost = true + db_password = "test_password" + auth_token = "test_token" + metallb_ip = "test_ip" + pcg_name = "test_pcg" + datacenter_name = "test_datacenter" + folder_name = "test_folder" + search_domain = "test_search_domain" + vsphere_cluster = "test_cluster" + datastore_name = "test_datastore" + network_name = "test_network" + resource_pool_name = "test_resource_pool" +} + +mock_provider "spectrocloud" { +} + +run "verify_vmware_kubecost" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.vmware-profile) == 1 + error_message = "No VMware cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_profile.vmware-profile-kubecost) == 1 + error_message = "No VMware cluster profile with Kubecost was created" + } + + assert { + condition = length(spectrocloud_cluster_vsphere.vmware-cluster) == 1 + error_message = "No VMware cluster was created" + } +} \ No newline at end of file diff --git a/terraform/getting-started-deployment-tf/tests/vmware-replace.tftest.hcl b/terraform/getting-started-deployment-tf/tests/vmware-replace.tftest.hcl new file mode 100644 index 0000000..a115c5e --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/vmware-replace.tftest.hcl @@ -0,0 +1,38 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 15 + +variables { + deploy-vmware = true + db_password = "test_password" + auth_token = "test_token" + metallb_ip = "REPLACE ME" + pcg_name = "REPLACE ME" + datacenter_name = "REPLACE ME" + folder_name = "REPLACE ME" + search_domain = "REPLACE ME" + vsphere_cluster = "REPLACE ME" + datastore_name = "REPLACE ME" + network_name = "REPLACE ME" + resource_pool_name = "REPLACE ME" +} + +mock_provider "spectrocloud" {} + +run "verify_vmware" { + + command = plan + + expect_failures = [ + var.metallb_ip, + var.pcg_name, + var.datacenter_name, + var.folder_name, + var.search_domain, + var.vsphere_cluster, + var.datastore_name, + var.network_name, + var.resource_pool_name + ] + +} diff --git a/terraform/getting-started-deployment-tf/tests/vmware-ssh.tftest.hcl b/terraform/getting-started-deployment-tf/tests/vmware-ssh.tftest.hcl new file mode 100644 index 0000000..9d83ceb --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/vmware-ssh.tftest.hcl @@ -0,0 +1,44 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 16 + +variables { + deploy-vmware = true + db_password = "test_password" + auth_token = "test_token" + metallb_ip = "test_ip" + pcg_name = "test_pcg" + datacenter_name = "test_datacenter" + folder_name = "test_folder" + search_domain = "test_search_domain" + vsphere_cluster = "test_cluster" + datastore_name = "test_datastore" + network_name = "test_network" + resource_pool_name = "test_resource_pool" + ssh_key = "" + ssh_key_private = "" +} + +mock_provider "spectrocloud" { +} + +run "verify_vmware" { + + command = plan + + assert { + condition = length(tls_private_key.tutorial_ssh_key) == 1 + error_message = "No SSH key was created" + } + + assert { + condition = length(local_sensitive_file.private_key_file) == 1 + error_message = "The file to store the private key was not created" + } + + assert { + condition = length(local_file.public_key_file) == 1 + error_message = "The file to store the public key was not created" + } + +} diff --git a/terraform/getting-started-deployment-tf/tests/vmware.tftest.hcl b/terraform/getting-started-deployment-tf/tests/vmware.tftest.hcl new file mode 100644 index 0000000..06bbf20 --- /dev/null +++ b/terraform/getting-started-deployment-tf/tests/vmware.tftest.hcl @@ -0,0 +1,37 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 +# Test case 13 + +variables { + deploy-vmware = true + db_password = "test_password" + auth_token = "test_token" + metallb_ip = "test_ip" + pcg_name = "test_pcg" + datacenter_name = "test_datacenter" + folder_name = "test_folder" + search_domain = "test_search_domain" + vsphere_cluster = "test_cluster" + datastore_name = "test_datastore" + network_name = "test_network" + resource_pool_name = "test_resource_pool" +} + +mock_provider "spectrocloud" { +} + +run "verify_vmware" { + + command = plan + + assert { + condition = length(spectrocloud_cluster_profile.vmware-profile) == 1 + error_message = "No VMware cluster profile was created" + } + + assert { + condition = length(spectrocloud_cluster_vsphere.vmware-cluster) == 1 + error_message = "No VMware cluster was created" + } + +}