diff --git a/docs/resources/addon_deployment.md b/docs/resources/addon_deployment.md index bfa4e679..ccbf65a0 100644 --- a/docs/resources/addon_deployment.md +++ b/docs/resources/addon_deployment.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_aks.md b/docs/resources/cluster_aks.md index d56c46cc..3854f716 100644 --- a/docs/resources/cluster_aks.md +++ b/docs/resources/cluster_aks.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_aws.md b/docs/resources/cluster_aws.md index 9707e999..2b291caa 100644 --- a/docs/resources/cluster_aws.md +++ b/docs/resources/cluster_aws.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_azure.md b/docs/resources/cluster_azure.md index 74ea77f4..41e4da39 100644 --- a/docs/resources/cluster_azure.md +++ b/docs/resources/cluster_azure.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_custom_cloud.md b/docs/resources/cluster_custom_cloud.md index af88c0bc..938d459b 100644 --- a/docs/resources/cluster_custom_cloud.md +++ b/docs/resources/cluster_custom_cloud.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_edge_native.md b/docs/resources/cluster_edge_native.md index 9f5633fd..1e1d4e1a 100644 --- a/docs/resources/cluster_edge_native.md +++ b/docs/resources/cluster_edge_native.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_edge_vsphere.md b/docs/resources/cluster_edge_vsphere.md index 65ea25af..243750c2 100644 --- a/docs/resources/cluster_edge_vsphere.md +++ b/docs/resources/cluster_edge_vsphere.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_eks.md b/docs/resources/cluster_eks.md index 634f32c7..64d5365b 100644 --- a/docs/resources/cluster_eks.md +++ b/docs/resources/cluster_eks.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_gcp.md b/docs/resources/cluster_gcp.md index 65331782..e519e1ca 100644 --- a/docs/resources/cluster_gcp.md +++ b/docs/resources/cluster_gcp.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_gke.md b/docs/resources/cluster_gke.md index c28a89da..969d5575 100644 --- a/docs/resources/cluster_gke.md +++ b/docs/resources/cluster_gke.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_group.md b/docs/resources/cluster_group.md index 2df02679..cef761e9 100644 --- a/docs/resources/cluster_group.md +++ b/docs/resources/cluster_group.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_import.md b/docs/resources/cluster_import.md index 6a524052..b85e6100 100644 --- a/docs/resources/cluster_import.md +++ b/docs/resources/cluster_import.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_maas.md b/docs/resources/cluster_maas.md index 4a75bbde..6b2f65e1 100644 --- a/docs/resources/cluster_maas.md +++ b/docs/resources/cluster_maas.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_openstack.md b/docs/resources/cluster_openstack.md index 2ceb6a6f..a0fde475 100644 --- a/docs/resources/cluster_openstack.md +++ b/docs/resources/cluster_openstack.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_tke.md b/docs/resources/cluster_tke.md index c98d3a65..67012d5e 100644 --- a/docs/resources/cluster_tke.md +++ b/docs/resources/cluster_tke.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/cluster_vsphere.md b/docs/resources/cluster_vsphere.md index de286868..54b961a5 100644 --- a/docs/resources/cluster_vsphere.md +++ b/docs/resources/cluster_vsphere.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/docs/resources/virtual_cluster.md b/docs/resources/virtual_cluster.md index 2037f2ff..7b70e26a 100644 --- a/docs/resources/virtual_cluster.md +++ b/docs/resources/virtual_cluster.md @@ -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"`. ### Nested Schema for `cluster_profile.pack` diff --git a/examples/resources/spectrocloud_cluster_aws/resource.tf b/examples/resources/spectrocloud_cluster_aws/resource.tf index f85ee121..698d1952 100644 --- a/examples/resources/spectrocloud_cluster_aws/resource.tf +++ b/examples/resources/spectrocloud_cluster_aws/resource.tf @@ -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 { 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 66389c63..0006c64a 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,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{}) { diff --git a/spectrocloud/resource_cluster_profile_test.go b/spectrocloud/resource_cluster_profile_test.go index f1e1e197..5e02d6ff 100644 --- a/spectrocloud/resource_cluster_profile_test.go +++ b/spectrocloud/resource_cluster_profile_test.go @@ -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") @@ -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") @@ -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) } diff --git a/spectrocloud/schemas/cluster_profile.go b/spectrocloud/schemas/cluster_profile.go index e48fc0d7..baeea623 100644 --- a/spectrocloud/schemas/cluster_profile.go +++ b/spectrocloud/schemas/cluster_profile.go @@ -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, + }, + }, }, }, }