Skip to content

Commit

Permalink
docs: cleanup of page examples
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Sep 3, 2024
1 parent e7aaa6f commit b654e15
Show file tree
Hide file tree
Showing 2 changed files with 355 additions and 0 deletions.
172 changes: 172 additions & 0 deletions docs/resources/cluster_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,112 @@ description: |-

## Example Usage



### Example of a Cluster Profile with Data Resources and Custom YAML

In the following example, the cluster profile references data resources for the pack information. The pack information is used to define the cluster profile. The cluster profile also references a YAML file that contains the manifest information.

```terraform
data "spectrocloud_registry" "public_registry" {
name = "Public Repo"
}
data "spectrocloud_cloudaccount_aws" "account" {
count = var.deploy-aws ? 1 : 0
name = var.aws-cloud-account-name
}
data "spectrocloud_pack" "aws_csi" {
name = "csi-aws-ebs"
version = "1.22.0"
registry_uid = data.spectrocloud_registry.public_registry.id
}
data "spectrocloud_pack" "aws_cni" {
name = "cni-calico"
version = "3.26.1"
registry_uid = data.spectrocloud_registry.public_registry.id
}
data "spectrocloud_pack" "aws_k8s" {
name = "kubernetes"
version = "1.27.5"
registry_uid = data.spectrocloud_registry.public_registry.id
}
data "spectrocloud_pack" "aws_ubuntu" {
name = "ubuntu-aws"
version = "22.04"
registry_uid = data.spectrocloud_registry.public_registry.id
}
data "spectrocloud_cluster" "aws_cluster_api" {
count = var.deploy-aws ? 1 : 0
name = "aws-cluster-api"
context = "project"
depends_on = [spectrocloud_cluster_aws.aws-cluster-api]
}
resource "spectrocloud_cluster_profile" "aws-profile" {
count = var.deploy-aws ? 1 : 0
name = "tf-aws-profile"
description = "A basic cluster profile for AWS"
tags = concat(var.tags, ["env:aws"])
cloud = "aws"
type = "cluster"
version = "1.0.0"
pack {
name = data.spectrocloud_pack.aws_ubuntu.name
tag = data.spectrocloud_pack.aws_ubuntu.version
uid = data.spectrocloud_pack.aws_ubuntu.id
values = data.spectrocloud_pack.aws_ubuntu.values
}
pack {
name = data.spectrocloud_pack.aws_k8s.name
tag = data.spectrocloud_pack.aws_k8s.version
uid = data.spectrocloud_pack.aws_k8s.id
values = data.spectrocloud_pack.aws_k8s.values
}
pack {
name = data.spectrocloud_pack.aws_cni.name
tag = data.spectrocloud_pack.aws_cni.version
uid = data.spectrocloud_pack.aws_cni.id
values = data.spectrocloud_pack.aws_cni.values
}
pack {
name = data.spectrocloud_pack.aws_csi.name
tag = data.spectrocloud_pack.aws_csi.version
uid = data.spectrocloud_pack.aws_csi.id
values = data.spectrocloud_pack.aws_csi.values
}
pack {
name = "hello-universe"
type = "manifest"
tag = "1.0.0"
values = ""
manifest {
name = "hello-universe"
content = file("manifests/hello-universe.yaml")
}
}
}
```

### Inline YAML Example

An example of a cluster profile using inline YAML.

```terraform
# If looking up a cluster profile instead of creating a new one
# data "spectrocloud_cluster_profile" "profile" {
Expand Down Expand Up @@ -178,6 +284,72 @@ resource "spectrocloud_cluster_profile" "this" {
}
```

### Profile Variables Example

