diff --git a/.copywrite.hcl b/.copywrite.hcl new file mode 100644 index 0000000..72d95a1 --- /dev/null +++ b/.copywrite.hcl @@ -0,0 +1,15 @@ +schema_version = 1 + +project { + copyright_holder = "Spectro Cloud" + license = "Apache-2.0" + copyright_year = 2024 + + # (OPTIONAL) A list of globs that should not have copyright/license headers. + # Supports doublestar glob patterns for more flexibility in defining which + # files or folders should be ignored + header_ignore = [ + # "vendors/**", + # "**autogen**", + ] +} diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..611379d --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,9 @@ +## Describe the Change + +This PR ..... + +## Checklist + +- [ ] README updated? + +- [ ] Content added contain comments that explain the purpose of the script and usage? diff --git a/.github/workflows/gitleaks.yaml b/.github/workflows/gitleaks.yaml new file mode 100644 index 0000000..bb431f7 --- /dev/null +++ b/.github/workflows/gitleaks.yaml @@ -0,0 +1,36 @@ +name: GitLeaks +on: [pull_request] + +concurrency: + group: gitleaks-${{ github.ref }} + cancel-in-progress: true + +jobs: + gitleaks-scan: + runs-on: ubuntu-latest + container: + image: gcr.io/spectro-dev-public/bulwark/gitleaks:latest + env: + REPO: ${{ github.event.repository.name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITLEAKS_CONFIG: config.toml + steps: + + - name: run-bulwark-gitleaks-scan + shell: sh + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + run: /workspace/bulwark -name CodeSASTGitLeaks -target $REPO -tags "branch:$BRANCH,options:--log-opts origin..HEAD" + + - name: check-result + shell: sh + run: | + resultPath=./$REPO/gitleaks.json + cat $resultPath | grep -v \"Match\"\: | grep -v \"Secret\"\: + total_failed_tests=`cat $resultPath | grep \"Fingerprint\"\: | wc -l` + if [ "$total_failed_tests" -gt 0 ]; then + echo "GitLeaks validation check failed with above findings..." + exit 1 + else + echo "GitLeaks validation check passed" + fi \ No newline at end of file diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..9713a59 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @spectrocloud/education-engineers \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d1b00c --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +.PHONY: license + +license: + @echo "Applying license headers..." + copywrite headers \ No newline at end of file diff --git a/README.md b/README.md index c6472e8..4d055a3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ -# palette-samples -A repository that contains templates, scripts, and other other useful content +# Palette Samples + +![Spectro Cloud logo with docs inline](/static/images/spectrocloud-logo-light.svg) + +This repository contains a collection of patterns, code samples, and more to help you get started with Palette and VerteX. Check out the resources below to learn more. + +## Patterns + +- [Managing Cluster Profiles with Terraform](./terraform/cluster-profiles/README.md) + +## Contact Us + +If you have any questions, please reach out to us at [spectro-doc@spectrocloud.com](mailto:spectro-doc@spectrocloud.com) or join our [Slack community](https://spectrocloudcommunity.slack.com). diff --git a/static/images/spectrocloud-logo-light.svg b/static/images/spectrocloud-logo-light.svg new file mode 100644 index 0000000..43fd25e --- /dev/null +++ b/static/images/spectrocloud-logo-light.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/terraform/cluster-profiles/README.md b/terraform/cluster-profiles/README.md new file mode 100644 index 0000000..6b50869 --- /dev/null +++ b/terraform/cluster-profiles/README.md @@ -0,0 +1,12 @@ +# Cluster Profile Management Patterns + +This folder contains examples of how to manage cluster profiles using Terraform. There are multiple ways to manage cluster profiles using Terraform. The examples in this folder are meant to be used as a starting point for managing cluster profiles using Terraform. Use these examples as a reference and modify them to suit your needs. + + +Check out the READMEs in each folder to learn more about the different patterns. + +- [Basic Pattern](./basic/README.md) + +- [Intermediate Pattern](./cp-versions/README.md) + +- [Advanced Pattern](./cp-profiles-with-module/README.md) \ No newline at end of file diff --git a/terraform/cluster-profiles/basic/.terraform.lock.hcl b/terraform/cluster-profiles/basic/.terraform.lock.hcl new file mode 100644 index 0000000..65d80f1 --- /dev/null +++ b/terraform/cluster-profiles/basic/.terraform.lock.hcl @@ -0,0 +1,44 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.1" + constraints = ">= 2.4.0" + hashes = [ + "h1:gpp25uNkYJYzJVnkyRr7RIBVfwLs9GSq2HNnFpTRBg0=", + "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", + "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", + "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", + "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", + "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", + "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", + "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", + "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", + "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", + "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", + ] +} + +provider "registry.terraform.io/spectrocloud/spectrocloud" { + version = "0.17.3" + constraints = ">= 0.17.2" + hashes = [ + "h1:dS2GwajJLUxJt/XrKkiuOEw/FjdctiSNEhZclg3mnlk=", + "zh:07e406148f825cae5642d2a6729afc905993e391842a459c0e33c0e67b919829", + "zh:243c73742f726e532294cdd7cf3dd063a61e96d8e6b69863a59d0732b45002f1", + "zh:25b60931dc8fd878b9fa04c055c281dcaf73f399a78847954397acf5a7453521", + "zh:3adaca6b6fc8d6077103946b1702aa5a707b08d0d58af9d2e2c6432350fbf398", + "zh:3b6011a3c81e71ec5be5c2906aaac40ccf7587b53eeeb4b9f70f4c7dd9b1b5d3", + "zh:41713bba8215c4fd29e3fbbd4c37c40476daf68cc65e0d8eed01fb10f6143f2e", + "zh:53e2ecb21137ba11f6ef3c21036ed6b2355b9549bcf1cd4574b35a7d3712edac", + "zh:6aa8a29d949a86b4001f9cb3e024406b5d83e2e3f7805ee7b5b8d195034a0573", + "zh:6c96137672b644fb9064a8c600ef8a44ceae1b3dc5538a7141b0cd740b70bf11", + "zh:6f0a2602900a28cb2ff7c16d4bf6731cc2b80afe28c82e7d5212c7c711927b4f", + "zh:971716885971e15731741e834373891f153fca61b465a0f0dfe9c4849e45068a", + "zh:997845c901236b5aad31318049f3826a29fb5f3c1cfc5c0b513f9d2a9f6551d4", + "zh:c0ae9a8bf92a9bacd121fbdd40c0bae3c697228d299933ba8fe91f10c6d83abd", + "zh:c4498caa78308334339e964cd646f69ed99522b51adf15ecb8eb40ab5c8cf250", + ] +} diff --git a/terraform/cluster-profiles/basic/README.md b/terraform/cluster-profiles/basic/README.md new file mode 100644 index 0000000..99006fe --- /dev/null +++ b/terraform/cluster-profiles/basic/README.md @@ -0,0 +1,89 @@ +# Basic Pattern + +The basic pattern of managing and maintain cluster profiles. Each cluster profile version is defined through the `spectrocloud_cluster_profile` resource. + + +| Pros | +| ---- | +| Easy to understand | +| Easy to implement | +| Mimumum complexity | +| Profiles are clearly defined | +| Low chances of accidental changes | +| YAML customization supported through dedicated `pack {}` block | + +| Cons | +| ---- | +| Requires code duplications | +| Tedious to maintain | + + +## Usage + +1. Create a data resource for each pack. Replace the name of the pack with the name of the pack you are adding. For example, if you are adding the `csi-aws-ebs` pack, the data resource would look like the following: + +```hcl +data "spectrocloud_pack" "csi-aws-ebs" { + name = "csi-aws-ebs" + version = "1.22.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} +``` + +2. If adding a new pack version, add a new data resource for the pack. + +```hcl +data "spectrocloud_pack" "csi-aws-ebs-1-24" { + name = "csi-aws-ebs" + version = "1.24.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} +``` + + +3. In the cluster profile resource `spectrocloud_cluster_profile`, add a new `pack {}` block for each pack version. Assign a name and version to the cluster profile. + +```hcl +resource "spectrocloud_cluster_profile" "aws-profile-1-0-0" { + + name = "tf-aws-profile" + description = "A basic cluster profile for AWS" + tags = concat(var.tags, ["env:aws", "version:1.0.0"]) + cloud = "aws" + type = "cluster" + version = "1.0.0" + + pack { + name = data.spectrocloud_pack.ubuntu-aws.name + tag = data.spectrocloud_pack.ubuntu-aws.version + uid = data.spectrocloud_pack.ubuntu-aws.id + values = data.spectrocloud_pack.ubuntu-aws.values + } + + pack { + name = data.spectrocloud_pack.kubernetes.name + tag = data.spectrocloud_pack.kubernetes.version + uid = data.spectrocloud_pack.kubernetes.id + values = data.spectrocloud_pack.kubernetes.values + } + + pack { + name = data.spectrocloud_pack.cni-calico.name + tag = data.spectrocloud_pack.cni-calico.version + uid = data.spectrocloud_pack.cni-calico.id + values = data.spectrocloud_pack.cni-calico.values + } + + pack { + name = data.spectrocloud_pack.csi-aws-ebs.name + tag = data.spectrocloud_pack.csi-aws-ebs.version + uid = data.spectrocloud_pack.csi-aws-ebs.id + values = data.spectrocloud_pack.csi-aws-ebs.values + } +} +``` + +4. Repeat the above steps for each cluster profile version. + + +5. Reference the desired cluster profile in the `spectrocloud_cluster` resource. \ No newline at end of file diff --git a/terraform/cluster-profiles/basic/cluster-profile.tf b/terraform/cluster-profiles/basic/cluster-profile.tf new file mode 100644 index 0000000..262228e --- /dev/null +++ b/terraform/cluster-profiles/basic/cluster-profile.tf @@ -0,0 +1,78 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +resource "spectrocloud_cluster_profile" "aws-profile-1-0-0" { + + name = "tf-aws-profile" + description = "A basic cluster profile for AWS" + tags = concat(var.tags, ["env:aws", "version:1.0.0"]) + cloud = "aws" + type = "cluster" + version = "1.0.0" + + pack { + name = data.spectrocloud_pack.ubuntu-aws.name + tag = data.spectrocloud_pack.ubuntu-aws.version + uid = data.spectrocloud_pack.ubuntu-aws.id + values = data.spectrocloud_pack.ubuntu-aws.values + } + + pack { + name = data.spectrocloud_pack.kubernetes.name + tag = data.spectrocloud_pack.kubernetes.version + uid = data.spectrocloud_pack.kubernetes.id + values = data.spectrocloud_pack.kubernetes.values + } + + pack { + name = data.spectrocloud_pack.cni-calico.name + tag = data.spectrocloud_pack.cni-calico.version + uid = data.spectrocloud_pack.cni-calico.id + values = data.spectrocloud_pack.cni-calico.values + } + + pack { + name = data.spectrocloud_pack.csi-aws-ebs.name + tag = data.spectrocloud_pack.csi-aws-ebs.version + uid = data.spectrocloud_pack.csi-aws-ebs.id + values = data.spectrocloud_pack.csi-aws-ebs.values + } +} + +resource "spectrocloud_cluster_profile" "aws-profile-1-0-1" { + + name = "tf-aws-profile" + description = "A basic cluster profile for AWS" + tags = concat(var.tags, ["env:aws", "version:1.0.1"]) + cloud = "aws" + type = "cluster" + version = "1.0.1" + + pack { + name = data.spectrocloud_pack.ubuntu-aws.name + tag = data.spectrocloud_pack.ubuntu-aws.version + uid = data.spectrocloud_pack.ubuntu-aws.id + values = data.spectrocloud_pack.ubuntu-aws.values + } + + pack { + name = data.spectrocloud_pack.kubernetes.name + tag = data.spectrocloud_pack.kubernetes.version + uid = data.spectrocloud_pack.kubernetes.id + values = data.spectrocloud_pack.kubernetes.values + } + + pack { + name = data.spectrocloud_pack.cni-calico.name + tag = data.spectrocloud_pack.cni-calico.version + uid = data.spectrocloud_pack.cni-calico.id + values = data.spectrocloud_pack.cni-calico.values + } + + pack { + name = data.spectrocloud_pack.csi-aws-ebs-1-24.name + tag = data.spectrocloud_pack.csi-aws-ebs-1-24.version + uid = data.spectrocloud_pack.csi-aws-ebs-1-24.id + values = data.spectrocloud_pack.csi-aws-ebs-1-24.values + } +} \ No newline at end of file diff --git a/terraform/cluster-profiles/basic/data.tf b/terraform/cluster-profiles/basic/data.tf new file mode 100644 index 0000000..8e5ac9c --- /dev/null +++ b/terraform/cluster-profiles/basic/data.tf @@ -0,0 +1,37 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +data "spectrocloud_registry" "public_registry" { + name = "Public Repo" +} + + +data "spectrocloud_pack" "csi-aws-ebs" { + name = "csi-aws-ebs" + version = "1.22.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "csi-aws-ebs-1-24" { + name = "csi-aws-ebs" + version = "1.24.0" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "cni-calico" { + name = "cni-calico" + version = "3.26.1" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "kubernetes" { + name = "kubernetes" + version = "1.27.5" + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "ubuntu-aws" { + name = "ubuntu-aws" + version = "22.04" + registry_uid = data.spectrocloud_registry.public_registry.id +} \ No newline at end of file diff --git a/terraform/cluster-profiles/basic/inputs.tf b/terraform/cluster-profiles/basic/inputs.tf new file mode 100644 index 0000000..43aef50 --- /dev/null +++ b/terraform/cluster-profiles/basic/inputs.tf @@ -0,0 +1,12 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +variable "tags" { + type = list(string) + description = "The default tags to apply to Palette resources" + default = [ + "spectro-cloud-education", + "repository:spectrocloud:tutorials", + "terraform_managed:true", + ] +} diff --git a/terraform/cluster-profiles/basic/provider.tf b/terraform/cluster-profiles/basic/provider.tf new file mode 100644 index 0000000..36d51f6 --- /dev/null +++ b/terraform/cluster-profiles/basic/provider.tf @@ -0,0 +1,21 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + spectrocloud = { + version = ">= 0.17.2" + source = "spectrocloud/spectrocloud" + } + local = { + source = "hashicorp/local" + version = ">= 2.4.0" + } + } + + required_version = ">= 1.5" +} + +provider "spectrocloud" { + project_name = "Default" +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-modules/.terraform.lock.hcl b/terraform/cluster-profiles/cp-modules/.terraform.lock.hcl new file mode 100644 index 0000000..db39970 --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/.terraform.lock.hcl @@ -0,0 +1,67 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.33.0" + constraints = "5.33.0" + hashes = [ + "h1:kPm7PkwHh6tZ74pUj5C/QRPtauxdnzrEG2yhCJla/4o=", + "zh:10bb683f2a9306e881f51a971ad3b2bb654ac94b54945dd63769876a343b5b04", + "zh:3916406db958d5487ea0c2d2320012d1907c29e6d01bf693560fe05e38ee0601", + "zh:3cb54b76b2f9e30620f3281ab7fb20633b1e4584fc84cc4ecd5752546252e86f", + "zh:513bcfd6971482215c5d64725189f875cbcbd260c6d11f0da4d66321efd93a92", + "zh:545a34427ebe7a950056627e7c980c9ba16318bf086d300eb808ffc41c52b7a8", + "zh:5a44b90faf1c8e8269f389c04bfac25ad4766d26360e7f7ac371be12a442981c", + "zh:64e1ef83162f78538dccad8b035577738851395ba774d6919cb21eb465a21e3a", + "zh:7315c70cb6b7f975471ea6129474639a08c58c071afc95a36cfaa41a13ae7fb9", + "zh:9806faae58938d638b757f54414400be998dddb45edfd4a29c85e827111dc93d", + "zh:997fa2e2db242354d9f772fba7eb17bd6d18d28480291dd93f85a18ca0a67ac2", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9f9e076b7e9752971f39eead6eda69df1c5e890c82ba2ca95f56974af7adfe79", + "zh:b1d6af047f96de7f97d38b685654f1aed4356d5060b0e696d87d0270f5d49f75", + "zh:bfb0654b6f34398aeffdf907b744af06733d168db610a2c5747263380f817ac7", + "zh:e25203ee8cedccf60bf450950d533d3c172509bda8af97dbc3bc817d2a503c57", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.1" + constraints = ">= 2.4.0" + hashes = [ + "h1:gpp25uNkYJYzJVnkyRr7RIBVfwLs9GSq2HNnFpTRBg0=", + "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", + "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", + "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", + "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", + "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", + "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", + "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", + "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", + "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", + "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", + ] +} + +provider "registry.terraform.io/spectrocloud/spectrocloud" { + version = "0.17.3" + constraints = ">= 0.17.2" + hashes = [ + "h1:dS2GwajJLUxJt/XrKkiuOEw/FjdctiSNEhZclg3mnlk=", + "zh:07e406148f825cae5642d2a6729afc905993e391842a459c0e33c0e67b919829", + "zh:243c73742f726e532294cdd7cf3dd063a61e96d8e6b69863a59d0732b45002f1", + "zh:25b60931dc8fd878b9fa04c055c281dcaf73f399a78847954397acf5a7453521", + "zh:3adaca6b6fc8d6077103946b1702aa5a707b08d0d58af9d2e2c6432350fbf398", + "zh:3b6011a3c81e71ec5be5c2906aaac40ccf7587b53eeeb4b9f70f4c7dd9b1b5d3", + "zh:41713bba8215c4fd29e3fbbd4c37c40476daf68cc65e0d8eed01fb10f6143f2e", + "zh:53e2ecb21137ba11f6ef3c21036ed6b2355b9549bcf1cd4574b35a7d3712edac", + "zh:6aa8a29d949a86b4001f9cb3e024406b5d83e2e3f7805ee7b5b8d195034a0573", + "zh:6c96137672b644fb9064a8c600ef8a44ceae1b3dc5538a7141b0cd740b70bf11", + "zh:6f0a2602900a28cb2ff7c16d4bf6731cc2b80afe28c82e7d5212c7c711927b4f", + "zh:971716885971e15731741e834373891f153fca61b465a0f0dfe9c4849e45068a", + "zh:997845c901236b5aad31318049f3826a29fb5f3c1cfc5c0b513f9d2a9f6551d4", + "zh:c0ae9a8bf92a9bacd121fbdd40c0bae3c697228d299933ba8fe91f10c6d83abd", + "zh:c4498caa78308334339e964cd646f69ed99522b51adf15ecb8eb40ab5c8cf250", + ] +} diff --git a/terraform/cluster-profiles/cp-modules/README.md b/terraform/cluster-profiles/cp-modules/README.md new file mode 100644 index 0000000..1a935bc --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/README.md @@ -0,0 +1,47 @@ +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.5 | +| [local](#requirement\_local) | >= 2.4.0 | +| [spectrocloud](#requirement\_spectrocloud) | >= 0.17.2 | + +## Providers + +| Name | Version | +|------|---------| +| [spectrocloud](#provider\_spectrocloud) | 0.17.3 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [spectrocloud_cluster_profile.profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource | +| [spectrocloud_pack.generic](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | 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 | +|------|-------------|------|---------|:--------:| +| [cluster\_profile\_type](#input\_cluster\_profile\_type) | The type of cluster profile. Default value is 'cluster'. | `string` | `"cluster"` | no | +| [context](#input\_context) | The Palette scope to create the cluster profile in. | `string` | `"project"` | no | +| [description](#input\_description) | The description of the cluster profile. | `string` | `""` | no | +| [infrastructure\_provider](#input\_infrastructure\_provider) | The infrastructure provider the cluster profile is for. | `string` | n/a | yes | +| [name](#input\_name) | The name of the cluster profile. The version is appended. | `string` | n/a | yes | +| [pack\_order](#input\_pack\_order) | The Ordered list of pack names. The order must match with the expected layer of a cluster profile. | `list(string)` | n/a | yes | +| [packs](#input\_packs) | A list | `map(string)` |
{
"cni-calico": "3.26.1",
"csi-aws-ebs": "1.22.0",
"kubernetes": "1.27.5",
"ubuntu-aws": "22.04"
}
| no | +| [profile\_version](#input\_profile\_version) | The version for the profile | `string` | `"1.0.0"` | no | +| [registry\_name](#input\_registry\_name) | n/a | `string` | `"Public Repo"` | no | +| [tags](#input\_tags) | The default tags to apply to Palette resources | `list(string)` | `[]` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [export](#output\_export) | n/a | +| [id](#output\_id) | n/a | diff --git a/terraform/cluster-profiles/cp-modules/cp.tf b/terraform/cluster-profiles/cp-modules/cp.tf new file mode 100644 index 0000000..226c29e --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/cp.tf @@ -0,0 +1,28 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +resource "spectrocloud_cluster_profile" "profile" { + + name = "${var.name}-${replace(var.profile_version, ".", "-")}" + description = var.description + tags = concat(var.tags, ["version:${var.profile_version}"]) + cloud = var.infrastructure_provider + type = var.cluster_profile_type + version = var.profile_version + + dynamic "pack" { + for_each = { for idx, cp in local.combined_packs : idx => cp } + + content { + name = pack.value.name + tag = pack.value.pack_data.version + uid = pack.value.pack_data.id + values = pack.value.pack_data.values + } + } + + + depends_on = [ + data.spectrocloud_pack.generic + ] +} diff --git a/terraform/cluster-profiles/cp-modules/data.tf b/terraform/cluster-profiles/cp-modules/data.tf new file mode 100644 index 0000000..9c5e537 --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/data.tf @@ -0,0 +1,13 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +data "spectrocloud_registry" "public_registry" { + name = var.registry_name +} + +data "spectrocloud_pack" "generic" { + count = length(keys(var.packs)) + name = keys(var.packs)[count.index] + version = var.packs[keys(var.packs)[count.index]] + registry_uid = data.spectrocloud_registry.public_registry.id +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-modules/inputs.tf b/terraform/cluster-profiles/cp-modules/inputs.tf new file mode 100644 index 0000000..812fb99 --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/inputs.tf @@ -0,0 +1,75 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + + + +variable "name" { + type = string + description = "The name of the cluster profile. The version is appended." +} + +variable "description" { + type = string + description = "The description of the cluster profile." + default = "" +} + +variable "infrastructure_provider" { + type = string + description = "The infrastructure provider the cluster profile is for." +} + +variable "cluster_profile_type" { + type = string + description = "The type of cluster profile. Default value is 'cluster'." + default = "cluster" +} + +variable "profile_version" { + type = string + description = "The version for the profile" + default = "1.0.0" +} + +variable "context" { + type = string + description = "The Palette scope to create the cluster profile in." + default = "project" +} + + +variable "registry_name" { + type = string + default = "Public Repo" +} + +variable "pack_order" { + type = list(string) + description = "The Ordered list of pack names. The order must match with the expected layer of a cluster profile. The order goes from highest to lowest. For example. the first item has the highest priority order value assigned and so on." +} + +variable "packs" { + type = map(string) + description = "A list " + default = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } +} + +variable "tags" { + type = list(string) + description = "The default tags to apply to Palette resources" + default = [] +} + + +locals { + combined_packs = [for pack_name in var.pack_order : { + name = pack_name + version = var.packs[pack_name] + pack_data = [for pack in data.spectrocloud_pack.generic : pack if pack.name == pack_name][0] + }] +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-modules/outputs.tf b/terraform/cluster-profiles/cp-modules/outputs.tf new file mode 100644 index 0000000..5a26498 --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/outputs.tf @@ -0,0 +1,10 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +output "id" { + value = spectrocloud_cluster_profile.profile.id +} + +output "export" { + value = spectrocloud_cluster_profile.profile +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-modules/provider.tf b/terraform/cluster-profiles/cp-modules/provider.tf new file mode 100644 index 0000000..36d51f6 --- /dev/null +++ b/terraform/cluster-profiles/cp-modules/provider.tf @@ -0,0 +1,21 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + spectrocloud = { + version = ">= 0.17.2" + source = "spectrocloud/spectrocloud" + } + local = { + source = "hashicorp/local" + version = ">= 2.4.0" + } + } + + required_version = ">= 1.5" +} + +provider "spectrocloud" { + project_name = "Default" +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-profiles-with-module/.terraform.lock.hcl b/terraform/cluster-profiles/cp-profiles-with-module/.terraform.lock.hcl new file mode 100644 index 0000000..db39970 --- /dev/null +++ b/terraform/cluster-profiles/cp-profiles-with-module/.terraform.lock.hcl @@ -0,0 +1,67 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.33.0" + constraints = "5.33.0" + hashes = [ + "h1:kPm7PkwHh6tZ74pUj5C/QRPtauxdnzrEG2yhCJla/4o=", + "zh:10bb683f2a9306e881f51a971ad3b2bb654ac94b54945dd63769876a343b5b04", + "zh:3916406db958d5487ea0c2d2320012d1907c29e6d01bf693560fe05e38ee0601", + "zh:3cb54b76b2f9e30620f3281ab7fb20633b1e4584fc84cc4ecd5752546252e86f", + "zh:513bcfd6971482215c5d64725189f875cbcbd260c6d11f0da4d66321efd93a92", + "zh:545a34427ebe7a950056627e7c980c9ba16318bf086d300eb808ffc41c52b7a8", + "zh:5a44b90faf1c8e8269f389c04bfac25ad4766d26360e7f7ac371be12a442981c", + "zh:64e1ef83162f78538dccad8b035577738851395ba774d6919cb21eb465a21e3a", + "zh:7315c70cb6b7f975471ea6129474639a08c58c071afc95a36cfaa41a13ae7fb9", + "zh:9806faae58938d638b757f54414400be998dddb45edfd4a29c85e827111dc93d", + "zh:997fa2e2db242354d9f772fba7eb17bd6d18d28480291dd93f85a18ca0a67ac2", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9f9e076b7e9752971f39eead6eda69df1c5e890c82ba2ca95f56974af7adfe79", + "zh:b1d6af047f96de7f97d38b685654f1aed4356d5060b0e696d87d0270f5d49f75", + "zh:bfb0654b6f34398aeffdf907b744af06733d168db610a2c5747263380f817ac7", + "zh:e25203ee8cedccf60bf450950d533d3c172509bda8af97dbc3bc817d2a503c57", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.1" + constraints = ">= 2.4.0" + hashes = [ + "h1:gpp25uNkYJYzJVnkyRr7RIBVfwLs9GSq2HNnFpTRBg0=", + "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", + "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", + "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", + "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", + "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", + "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", + "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", + "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", + "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", + "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", + ] +} + +provider "registry.terraform.io/spectrocloud/spectrocloud" { + version = "0.17.3" + constraints = ">= 0.17.2" + hashes = [ + "h1:dS2GwajJLUxJt/XrKkiuOEw/FjdctiSNEhZclg3mnlk=", + "zh:07e406148f825cae5642d2a6729afc905993e391842a459c0e33c0e67b919829", + "zh:243c73742f726e532294cdd7cf3dd063a61e96d8e6b69863a59d0732b45002f1", + "zh:25b60931dc8fd878b9fa04c055c281dcaf73f399a78847954397acf5a7453521", + "zh:3adaca6b6fc8d6077103946b1702aa5a707b08d0d58af9d2e2c6432350fbf398", + "zh:3b6011a3c81e71ec5be5c2906aaac40ccf7587b53eeeb4b9f70f4c7dd9b1b5d3", + "zh:41713bba8215c4fd29e3fbbd4c37c40476daf68cc65e0d8eed01fb10f6143f2e", + "zh:53e2ecb21137ba11f6ef3c21036ed6b2355b9549bcf1cd4574b35a7d3712edac", + "zh:6aa8a29d949a86b4001f9cb3e024406b5d83e2e3f7805ee7b5b8d195034a0573", + "zh:6c96137672b644fb9064a8c600ef8a44ceae1b3dc5538a7141b0cd740b70bf11", + "zh:6f0a2602900a28cb2ff7c16d4bf6731cc2b80afe28c82e7d5212c7c711927b4f", + "zh:971716885971e15731741e834373891f153fca61b465a0f0dfe9c4849e45068a", + "zh:997845c901236b5aad31318049f3826a29fb5f3c1cfc5c0b513f9d2a9f6551d4", + "zh:c0ae9a8bf92a9bacd121fbdd40c0bae3c697228d299933ba8fe91f10c6d83abd", + "zh:c4498caa78308334339e964cd646f69ed99522b51adf15ecb8eb40ab5c8cf250", + ] +} diff --git a/terraform/cluster-profiles/cp-profiles-with-module/README.md b/terraform/cluster-profiles/cp-profiles-with-module/README.md new file mode 100644 index 0000000..ef0474e --- /dev/null +++ b/terraform/cluster-profiles/cp-profiles-with-module/README.md @@ -0,0 +1,83 @@ +## Advanced Pattern + +This pattern leverages Terraform modules to decouple the management of cluster profile versions from the cluster profile resource. Each cluster profile version is defined through a dedicated module. Terraform logic is applied to achieve unique cluster profile versions. + + +| Pros | +| ---- | +| Reduces code duplication | +| Adding or removing versions is a low complexity task| +| Managing versions is an isolated task and does not impact other resources except clusters consuming the specific version | +| Accidental changes are less likely to occur | +| Flexible and allows future changes to be made with minimal impact to existing code | + + +| Cons | +| ---- | +| Increased complexity that is offloaded to the module | +| May be fifficult to understand | +| YAML customization requires additional logic to support | +| Removing a version requires using the command `terraform destroy -target` where the specific version module is targeted. | +| Assumes all packs are defined in the same registry. Otherwise, additional logic is required. | + +## Usage + +1. To add a new version, create a new module in the `modules` directory. The module name should be the version number. For example, if you are adding version `1.0.0`, the module name would be `[your-module-name-1-0-0]`. Populate with all the required variables and resources. + +```hcl +module "primary-cp-1-0-0" { + source = "../cp-modules" + + name = "md-test" + infrastructure_provider = "aws" + cluster_profile_type = "cluster" + registry_name = "Public Repo" + profile_version = "1.0.0" + pack_order = ["ubuntu-aws", "kubernetes","cni-calico", "csi-aws-ebs" ] + packs = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } +} +``` + +2. The module requires you to explicity define the order of the packs. This is done through the `pack_order` variable. The order of the packs is important because it determines the order in which the packs are applied to the cluster. The first item in the list has the highest priority and the last item in the list has the lowest priority. This corresponds to the order in which the packs are applied to the cluster profile. + +3. The module requires you to explicity define the pack name and version. This is done through the `packs` variable. The pack name and version are used to create the pack resource. You can also define the pack registry name through the `registry_name` variable. If the pack registry name is not defined, the default registry is used. + + +4. To add a new version to the cluster profile, add a new module resource to the `spectrocloud_cluster_profile` resource. The module name should be the version number. For example, if you are adding version `1.0.1`, the module name would be `[your-module-name-1-0-1]`. + +```hcl +module "primary-cp-1-0-1" { + source = "../cp-modules" + + name = "md-test" + infrastructure_provider = "aws" + cluster_profile_type = "cluster" + registry_name = "Public Repo" + profile_version = "1.0.1" + pack_order = ["ubuntu-aws", "kubernetes","cni-calico", "csi-aws-ebs" ] + packs = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } +} +``` + +5. To use the new version, update the `spectrocloud_cluster` resource to use the new version. + +```hcl +resource "spectrocloud_cluster" "primary-cluster" { + name = "primary-cluster" + cluster_profile = module.primary-cp-1-0-1.id + .... +} +``` + +> [!NOTE] +> You can also access all the exported attributes from the module. To search for an exported attribute, reference the module `module.primary-cp-1-0-1` and add a `.` to the end of the module name. This will display all the exported attributes, assuming your editor supports the Terraform language server. \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-profiles-with-module/cp.tf b/terraform/cluster-profiles/cp-profiles-with-module/cp.tf new file mode 100644 index 0000000..819623c --- /dev/null +++ b/terraform/cluster-profiles/cp-profiles-with-module/cp.tf @@ -0,0 +1,36 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +module "primary-cp-1-0-0" { + source = "../cp-modules" + + name = "md-test" + infrastructure_provider = "aws" + cluster_profile_type = "cluster" + registry_name = "Public Repo" + profile_version = "1.0.0" + pack_order = ["ubuntu-aws", "kubernetes", "cni-calico", "csi-aws-ebs"] + packs = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } +} + +module "primary-cp-1-0-1" { + source = "../cp-modules" + + name = "md-test" + infrastructure_provider = "aws" + cluster_profile_type = "cluster" + registry_name = "Public Repo" + profile_version = "1.0.1" + pack_order = ["ubuntu-aws", "kubernetes", "cni-calico", "csi-aws-ebs"] + packs = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-profiles-with-module/providers.tf b/terraform/cluster-profiles/cp-profiles-with-module/providers.tf new file mode 100644 index 0000000..690c88a --- /dev/null +++ b/terraform/cluster-profiles/cp-profiles-with-module/providers.tf @@ -0,0 +1,25 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + spectrocloud = { + version = ">= 0.17.2" + source = "spectrocloud/spectrocloud" + } + local = { + source = "hashicorp/local" + version = ">= 2.4.0" + } + aws = { + source = "hashicorp/aws" + version = "5.33.0" + } + } + + required_version = ">= 1.5" +} + +provider "spectrocloud" { + project_name = "Default" +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-versions/.terraform.lock.hcl b/terraform/cluster-profiles/cp-versions/.terraform.lock.hcl new file mode 100644 index 0000000..db39970 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/.terraform.lock.hcl @@ -0,0 +1,67 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.33.0" + constraints = "5.33.0" + hashes = [ + "h1:kPm7PkwHh6tZ74pUj5C/QRPtauxdnzrEG2yhCJla/4o=", + "zh:10bb683f2a9306e881f51a971ad3b2bb654ac94b54945dd63769876a343b5b04", + "zh:3916406db958d5487ea0c2d2320012d1907c29e6d01bf693560fe05e38ee0601", + "zh:3cb54b76b2f9e30620f3281ab7fb20633b1e4584fc84cc4ecd5752546252e86f", + "zh:513bcfd6971482215c5d64725189f875cbcbd260c6d11f0da4d66321efd93a92", + "zh:545a34427ebe7a950056627e7c980c9ba16318bf086d300eb808ffc41c52b7a8", + "zh:5a44b90faf1c8e8269f389c04bfac25ad4766d26360e7f7ac371be12a442981c", + "zh:64e1ef83162f78538dccad8b035577738851395ba774d6919cb21eb465a21e3a", + "zh:7315c70cb6b7f975471ea6129474639a08c58c071afc95a36cfaa41a13ae7fb9", + "zh:9806faae58938d638b757f54414400be998dddb45edfd4a29c85e827111dc93d", + "zh:997fa2e2db242354d9f772fba7eb17bd6d18d28480291dd93f85a18ca0a67ac2", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9f9e076b7e9752971f39eead6eda69df1c5e890c82ba2ca95f56974af7adfe79", + "zh:b1d6af047f96de7f97d38b685654f1aed4356d5060b0e696d87d0270f5d49f75", + "zh:bfb0654b6f34398aeffdf907b744af06733d168db610a2c5747263380f817ac7", + "zh:e25203ee8cedccf60bf450950d533d3c172509bda8af97dbc3bc817d2a503c57", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.4.1" + constraints = ">= 2.4.0" + hashes = [ + "h1:gpp25uNkYJYzJVnkyRr7RIBVfwLs9GSq2HNnFpTRBg0=", + "zh:244b445bf34ddbd167731cc6c6b95bbed231dc4493f8cc34bd6850cfe1f78528", + "zh:3c330bdb626123228a0d1b1daa6c741b4d5d484ab1c7ae5d2f48d4c9885cc5e9", + "zh:5ff5f9b791ddd7557e815449173f2db38d338e674d2d91800ac6e6d808de1d1d", + "zh:70206147104f4bf26ae67d730c995772f85bf23e28c2c2e7612c74f4dae3c46f", + "zh:75029676993accd6bef933c196b2fad51a9ec8a69a847dbbe96ec8ebf7926cdc", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7d48d5999fe1fcdae9295a7c3448ac1541f5a24c474bd82df6d4fa3732483f2b", + "zh:b766b38b027f0f84028244d1c2f990431a37d4fc3ac645962924554016507e77", + "zh:bfc7ad301dada204cf51c59d8bd6a9a87de5fddb42190b4d6ba157d6e08a1f10", + "zh:c902b527702a8c5e2c25a6637d07bbb1690cb6c1e63917a5f6dc460efd18d43f", + "zh:d68ae0e1070cf429c46586bc87580c3ed113f76241da2b6e4f1a8348126b3c46", + "zh:f4903fd89f7c92a346ae9e666c2d0b6884c4474ae109e9b4bd15e7efaa4bfc29", + ] +} + +provider "registry.terraform.io/spectrocloud/spectrocloud" { + version = "0.17.3" + constraints = ">= 0.17.2" + hashes = [ + "h1:dS2GwajJLUxJt/XrKkiuOEw/FjdctiSNEhZclg3mnlk=", + "zh:07e406148f825cae5642d2a6729afc905993e391842a459c0e33c0e67b919829", + "zh:243c73742f726e532294cdd7cf3dd063a61e96d8e6b69863a59d0732b45002f1", + "zh:25b60931dc8fd878b9fa04c055c281dcaf73f399a78847954397acf5a7453521", + "zh:3adaca6b6fc8d6077103946b1702aa5a707b08d0d58af9d2e2c6432350fbf398", + "zh:3b6011a3c81e71ec5be5c2906aaac40ccf7587b53eeeb4b9f70f4c7dd9b1b5d3", + "zh:41713bba8215c4fd29e3fbbd4c37c40476daf68cc65e0d8eed01fb10f6143f2e", + "zh:53e2ecb21137ba11f6ef3c21036ed6b2355b9549bcf1cd4574b35a7d3712edac", + "zh:6aa8a29d949a86b4001f9cb3e024406b5d83e2e3f7805ee7b5b8d195034a0573", + "zh:6c96137672b644fb9064a8c600ef8a44ceae1b3dc5538a7141b0cd740b70bf11", + "zh:6f0a2602900a28cb2ff7c16d4bf6731cc2b80afe28c82e7d5212c7c711927b4f", + "zh:971716885971e15731741e834373891f153fca61b465a0f0dfe9c4849e45068a", + "zh:997845c901236b5aad31318049f3826a29fb5f3c1cfc5c0b513f9d2a9f6551d4", + "zh:c0ae9a8bf92a9bacd121fbdd40c0bae3c697228d299933ba8fe91f10c6d83abd", + "zh:c4498caa78308334339e964cd646f69ed99522b51adf15ecb8eb40ab5c8cf250", + ] +} diff --git a/terraform/cluster-profiles/cp-versions/README.md b/terraform/cluster-profiles/cp-versions/README.md new file mode 100644 index 0000000..9c13876 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/README.md @@ -0,0 +1,100 @@ + +## Intermediate Pattern + +The intermediate pattern of managing and maintain cluster profiles. Each cluster profile version is defined through a single `spectrocloud_cluster_profile` resource. Terraform logic is applied to achieve unique cluster profile versions. + + +| Pros | +| ---- | +| Reduces code duplication | +| Adding new versions is a low complexity task| + + + + +| Cons | +| ---- | +| Requires more complex Terraform logic | +| Difficult to understand | +| Removing versions is difficult as cluster profiles are recreated. This us due to state being maintained in a list. | +| YAML customization not supported. Additional logic is required to support YAML customization. | + + +## Usage + + +1. List the number of versions desired in the `locals.cp-versions` variable. + +```hcl +cp-versions = ["1.0.0", "1.0.1", "1.0.3"] +``` + +2. List each versions pack name and pack version in the `locals.cp-packs` variable. + +```hcl + packs = { + "1.0.0" = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } + "1.0.1" = { + "csi-aws-ebs" = "1.24.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } + "1.0.3" = { + "csi-aws-ebs" = "1.24.0" + "cni-cilium-oss" = "1.14.3" + "kubernetes" = "1.28.3" + "ubuntu-aws" = "22.04" + } + } + +``` + +3. Add a data resouce for each defined pack. Replace the name of the pack with the name of the pack you are adding. For example, if you are adding the `csi-aws-ebs` pack, the data resource would look like the following: + +```hcl +data "spectrocloud_pack" "csi-aws-ebs" { + count = length([for version, pack in local.packs : version if contains(keys(pack), "csi-aws-ebs")]) + name = "csi-aws-ebs" + version = [for version, pack in local.packs : pack["csi-aws-ebs"] if contains(keys(pack), "csi-aws-ebs")][count.index] + registry_uid = data.spectrocloud_registry.public_registry.id +} +``` + + +4. Add a local variable that contains a reference to the respective data resource. This is required for the dynamic behavior of the `spectrocloud_cluster_profile` resource. Add or remove packs as needed. + +```hcl + pack_data = { + "csi-aws-ebs" = { + data_source = data.spectrocloud_pack.csi-aws-ebs + } + "cni-calico" = { + data_source = data.spectrocloud_pack.cni-calico + } + "kubernetes" = { + data_source = data.spectrocloud_pack.kubernetes + } + "ubuntu-aws" = { + data_source = data.spectrocloud_pack.ubuntu-aws + } + "cni-cilium-oss" = { + data_source = data.spectrocloud_pack.cni-cilium-oss + } + } +``` + + +5. Specify the desired cluster profile version when deploying a cluster. You can use a target variable or manually specify the version. In the example below, the target variable `target_version` is used. + + +```hcl +cluster_profile { + id = spectrocloud_cluster_profile.aws-profile[index(local.cp-versions, local.target_version)].id + } +``` \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-versions/clusters.tf b/terraform/cluster-profiles/cp-versions/clusters.tf new file mode 100644 index 0000000..9153ab5 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/clusters.tf @@ -0,0 +1,41 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +resource "spectrocloud_cluster_aws" "aws-cluster" { + + name = "aws-cluster" + tags = concat(var.tags, ["env:aws", "service:hello-universe-frontend"]) + cloud_account_id = data.spectrocloud_cloudaccount_aws.account.id + + cloud_config { + region = var.aws_region + ssh_key_name = var.aws_key_pair_name + } + + cluster_profile { + id = spectrocloud_cluster_profile.aws-profile[index(local.cp-versions, local.target_version)].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" + } +} \ No newline at end of file diff --git a/terraform/cluster-profiles/cp-versions/cp.tf b/terraform/cluster-profiles/cp-versions/cp.tf new file mode 100644 index 0000000..7d74947 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/cp.tf @@ -0,0 +1,46 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +resource "spectrocloud_cluster_profile" "aws-profile" { + count = length(local.cp-versions) + + name = "tf-aws-profile-${local.cp-versions[count.index]}" + description = "A basic cluster profile for AWS" + tags = concat(var.tags, ["env:aws", "version:${local.cp-versions[count.index]}"]) + cloud = "aws" + type = "cluster" + version = local.cp-versions[count.index] + + + dynamic "pack" { + for_each = local.packs[local.cp-versions[count.index]] + + content { + name = pack.key + tag = pack.value + + uid = local.pack_data[pack.key].data_source[ + index( + [for v, p in local.packs : p[pack.key] if contains(keys(p), pack.key)], + pack.value + ) + ].id + + values = local.pack_data[pack.key].data_source[ + index( + [for v, p in local.packs : p[pack.key] if contains(keys(p), pack.key)], + pack.value + ) + ].values + } + } + + + depends_on = [ + data.spectrocloud_pack.cni-calico, + data.spectrocloud_pack.csi-aws-ebs, + data.spectrocloud_pack.kubernetes, + data.spectrocloud_pack.ubuntu-aws, + data.spectrocloud_pack.cni-cilium-oss + ] +} diff --git a/terraform/cluster-profiles/cp-versions/data.tf b/terraform/cluster-profiles/cp-versions/data.tf new file mode 100644 index 0000000..b083f52 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/data.tf @@ -0,0 +1,53 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +data "spectrocloud_registry" "public_registry" { + name = "Public Repo" +} + + + +data "spectrocloud_cloudaccount_aws" "account" { + name = var.aws_cloud_account_name +} + + + +data "spectrocloud_pack" "csi-aws-ebs" { + count = length([for version, pack in local.packs : version if contains(keys(pack), "csi-aws-ebs")]) + name = "csi-aws-ebs" + version = [for version, pack in local.packs : pack["csi-aws-ebs"] if contains(keys(pack), "csi-aws-ebs")][count.index] + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "cni-calico" { + count = length([for version, pack in local.packs : version if contains(keys(pack), "cni-calico")]) + name = "cni-calico" + version = [for version, pack in local.packs : pack["cni-calico"] if contains(keys(pack), "cni-calico")][count.index] + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "kubernetes" { + count = length([for version, pack in local.packs : version if contains(keys(pack), "kubernetes")]) + name = "kubernetes" + version = [for version, pack in local.packs : pack["kubernetes"] if contains(keys(pack), "kubernetes")][count.index] + registry_uid = data.spectrocloud_registry.public_registry.id +} + +data "spectrocloud_pack" "ubuntu-aws" { + count = length([for version, pack in local.packs : version if contains(keys(pack), "ubuntu-aws")]) + name = "ubuntu-aws" + version = [for version, pack in local.packs : pack["ubuntu-aws"] if contains(keys(pack), "ubuntu-aws")][count.index] + registry_uid = data.spectrocloud_registry.public_registry.id +} + + +data "spectrocloud_pack" "cni-cilium-oss" { + count = length([for version, pack in local.packs : version if contains(keys(pack), "cni-cilium-oss")]) + name = "cni-cilium-oss" + version = [for version, pack in local.packs : pack["cni-cilium-oss"] if contains(keys(pack), "cni-cilium-oss")][count.index] + registry_uid = data.spectrocloud_registry.public_registry.id +} + + + diff --git a/terraform/cluster-profiles/cp-versions/inputs.tf b/terraform/cluster-profiles/cp-versions/inputs.tf new file mode 100644 index 0000000..a439139 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/inputs.tf @@ -0,0 +1,78 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + + +variable "aws_cloud_account_name" { + type = string + description = "The name of the AWS account registered in Palette." +} + +variable "aws_region" { + type = string + description = "AWS region" + default = "us-east-1" +} + +variable "tags" { + type = list(string) + description = "The default tags to apply to Palette resources" + default = [ + "spectro-cloud-education", + "terraform_managed:true" + ] +} + + +variable "aws_key_pair_name" { + type = string + description = "The name of the AWS key pair to use for SSH access to the cluster. Refer to [EC2 Key Pairs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) to learn more." + default = "" +} + + + + +locals { + target_version = "1.0.0" + cp-versions = ["1.0.0", "1.0.1", "1.0.3"] + + packs = { + "1.0.0" = { + "csi-aws-ebs" = "1.22.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } + "1.0.1" = { + "csi-aws-ebs" = "1.24.0" + "cni-calico" = "3.26.1" + "kubernetes" = "1.27.5" + "ubuntu-aws" = "22.04" + } + "1.0.3" = { + "csi-aws-ebs" = "1.24.0" + "cni-cilium-oss" = "1.14.3" + "kubernetes" = "1.28.3" + "ubuntu-aws" = "22.04" + } + } + + + pack_data = { + "csi-aws-ebs" = { + data_source = data.spectrocloud_pack.csi-aws-ebs + } + "cni-calico" = { + data_source = data.spectrocloud_pack.cni-calico + } + "kubernetes" = { + data_source = data.spectrocloud_pack.kubernetes + } + "ubuntu-aws" = { + data_source = data.spectrocloud_pack.ubuntu-aws + } + "cni-cilium-oss" = { + data_source = data.spectrocloud_pack.cni-cilium-oss + } + } +} diff --git a/terraform/cluster-profiles/cp-versions/outputs.tf b/terraform/cluster-profiles/cp-versions/outputs.tf new file mode 100644 index 0000000..fb97b30 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/outputs.tf @@ -0,0 +1,3 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + diff --git a/terraform/cluster-profiles/cp-versions/provider.tf b/terraform/cluster-profiles/cp-versions/provider.tf new file mode 100644 index 0000000..36d51f6 --- /dev/null +++ b/terraform/cluster-profiles/cp-versions/provider.tf @@ -0,0 +1,21 @@ +# Copyright (c) Spectro Cloud +# SPDX-License-Identifier: Apache-2.0 + +terraform { + required_providers { + spectrocloud = { + version = ">= 0.17.2" + source = "spectrocloud/spectrocloud" + } + local = { + source = "hashicorp/local" + version = ">= 2.4.0" + } + } + + required_version = ">= 1.5" +} + +provider "spectrocloud" { + project_name = "Default" +} \ No newline at end of file