Skip to content

Commit

Permalink
chore: updated the template and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Nov 13, 2023
1 parent 1bb0c63 commit 418e87e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 64 deletions.
36 changes: 18 additions & 18 deletions terraform/pack-tf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|------|---------|
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement\_spectrocloud) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.0 |
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement\_spectrocloud) | >= 0.16.1 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
| <a name="provider_spectrocloud"></a> [spectrocloud](#provider\_spectrocloud) | 0.16.1 |

## Modules
Expand All @@ -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 |
Expand All @@ -54,18 +53,19 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_aws_az_name"></a> [aws\_az\_name](#input\_aws\_az\_name) | Choose the AWS availability zone. | `string` | n/a | yes |
| <a name="input_aws_region_name"></a> [aws\_region\_name](#input\_aws\_region\_name) | Choose the AWS region. | `string` | n/a | yes |
| <a name="input_cluster_cloud_account_aws_name"></a> [cluster\_cloud\_account\_aws\_name](#input\_cluster\_cloud\_account\_aws\_name) | Choose the AWS account integrated with Spektro Palette. | `string` | n/a | yes |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Give the cluster a name. | `string` | `"pack-tutorial-cluster"` | no |
| <a name="input_cluster_profile_description"></a> [cluster\_profile\_description](#input\_cluster\_profile\_description) | Provide a description. | `string` | `"My cluster profile as part of the packs tutorial."` | no |
| <a name="input_cluster_profile_name"></a> [cluster\_profile\_name](#input\_cluster\_profile\_name) | Give the cluster-profile a name. | `string` | `"pack-tutorial-profile"` | no |
| <a name="input_aws_az_names"></a> [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 |
| <a name="input_aws_region_name"></a> [aws\_region\_name](#input\_aws\_region\_name) | Specify the AWS region where you want to deploy the cluster. | `string` | n/a | yes |
| <a name="input_cluster_cloud_account_aws_name"></a> [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 |
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name of the cluster. | `string` | `"pack-tutorial-cluster"` | no |
| <a name="input_cluster_profile_description"></a> [cluster\_profile\_description](#input\_cluster\_profile\_description) | Provide a description of the cluster profile. | `string` | `"My cluster profile as part of the packs tutorial."` | no |
| <a name="input_cluster_profile_name"></a> [cluster\_profile\_name](#input\_cluster\_profile\_name) | The name of the cluster profile. | `string` | `"pack-tutorial-profile"` | no |
| <a name="input_custom_addon_pack"></a> [custom\_addon\_pack](#input\_custom\_addon\_pack) | Custom add-on pack name. | `string` | `"hellouniverse"` | no |
| <a name="input_custom_addon_pack_version"></a> [custom\_addon\_pack\_version](#input\_custom\_addon\_pack\_version) | Custom add-on pack version. | `string` | `"1.0.0"` | no |
| <a name="input_private_pack_registry"></a> [private\_pack\_registry](#input\_private\_pack\_registry) | Private pack registry server name. | `string` | n/a | yes |
| <a name="input_ssh_key_name"></a> [ssh\_key\_name](#input\_ssh\_key\_name) | Choose the AWS region. | `string` | n/a | yes |
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Specify the AWS instance type. | `string` | `"m4.xlarge"` | no |
| <a name="input_private_pack_registry"></a> [private\_pack\_registry](#input\_private\_pack\_registry) | The name of the private pack registry server. | `string` | n/a | yes |
| <a name="input_ssh_key_name"></a> [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 |
| <a name="input_tags"></a> [tags](#input\_tags) | The default tags to apply to Palette resources | `list(string)` | <pre>[<br> "spectro-cloud-education",<br> "app:hello-universe",<br> "terraform_managed:true"<br>]</pre> | no |
| <a name="input_use_oci_registry"></a> [use\_oci\_registry](#input\_use\_oci\_registry) | Set the use of OCI registry to true or false | `bool` | `true` | no |
| <a name="input_use_oci_registry"></a> [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

Expand Down
8 changes: 4 additions & 4 deletions terraform/pack-tf/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

##############################
Expand All @@ -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
}

}
38 changes: 22 additions & 16 deletions terraform/pack-tf/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Data resources for the profile
####################################
data "spectrocloud_registry" "public_registry" {
name = "Public Repo"
name = "Public Repo"
}

####################################
Expand All @@ -12,44 +12,44 @@ 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
}

####################################
# 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
}

Expand All @@ -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
}
name = var.cluster_cloud_account_aws_name
}


####################################
# AWS
####################################
data "aws_availability_zones" "available" {}
37 changes: 25 additions & 12 deletions terraform/pack-tf/inputs.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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" {
Expand All @@ -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)
}
13 changes: 1 addition & 12 deletions terraform/pack-tf/profile.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
6 changes: 5 additions & 1 deletion terraform/pack-tf/provider.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/pack-tf/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 418e87e

Please sign in to comment.