An example of a cluster profile with profile variables. Refer to the [Profile Variables](#nested-schema-for-profile_variablesvariable) section for more information on the nested schema for profile variables.

~> Profile variables are currently under Tech Preview and only available for Edge clusters. Refer to the [Define and Manage Profile Variables](https://docs.spectrocloud.com/profiles/cluster-profiles/create-cluster-profiles/define-profile-variables/) documentation for more information on how to use profile variables.


```terraform
resource "spectrocloud_cluster_profile" "profile" {
name = "vsphere-picard-4"
description = "basic cp"
tags = ["dev", "department:devops", "owner:bob"]
cloud = "vsphere"
type = "cluster"
pack {
name = "ubuntu-vsphere"
tag = "LTS__18.4.x"
uid = data.spectrocloud_pack.ubuntu.id
values = "foo: 1"
}
pack {
name = "kubernetes"
tag = "1.21.5"
uid = data.spectrocloud_pack.k8s.id
values = data.spectrocloud_pack.k8s.values
}
pack {
name = "cni-calico"
tag = "3.16.x"
uid = data.spectrocloud_pack.cni.id
values = data.spectrocloud_pack.cni.values
}
pack {
name = "csi-vsphere-csi"
tag = "2.3.x"
uid = data.spectrocloud_pack.csi.id
values = data.spectrocloud_pack.csi.values
}
profile_variables{
variable {
name = "default_password"
display_name = "Default Password"
format = "string"
hidden = true // For sensitive variables like passwords, setting hidden to true will mask the variable value.
}
variable {
name = "default_version"
display_name = "Version"
format = "version"
description = "description hard-version"
default_value = "0.0.1"
regex = "*.*"
required = true
immutable = false
}
}
}
```


## Import

In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import)
Expand Down
183 changes: 183 additions & 0 deletions templates/resources/cluster_profile.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,191 @@ description: |-

## Example Usage

Example of a cluster profile using data resources.

```terraform

data "spectrocloud_registry" "public_registry" {
name = "Public Repo"
}

data "spectrocloud_cloudaccount_aws" "account" {
count = var.deploy-aws ? 1 : 0
name = var.aws-cloud-account-name
}

data "spectrocloud_pack" "aws_csi" {
name = "csi-aws-ebs"
version = "1.22.0"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "aws_cni" {
name = "cni-calico"
version = "3.26.1"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "aws_k8s" {
name = "kubernetes"
version = "1.27.5"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_pack" "aws_ubuntu" {
name = "ubuntu-aws"
version = "22.04"
registry_uid = data.spectrocloud_registry.public_registry.id
}

data "spectrocloud_cluster" "aws_cluster_api" {
count = var.deploy-aws ? 1 : 0

name = "aws-cluster-api"
context = "project"

depends_on = [spectrocloud_cluster_aws.aws-cluster-api]
}


resource "spectrocloud_cluster_profile" "aws-profile" {
count = var.deploy-aws ? 1 : 0

name = "tf-aws-profile"
description = "A basic cluster profile for AWS"
tags = concat(var.tags, ["env:aws"])
cloud = "aws"
type = "cluster"
version = "1.0.0"

pack {
name = data.spectrocloud_pack.aws_ubuntu.name
tag = data.spectrocloud_pack.aws_ubuntu.version
uid = data.spectrocloud_pack.aws_ubuntu.id
values = data.spectrocloud_pack.aws_ubuntu.values
}

pack {
name = data.spectrocloud_pack.aws_k8s.name
tag = data.spectrocloud_pack.aws_k8s.version
uid = data.spectrocloud_pack.aws_k8s.id
values = data.spectrocloud_pack.aws_k8s.values
}

pack {
name = data.spectrocloud_pack.aws_cni.name
tag = data.spectrocloud_pack.aws_cni.version
uid = data.spectrocloud_pack.aws_cni.id
values = data.spectrocloud_pack.aws_cni.values
}

pack {
name = data.spectrocloud_pack.aws_csi.name
tag = data.spectrocloud_pack.aws_csi.version
uid = data.spectrocloud_pack.aws_csi.id
values = data.spectrocloud_pack.aws_csi.values
}

pack {
name = "hello-universe"
type = "manifest"
tag = "1.0.0"
values = ""
manifest {
name = "hello-universe"
content = file("manifests/hello-universe.yaml")
}
}
}
```

### Inline YAML Example

An example of a cluster profile using inline YAML.

{{ tffile "examples/resources/spectrocloud_cluster_profile/resource.tf" }}


### Example of Providing Multiple Packs

You can provide multiple packs at once by leveraging a dynamic block.

!> The order of the Packs must be taken into consideration so avoid any situations where the order of the Packs is re-arranged by Terraform, such as nested loops `for_each = { for pack in var.packs : pack => pack }`. We recommend creating a variable that contains the list of Packs arranged in order of the App Profile stack and their respective configuration.

```terraform
resource "spectrocloud_cluster_profile" "this" {
name = "security-profile"
dynamic "pack" {
for_each = var.my-packs
}
```

### Profile Variables Example

An example of a cluster profile with profile variables.

~> Profile variables are currently under Tech Preview and only available for Edge clusters. Refer to the [Define and Manage Profile Variables](https://docs.spectrocloud.com/profiles/cluster-profiles/create-cluster-profiles/define-profile-variables/) documentation for more information on how to use profile variables.


```terraform
resource "spectrocloud_cluster_profile" "profile" {
name = "vsphere-picard-4"
description = "basic cp"
tags = ["dev", "department:devops", "owner:bob"]
cloud = "vsphere"
type = "cluster"

pack {
name = "ubuntu-vsphere"
tag = "LTS__18.4.x"
uid = data.spectrocloud_pack.ubuntu.id
values = "foo: 1"
}

pack {
name = "kubernetes"
tag = "1.21.5"
uid = data.spectrocloud_pack.k8s.id
values = data.spectrocloud_pack.k8s.values
}

pack {
name = "cni-calico"
tag = "3.16.x"
uid = data.spectrocloud_pack.cni.id
values = data.spectrocloud_pack.cni.values
}

pack {
name = "csi-vsphere-csi"
tag = "2.3.x"
uid = data.spectrocloud_pack.csi.id
values = data.spectrocloud_pack.csi.values
}


profile_variables{
variable {
name = "default_password"
display_name = "Default Password"
format = "string"
hidden = true // For sensitive variables like passwords, setting hidden to true will mask the variable value.
}
variable {
name = "default_version"
display_name = "Version"
format = "version"
description = "description hard-version"
default_value = "0.0.1"
regex = "*.*"
required = true
immutable = false
}
}
}
```


## Import

In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import)
Expand Down

0 comments on commit b654e15

Please sign in to comment.