diff --git a/terraform/pack-tf/README.md b/terraform/pack-tf/README.md index 59cc73f..b2a1faa 100644 --- a/terraform/pack-tf/README.md +++ b/terraform/pack-tf/README.md @@ -5,28 +5,26 @@ Use the code in this directory with the tutorial. ## Prerequisites You will need the following things before getting started: -1. Spectro Cloud API key generated from the Palette. +1. A Palette API key. 2. A cloud account added to your Palette project settings. -3. An SSH key created in the region where you will deploy the cluster. +3. An AWS Key pair or SSH key created in the region where you will deploy the cluster. -Note that the Terraform code, when executed, will deploy the resources to the **AWS** cloud service provider. -To deploy your resource to Azure or Google Cloud, use the specific layer details outlined in the **Cloud Service Provider Configurations** section below. - - -## Cloud Service Provider Configurations -The code uses the data resources, the core infrastructure layers, defined in the **data.tf** to deploy the `spectrocloud_cluster_profile.profile` resource to the AWS. Here are the pack details for each infrastructure layer. +> [!NOTE] +> This Terraform code will deploy the resources specified in the template to **AWS**. ## Requirements | Name | Version | |------|---------| -| [spectrocloud](#requirement\_spectrocloud) | >= 0.13.1 | +| [aws](#requirement\_aws) | ~> 5.0 | +| [spectrocloud](#requirement\_spectrocloud) | >= 0.16.1 | ## Providers | Name | Version | |------|---------| +| [aws](#provider\_aws) | 5.25.0 | | [spectrocloud](#provider\_spectrocloud) | 0.16.1 | ## Modules @@ -39,6 +37,7 @@ No modules. |------|------| | [spectrocloud_cluster_aws.cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_aws) | resource | | [spectrocloud_cluster_profile.profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source | | [spectrocloud_cloudaccount_aws.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_aws) | data source | | [spectrocloud_pack.cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | | [spectrocloud_pack.csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source | @@ -54,18 +53,19 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [aws\_az\_name](#input\_aws\_az\_name) | Choose the AWS availability zone. | `string` | n/a | yes | -| [aws\_region\_name](#input\_aws\_region\_name) | Choose the AWS region. | `string` | n/a | yes | -| [cluster\_cloud\_account\_aws\_name](#input\_cluster\_cloud\_account\_aws\_name) | Choose the AWS account integrated with Spektro Palette. | `string` | n/a | yes | -| [cluster\_name](#input\_cluster\_name) | Give the cluster a name. | `string` | `"pack-tutorial-cluster"` | no | -| [cluster\_profile\_description](#input\_cluster\_profile\_description) | Provide a description. | `string` | `"My cluster profile as part of the packs tutorial."` | no | -| [cluster\_profile\_name](#input\_cluster\_profile\_name) | Give the cluster-profile a name. | `string` | `"pack-tutorial-profile"` | no | +| [aws\_az\_names](#input\_aws\_az\_names) | Provide a list of AWS Availability Zones. For example: ['us-east-1a', 'us-east-1b', 'us-east-1c'] | `list(string)` | `[]` | no | +| [aws\_region\_name](#input\_aws\_region\_name) | Specify the AWS region where you want to deploy the cluster. | `string` | n/a | yes | +| [cluster\_cloud\_account\_aws\_name](#input\_cluster\_cloud\_account\_aws\_name) | Specify the AWS account integrated with Palette. Use the same name as the one used in the Palette project settings. | `string` | n/a | yes | +| [cluster\_name](#input\_cluster\_name) | The name of the cluster. | `string` | `"pack-tutorial-cluster"` | no | +| [cluster\_profile\_description](#input\_cluster\_profile\_description) | Provide a description of the cluster profile. | `string` | `"My cluster profile as part of the packs tutorial."` | no | +| [cluster\_profile\_name](#input\_cluster\_profile\_name) | The name of the cluster profile. | `string` | `"pack-tutorial-profile"` | no | | [custom\_addon\_pack](#input\_custom\_addon\_pack) | Custom add-on pack name. | `string` | `"hellouniverse"` | no | | [custom\_addon\_pack\_version](#input\_custom\_addon\_pack\_version) | Custom add-on pack version. | `string` | `"1.0.0"` | no | -| [private\_pack\_registry](#input\_private\_pack\_registry) | Private pack registry server name. | `string` | n/a | yes | -| [ssh\_key\_name](#input\_ssh\_key\_name) | Choose the AWS region. | `string` | n/a | yes | +| [instance\_type](#input\_instance\_type) | Specify the AWS instance type. | `string` | `"m4.xlarge"` | no | +| [private\_pack\_registry](#input\_private\_pack\_registry) | The name of the private pack registry server. | `string` | n/a | yes | +| [ssh\_key\_name](#input\_ssh\_key\_name) | Specify the AWS Keypair available in the AWS region where you want to deploy the cluster. | `string` | n/a | yes | | [tags](#input\_tags) | The default tags to apply to Palette resources | `list(string)` |
[| no | -| [use\_oci\_registry](#input\_use\_oci\_registry) | Set the use of OCI registry to true or false | `bool` | `true` | no | +| [use\_oci\_registry](#input\_use\_oci\_registry) | Set the use of OCI registry to true or false. If you are not using an OCI registry, set this value to false. | `bool` | `true` | no | ## Outputs diff --git a/terraform/pack-tf/cluster.tf b/terraform/pack-tf/cluster.tf index 221e0a4..776cc71 100644 --- a/terraform/pack-tf/cluster.tf +++ b/terraform/pack-tf/cluster.tf @@ -32,9 +32,9 @@ resource "spectrocloud_cluster_aws" "cluster" { control_plane_as_worker = true name = "master-pool" count = 1 - instance_type = "m4.xlarge" + instance_type = var.instance_type disk_size_gb = 60 - azs = [var.aws_az_name] + azs = local.azs } ############################## @@ -48,8 +48,8 @@ resource "spectrocloud_cluster_aws" "cluster" { } name = "worker-basic" count = 1 - instance_type = "m4.xlarge" - azs = [var.aws_az_name] + instance_type = var.instance_type + azs = local.azs } } \ No newline at end of file diff --git a/terraform/pack-tf/data.tf b/terraform/pack-tf/data.tf index 4ea7128..79071ea 100644 --- a/terraform/pack-tf/data.tf +++ b/terraform/pack-tf/data.tf @@ -2,7 +2,7 @@ # Data resources for the profile #################################### data "spectrocloud_registry" "public_registry" { - name = "Public Repo" + name = "Public Repo" } #################################### @@ -12,26 +12,26 @@ data "spectrocloud_registry" "public_registry" { # Refer to the "Cloud Service Provider Configurations" section in the README for more details. #################################### data "spectrocloud_pack" "ubuntu" { - name = "ubuntu-aws" - version = "22.04" + name = "ubuntu-aws" + version = "22.04" registry_uid = data.spectrocloud_registry.public_registry.id } data "spectrocloud_pack" "k8s" { - name = "kubernetes" - version = "1.28.2" + name = "kubernetes" + version = "1.28.2" registry_uid = data.spectrocloud_registry.public_registry.id } data "spectrocloud_pack" "cni" { - name = "cni-calico" - version = "3.26.1" + name = "cni-calico" + version = "3.26.1" registry_uid = data.spectrocloud_registry.public_registry.id } data "spectrocloud_pack" "csi" { - name = "csi-aws-ebs" - version = "1.22.0" + name = "csi-aws-ebs" + version = "1.22.0" registry_uid = data.spectrocloud_registry.public_registry.id } @@ -39,17 +39,17 @@ data "spectrocloud_pack" "csi" { # Add-On Layers #################################### data "spectrocloud_pack" "spectro-proxy" { - name = "spectro-proxy" - version = "1.4.1" - type = "spectro" + name = "spectro-proxy" + version = "1.4.1" + type = "spectro" registry_uid = data.spectrocloud_registry.public_registry.id } # Select the correct registry (OCI or non-OCI) data "spectrocloud_pack" "hellouniverse" { - name = var.custom_addon_pack - version = var.custom_addon_pack_version + name = var.custom_addon_pack + version = var.custom_addon_pack_version registry_uid = var.use_oci_registry ? data.spectrocloud_registry_oci.hellouniverseregistry[0].id : data.spectrocloud_registry.hellouniverseregistry[0].id } @@ -67,5 +67,11 @@ data "spectrocloud_registry_oci" "hellouniverseregistry" { # Data resources for the cluster #################################### data "spectrocloud_cloudaccount_aws" "account" { - name = var.cluster_cloud_account_aws_name -} \ No newline at end of file + name = var.cluster_cloud_account_aws_name +} + + +#################################### +# AWS +#################################### +data "aws_availability_zones" "available" {} \ No newline at end of file diff --git a/terraform/pack-tf/inputs.tf b/terraform/pack-tf/inputs.tf index 96b20c2..b3d415c 100644 --- a/terraform/pack-tf/inputs.tf +++ b/terraform/pack-tf/inputs.tf @@ -1,52 +1,60 @@ variable "cluster_profile_name" { type = string - description = "Give the cluster-profile a name." + description = "The name of the cluster profile." default = "pack-tutorial-profile" } variable "cluster_profile_description" { type = string - description = "Provide a description." + description = "Provide a description of the cluster profile." default = "My cluster profile as part of the packs tutorial." } variable "cluster_name" { type = string - description = "Give the cluster a name." + description = "The name of the cluster." default = "pack-tutorial-cluster" } + +variable "instance_type" { + type = string + description = "Specify the AWS instance type." + default = "m4.xlarge" +} + # ToDo: Provide a value for the variable below. The value will be the actual cloud account name added to your Palette project settings. variable "cluster_cloud_account_aws_name" { type = string - description = "Choose the AWS account integrated with Spektro Palette." + description = "Specify the AWS account integrated with Palette. Use the same name as the one used in the Palette project settings." } # ToDo: Provide a value for the variable below. The value will be one of the [AWS regions](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html) # The tutorial example uses "us-east-1" region. variable "aws_region_name" { type = string - description = "Choose the AWS region." + description = "Specify the AWS region where you want to deploy the cluster." } # ToDo: Provide a value for the variable below. The value will be one of the [AWS Availability Zones](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html) # The tutorial example uses "us-east-1a" availability zone. -variable "aws_az_name" { - type = string - description = "Choose the AWS availability zone." +variable "aws_az_names" { + type = list(string) + description = "Provide a list of AWS Availability Zones. For example: ['us-east-1a', 'us-east-1b', 'us-east-1c']" + default = [] } # ToDo: Provide a value for the variable below. The value will be the SSH key created in the AWS region where you will deploy the cluster. variable "ssh_key_name" { type = string - description = "Choose the AWS region." + description = "Specify the AWS Keypair available in the AWS region where you want to deploy the cluster." } # ToDo: Provide the name of your private registry server. # The tutorial example uses "private-pack-registry". variable "private_pack_registry" { type = string - description = "Private pack registry server name." + description = "The name of the private pack registry server." } variable "custom_addon_pack" { @@ -65,8 +73,8 @@ variable "custom_addon_pack_version" { # The default value is set as true. variable "use_oci_registry" { type = bool - description = "Set the use of OCI registry to true or false" - default = true + description = "Set the use of OCI registry to true or false. If you are not using an OCI registry, set this value to false." + default = true } variable "tags" { @@ -75,4 +83,9 @@ variable "tags" { # Value and key must be 63 characters or less, must start and end with an alphanumeric character, and can contain only alphanumeric characters, dots, dashes or underscores. # Slashes `\` are not allowed. default = ["spectro-cloud-education", "app:hello-universe", "terraform_managed:true"] +} + +locals { + # Check if the user has provided a list of AWS Availability Zones. If not, use the first AZ from the list of available AZs in the region. + azs = length(var.aws_az_names) != 0 ? var.aws_az_names : slice(data.aws_availability_zones.available.names, 0, 1) } \ No newline at end of file diff --git a/terraform/pack-tf/profile.tf b/terraform/pack-tf/profile.tf index e6227b8..3b9bb3b 100644 --- a/terraform/pack-tf/profile.tf +++ b/terraform/pack-tf/profile.tf @@ -46,7 +46,7 @@ resource "spectrocloud_cluster_profile" "profile" { name = "spectro-proxy" # Static value. Refer to the HubbleAPI collection before changing this value. tag = "1.4.x" uid = data.spectrocloud_pack.spectro-proxy.id - values = local.proxy_val + values = data.spectrocloud_pack.spectro-proxy.values } # Custom add-on pack @@ -56,15 +56,4 @@ resource "spectrocloud_cluster_profile" "profile" { uid = data.spectrocloud_pack.hellouniverse.id values = data.spectrocloud_pack.hellouniverse.values } -} - -locals { - proxy_val = <<-EOT - manifests: - spectro-proxy: - namespace: "cluster-{{ .spectro.system.cluster.uid }}" - server: "{{ .spectro.system.reverseproxy.server }}" - clusterUid: "{{ .spectro.system.cluster.uid }}" - subdomain: "cluster-{{ .spectro.system.cluster.uid }}" - EOT } \ No newline at end of file diff --git a/terraform/pack-tf/provider.tf b/terraform/pack-tf/provider.tf index cfdecfd..709ca09 100644 --- a/terraform/pack-tf/provider.tf +++ b/terraform/pack-tf/provider.tf @@ -1,9 +1,13 @@ terraform { required_providers { spectrocloud = { - version = ">= 0.13.1" + version = ">= 0.16.1" source = "spectrocloud/spectrocloud" } + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } } } diff --git a/terraform/pack-tf/terraform.tfvars b/terraform/pack-tf/terraform.tfvars index 3dc08b8..fdac1df 100644 --- a/terraform/pack-tf/terraform.tfvars +++ b/terraform/pack-tf/terraform.tfvars @@ -1,6 +1,6 @@ cluster_cloud_account_aws_name = "REPLACE ME" # Name of the cloud account added to your Palette project settings aws_region_name = "REPLACE ME" # Use "us-east-1" or any other AWS region -aws_az_name = "REPLACE ME" # Use "us-east-1a" or any other AWS availability zone +aws_az_names = ["REPLACE ME"] # Specify the AWS availability zone name. For example: ['us-east-1a', 'us-east-1b', 'us-east-1c']. ssh_key_name = "REPLACE ME" # Name of the SSH key available in the region where you will deploy the cluster private_pack_registry = "REPLACE ME" # Your registry server name. This tutorial uses "private-pack-registry". use_oci_registry = true # Set the use of OCI registry to true or false. The default value is set as true. \ No newline at end of file
"spectro-cloud-education",
"app:hello-universe",
"terraform_managed:true"
]