From 3b0b3cb98cfa1194ce985a85c726e8e99006f68b Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Fri, 20 Dec 2024 10:40:42 +0530 Subject: [PATCH] PLT-1110: Added profile variable support during cluster provisioning. --- spectrocloud/cluster_common_profiles.go | 13 +++++++++++++ spectrocloud/resource_cluster_profile.go | 17 ++++++++--------- spectrocloud/schemas/cluster_profile.go | 5 +++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/spectrocloud/cluster_common_profiles.go b/spectrocloud/cluster_common_profiles.go index 6856a6aa..c5f0c5cb 100644 --- a/spectrocloud/cluster_common_profiles.go +++ b/spectrocloud/cluster_common_profiles.go @@ -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" @@ -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{}) { @@ -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, }) } } diff --git a/spectrocloud/resource_cluster_profile.go b/spectrocloud/resource_cluster_profile.go index 65caf1b3..fa207694 100644 --- a/spectrocloud/resource_cluster_profile.go +++ b/spectrocloud/resource_cluster_profile.go @@ -2,7 +2,6 @@ package spectrocloud import ( "context" - "errors" "fmt" "github.com/spectrocloud/gomi/pkg/ptr" @@ -478,14 +477,14 @@ func toClusterProfileVariables(d *schema.ResourceData) ([]*models.V1Variable, er 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 - } - } + //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"] diff --git a/spectrocloud/schemas/cluster_profile.go b/spectrocloud/schemas/cluster_profile.go index e48fc0d7..ad3f42ea 100644 --- a/spectrocloud/schemas/cluster_profile.go +++ b/spectrocloud/schemas/cluster_profile.go @@ -16,6 +16,11 @@ 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, defined as key-value pairs. Example: `priority: 5`.", + }, }, }, }