Skip to content

Commit

Permalink
PLT-1110: Added profile variable support during cluster provisioning. (
Browse files Browse the repository at this point in the history
…#557)

* PLT-1110: Added profile variable support during cluster provisioning.

* add docs

* removed commented code
  • Loading branch information
SivaanandM authored Dec 26, 2024
1 parent adc95fe commit 379f566
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/resources/addon_deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aks.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_custom_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_eks.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_gke.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_maas.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_openstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_tke.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/virtual_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Required:
Optional:

- `pack` (Block List) For packs of type `spectro`, `helm`, and `manifest`, at least one pack must be specified. (see [below for nested schema](#nestedblock--cluster_profile--pack))
- `variables` (Map of String) A map of cluster profile variables, specified as key-value pairs. For example: `priority = "5"`.

<a id="nestedblock--cluster_profile--pack"></a>
### Nested Schema for `cluster_profile.pack`
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/spectrocloud_cluster_aws/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ resource "spectrocloud_cluster_aws" "cluster" {
cluster_profile {
id = data.spectrocloud_cluster_profile.profile.id

variables = {
"priority" = "5",
"default_cmd" = "pwd"
}

# To override or specify values for a cluster:

# pack {
Expand Down
13 changes: 13 additions & 0 deletions spectrocloud/cluster_common_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package spectrocloud
import (
"context"
"fmt"
"github.com/spectrocloud/gomi/pkg/ptr"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -53,6 +54,17 @@ func toProfilesCommon(c *client.V1Client, d *schema.ResourceData, clusterUID, co
if len(profiles) > 0 {
for _, profile := range profiles {
p := profile.(map[string]interface{})
// Profile Variables handling
pVars := make([]*models.V1SpectroClusterVariable, 0)
if pv, ok := p["variables"]; ok && pv != nil {
variables := p["variables"].(map[string]interface{})
for key, value := range variables {
pVars = append(pVars, &models.V1SpectroClusterVariable{
Name: ptr.StringPtr(key),
Value: value.(string),
})
}
}

packValues := make([]*models.V1PackValuesEntity, 0)
for _, pack := range p["pack"].([]interface{}) {
Expand All @@ -62,6 +74,7 @@ func toProfilesCommon(c *client.V1Client, d *schema.ResourceData, clusterUID, co
resp = append(resp, &models.V1SpectroClusterProfileEntity{
UID: p["id"].(string),
PackValues: packValues,
Variables: pVars,
})
}
}
Expand Down
11 changes: 0 additions & 11 deletions spectrocloud/resource_cluster_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spectrocloud

import (
"context"
"errors"
"fmt"
"github.com/spectrocloud/gomi/pkg/ptr"

Expand Down Expand Up @@ -478,16 +477,6 @@ func toClusterProfileVariables(d *schema.ResourceData) ([]*models.V1Variable, er
var profileVariables []*models.V1Variable
if pVariables, ok := d.GetOk("profile_variables"); ok {

// Once the profile_Variables feature is extended to all cloud types, the following block should be removed.
cloudType, _ := d.Get("cloud").(string)
profileType, _ := d.Get("type").(string)
if cloudType != "edge-native" {
if profileType != "add-on" {
err := errors.New("currently, `profile_variables` is only supported for the `add-on` profile type and other profile type is supported only for edge-native cloud type")
return profileVariables, err
}
}

if pVariables.([]interface{})[0] != nil {
variables := pVariables.([]interface{})[0].(map[string]interface{})["variable"]
for _, v := range variables.([]interface{}) {
Expand Down
10 changes: 5 additions & 5 deletions spectrocloud/resource_cluster_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ func TestToClusterProfileVariablesRestrictionError(t *testing.T) {
result, err := toClusterProfileVariables(mockResourceData)

// Assertions for valid profile variables
assert.Error(t, err)
assert.Len(t, result, 0)
assert.NoError(t, err)
assert.Len(t, result, 2)

_ = mockResourceData.Set("cloud", "edge-native")
_ = mockResourceData.Set("type", "infra")
Expand All @@ -228,8 +228,8 @@ func TestToClusterProfileVariablesRestrictionError(t *testing.T) {
_ = mockResourceData.Set("cloud", "aws")
_ = mockResourceData.Set("type", "infra")
result, err = toClusterProfileVariables(mockResourceData)
assert.Error(t, err)
assert.Len(t, result, 0)
assert.NoError(t, err)
assert.Len(t, result, 2)

_ = mockResourceData.Set("cloud", "edge-native")
_ = mockResourceData.Set("type", "add-on")
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestResourceClusterProfileCreate(t *testing.T) {
func TestResourceClusterProfileCreateError(t *testing.T) {
d := prepareBaseClusterProfileTestData()
var ctx context.Context
diags := resourceClusterProfileCreate(ctx, d, unitTestMockAPIClient)
diags := resourceClusterProfileCreate(ctx, d, unitTestMockAPINegativeClient)
assert.NotEmpty(t, diags)
}

Expand Down
8 changes: 8 additions & 0 deletions spectrocloud/schemas/cluster_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ func ClusterProfileSchema() *schema.Schema {
Description: "The ID of the cluster profile.",
},
"pack": PackSchema(),
"variables": {
Type: schema.TypeMap,
Optional: true,
Description: "A map of cluster profile variables, specified as key-value pairs. For example: `priority = \"5\"`.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
}
Expand Down

0 comments on commit 379f566

Please sign in to comment.