diff --git a/terraform/cp-management/basic/README.md b/terraform/cp-management/basic/README.md new file mode 100644 index 0000000..99006fe --- /dev/null +++ b/terraform/cp-management/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/cp-management/basic/cluster-profile.tf b/terraform/cp-management/basic/cluster-profile.tf new file mode 100644 index 0000000..85c6cfa --- /dev/null +++ b/terraform/cp-management/basic/cluster-profile.tf @@ -0,0 +1,75 @@ +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/cp-management/basic/data.tf b/terraform/cp-management/basic/data.tf new file mode 100644 index 0000000..e443eb0 --- /dev/null +++ b/terraform/cp-management/basic/data.tf @@ -0,0 +1,34 @@ +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/cp-management/basic/inputs.tf b/terraform/cp-management/basic/inputs.tf new file mode 100644 index 0000000..fb9498a --- /dev/null +++ b/terraform/cp-management/basic/inputs.tf @@ -0,0 +1,9 @@ +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/cp-management/basic/provider.tf b/terraform/cp-management/basic/provider.tf new file mode 100644 index 0000000..3363942 --- /dev/null +++ b/terraform/cp-management/basic/provider.tf @@ -0,0 +1,18 @@ +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/cp-management/cp-modules/README.md b/terraform/cp-management/cp-modules/README.md new file mode 100644 index 0000000..1a935bc --- /dev/null +++ b/terraform/cp-management/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)` |
{| 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/cp-management/cp-modules/cp.tf b/terraform/cp-management/cp-modules/cp.tf new file mode 100644 index 0000000..b2c5df6 --- /dev/null +++ b/terraform/cp-management/cp-modules/cp.tf @@ -0,0 +1,25 @@ +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/cp-management/cp-modules/data.tf b/terraform/cp-management/cp-modules/data.tf new file mode 100644 index 0000000..bf3da10 --- /dev/null +++ b/terraform/cp-management/cp-modules/data.tf @@ -0,0 +1,10 @@ +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/cp-management/cp-modules/inputs.tf b/terraform/cp-management/cp-modules/inputs.tf new file mode 100644 index 0000000..acca3e2 --- /dev/null +++ b/terraform/cp-management/cp-modules/inputs.tf @@ -0,0 +1,72 @@ + + +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/cp-management/cp-modules/outputs.tf b/terraform/cp-management/cp-modules/outputs.tf new file mode 100644 index 0000000..641fcc3 --- /dev/null +++ b/terraform/cp-management/cp-modules/outputs.tf @@ -0,0 +1,7 @@ +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/cp-management/cp-modules/provider.tf b/terraform/cp-management/cp-modules/provider.tf new file mode 100644 index 0000000..3363942 --- /dev/null +++ b/terraform/cp-management/cp-modules/provider.tf @@ -0,0 +1,18 @@ +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/cp-management/cp-profiles-with-module/README.md b/terraform/cp-management/cp-profiles-with-module/README.md new file mode 100644 index 0000000..d366776 --- /dev/null +++ b/terraform/cp-management/cp-profiles-with-module/README.md @@ -0,0 +1,20 @@ +## Advanced Pattern + + + +| 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. | + diff --git a/terraform/cp-management/cp-profiles-with-module/cp.tf b/terraform/cp-management/cp-profiles-with-module/cp.tf new file mode 100644 index 0000000..f1a87c2 --- /dev/null +++ b/terraform/cp-management/cp-profiles-with-module/cp.tf @@ -0,0 +1,33 @@ +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/cp-management/cp-profiles-with-module/providers.tf b/terraform/cp-management/cp-profiles-with-module/providers.tf new file mode 100644 index 0000000..1d1d05f --- /dev/null +++ b/terraform/cp-management/cp-profiles-with-module/providers.tf @@ -0,0 +1,22 @@ +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/cp-management/cp-versions/README.md b/terraform/cp-management/cp-versions/README.md new file mode 100644 index 0000000..9c13876 --- /dev/null +++ b/terraform/cp-management/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/cp-management/cp-versions/clusters.tf b/terraform/cp-management/cp-versions/clusters.tf new file mode 100644 index 0000000..777017a --- /dev/null +++ b/terraform/cp-management/cp-versions/clusters.tf @@ -0,0 +1,38 @@ +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/cp-management/cp-versions/cp.tf b/terraform/cp-management/cp-versions/cp.tf new file mode 100644 index 0000000..a9c3f1c --- /dev/null +++ b/terraform/cp-management/cp-versions/cp.tf @@ -0,0 +1,43 @@ +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/cp-management/cp-versions/data.tf b/terraform/cp-management/cp-versions/data.tf new file mode 100644 index 0000000..f61bf0a --- /dev/null +++ b/terraform/cp-management/cp-versions/data.tf @@ -0,0 +1,50 @@ +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/cp-management/cp-versions/inputs.tf b/terraform/cp-management/cp-versions/inputs.tf new file mode 100644 index 0000000..2cd3e54 --- /dev/null +++ b/terraform/cp-management/cp-versions/inputs.tf @@ -0,0 +1,75 @@ + +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/cp-management/cp-versions/outputs.tf b/terraform/cp-management/cp-versions/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/cp-management/cp-versions/provider.tf b/terraform/cp-management/cp-versions/provider.tf new file mode 100644 index 0000000..3363942 --- /dev/null +++ b/terraform/cp-management/cp-versions/provider.tf @@ -0,0 +1,18 @@ +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/cp-management/cp-versions/terraform.tfvars b/terraform/cp-management/cp-versions/terraform.tfvars new file mode 100644 index 0000000..788c82d --- /dev/null +++ b/terraform/cp-management/cp-versions/terraform.tfvars @@ -0,0 +1,3 @@ +aws_cloud_account_name = "spectro-cloud" +aws_key_pair_name = "my-ec2-keypair" +aws_region = "us-east-1" \ No newline at end of file
"cni-calico": "3.26.1",
"csi-aws-ebs": "1.22.0",
"kubernetes": "1.27.5",
"ubuntu-aws": "22.04"
}