diff --git a/spectrocloud/cluster_common_profiles.go b/spectrocloud/cluster_common_profiles.go index a087c76f..e367bd42 100644 --- a/spectrocloud/cluster_common_profiles.go +++ b/spectrocloud/cluster_common_profiles.go @@ -13,8 +13,7 @@ import ( "github.com/spectrocloud/terraform-provider-spectrocloud/types" ) -func toProfiles(c *client.V1Client, d *schema.ResourceData) ([]*models.V1SpectroClusterProfileEntity, error) { - clusterContext := d.Get("context").(string) +func toProfiles(c *client.V1Client, d *schema.ResourceData, clusterContext string) ([]*models.V1SpectroClusterProfileEntity, error) { return toProfilesCommon(c, d, d.Id(), clusterContext) } diff --git a/spectrocloud/resource_cluster_aks.go b/spectrocloud/resource_cluster_aks.go index b7e16de8..ccc63575 100644 --- a/spectrocloud/resource_cluster_aks.go +++ b/spectrocloud/resource_cluster_aks.go @@ -454,7 +454,8 @@ func toAksCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro } } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_aws.go b/spectrocloud/resource_cluster_aws.go index cbec77d6..19abd987 100644 --- a/spectrocloud/resource_cluster_aws.go +++ b/spectrocloud/resource_cluster_aws.go @@ -496,7 +496,8 @@ func toAwsCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro // gnarly, I know! =/ cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{}) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_azure.go b/spectrocloud/resource_cluster_azure.go index 3f16e47a..c1beb411 100644 --- a/spectrocloud/resource_cluster_azure.go +++ b/spectrocloud/resource_cluster_azure.go @@ -489,7 +489,8 @@ func toAzureCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spect cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{}) //clientSecret := strfmt.Password(d.Get("azure_client_secret").(string)) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_coxedge.go b/spectrocloud/resource_cluster_coxedge.go index 65ced376..3221a27c 100644 --- a/spectrocloud/resource_cluster_coxedge.go +++ b/spectrocloud/resource_cluster_coxedge.go @@ -674,7 +674,8 @@ func toCoxEdgeCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spe } } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_edge_native.go b/spectrocloud/resource_cluster_edge_native.go index 8c0950cd..2165e804 100644 --- a/spectrocloud/resource_cluster_edge_native.go +++ b/spectrocloud/resource_cluster_edge_native.go @@ -439,7 +439,8 @@ func toEdgeNativeCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1 } } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_edge_vsphere.go b/spectrocloud/resource_cluster_edge_vsphere.go index a60f7ba0..77b640de 100644 --- a/spectrocloud/resource_cluster_edge_vsphere.go +++ b/spectrocloud/resource_cluster_edge_vsphere.go @@ -494,7 +494,8 @@ func toEdgeVsphereCluster(c *client.V1Client, d *schema.ResourceData) (*models.V vip := cloudConfig["vip"].(string) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_eks.go b/spectrocloud/resource_cluster_eks.go index 1b32f4d5..56539037 100644 --- a/spectrocloud/resource_cluster_eks.go +++ b/spectrocloud/resource_cluster_eks.go @@ -666,7 +666,8 @@ func toEksCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro } } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_gcp.go b/spectrocloud/resource_cluster_gcp.go index 8b5c32c9..59cc725f 100644 --- a/spectrocloud/resource_cluster_gcp.go +++ b/spectrocloud/resource_cluster_gcp.go @@ -413,7 +413,8 @@ func toGcpCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{}) //clientSecret := strfmt.Password(d.Get("gcp_client_secret").(string)) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_import.go b/spectrocloud/resource_cluster_import.go index ae5ebce0..4cea3983 100644 --- a/spectrocloud/resource_cluster_import.go +++ b/spectrocloud/resource_cluster_import.go @@ -207,7 +207,8 @@ func resourceCloudClusterUpdate(_ context.Context, d *schema.ResourceData, m int func toCloudClusterProfiles(c *client.V1Client, d *schema.ResourceData) (*models.V1SpectroClusterProfiles, error) { if profiles := d.Get("cluster_profile").([]interface{}); len(profiles) > 0 { - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_libvirt.go b/spectrocloud/resource_cluster_libvirt.go index ac6f9d8e..4eb71496 100644 --- a/spectrocloud/resource_cluster_libvirt.go +++ b/spectrocloud/resource_cluster_libvirt.go @@ -607,7 +607,8 @@ func toLibvirtCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spe return nil, err } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_maas.go b/spectrocloud/resource_cluster_maas.go index 59e41d80..87aa0db5 100644 --- a/spectrocloud/resource_cluster_maas.go +++ b/spectrocloud/resource_cluster_maas.go @@ -453,7 +453,8 @@ func toMaasCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectr cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{}) DomainVal := cloudConfig["domain"].(string) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_openstack.go b/spectrocloud/resource_cluster_openstack.go index 32899335..0786fd6b 100644 --- a/spectrocloud/resource_cluster_openstack.go +++ b/spectrocloud/resource_cluster_openstack.go @@ -271,7 +271,8 @@ func toOpenStackCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1S cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{}) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_tke.go b/spectrocloud/resource_cluster_tke.go index bd0257bc..e4293c77 100644 --- a/spectrocloud/resource_cluster_tke.go +++ b/spectrocloud/resource_cluster_tke.go @@ -426,7 +426,8 @@ func toTkeCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectro sshKeyIds = append(sshKeyIds, cloudConfig["ssh_key_name"].(string)) } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_virtual.go b/spectrocloud/resource_cluster_virtual.go index 41ca8127..19474b26 100644 --- a/spectrocloud/resource_cluster_virtual.go +++ b/spectrocloud/resource_cluster_virtual.go @@ -36,6 +36,12 @@ func resourceClusterVirtual() *schema.Resource { Required: true, ForceNew: true, }, + "context": { + Type: schema.TypeString, + Optional: true, + Default: "project", + ValidateFunc: validation.StringInSlice([]string{"project", "cluster"}, false), + }, "tags": { Type: schema.TypeSet, Optional: true, @@ -368,7 +374,8 @@ func toVirtualCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spe kubernetesVersion = cloudConfig["k8s_version"].(string) } - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err } diff --git a/spectrocloud/resource_cluster_vsphere.go b/spectrocloud/resource_cluster_vsphere.go index 64e9a3b5..432398ab 100644 --- a/spectrocloud/resource_cluster_vsphere.go +++ b/spectrocloud/resource_cluster_vsphere.go @@ -678,7 +678,8 @@ func toVsphereCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spe cloudConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{}) //clientSecret := strfmt.Password(d.Get("azure_client_secret").(string)) - profiles, err := toProfiles(c, d) + clusterContext := d.Get("context").(string) + profiles, err := toProfiles(c, d, clusterContext) if err != nil { return nil, err }