-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec2dc31
commit cd4698d
Showing
22 changed files
with
806 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 | | ||
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.4.0 | | ||
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement\_spectrocloud) | >= 0.17.2 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_spectrocloud"></a> [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 | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_cluster_profile_type"></a> [cluster\_profile\_type](#input\_cluster\_profile\_type) | The type of cluster profile. Default value is 'cluster'. | `string` | `"cluster"` | no | | ||
| <a name="input_context"></a> [context](#input\_context) | The Palette scope to create the cluster profile in. | `string` | `"project"` | no | | ||
| <a name="input_description"></a> [description](#input\_description) | The description of the cluster profile. | `string` | `""` | no | | ||
| <a name="input_infrastructure_provider"></a> [infrastructure\_provider](#input\_infrastructure\_provider) | The infrastructure provider the cluster profile is for. | `string` | n/a | yes | | ||
| <a name="input_name"></a> [name](#input\_name) | The name of the cluster profile. The version is appended. | `string` | n/a | yes | | ||
| <a name="input_pack_order"></a> [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 | | ||
| <a name="input_packs"></a> [packs](#input\_packs) | A list | `map(string)` | <pre>{<br> "cni-calico": "3.26.1",<br> "csi-aws-ebs": "1.22.0",<br> "kubernetes": "1.27.5",<br> "ubuntu-aws": "22.04"<br>}</pre> | no | | ||
| <a name="input_profile_version"></a> [profile\_version](#input\_profile\_version) | The version for the profile | `string` | `"1.0.0"` | no | | ||
| <a name="input_registry_name"></a> [registry\_name](#input\_registry\_name) | n/a | `string` | `"Public Repo"` | no | | ||
| <a name="input_tags"></a> [tags](#input\_tags) | The default tags to apply to Palette resources | `list(string)` | `[]` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_export"></a> [export](#output\_export) | n/a | | ||
| <a name="output_id"></a> [id](#output\_id) | n/a | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
}] | ||
} |
Oops, something went wrong.