Skip to content

Commit

Permalink
Merging with main.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Sep 29, 2023
2 parents bec72ae + 0ff60c3 commit a89a3fd
Show file tree
Hide file tree
Showing 45 changed files with 1,124 additions and 54 deletions.
8 changes: 8 additions & 0 deletions docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ resource "local_file" "kubeconfig" {
file_permission = "0644"
directory_permission = "0755"
}
resource "local_file" "adminkubeconfig" {
content = data.spectrocloud_cluster.cluster.admin_kube_config
filename = "admin-client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -39,6 +46,7 @@ resource "local_file" "kubeconfig" {

### Read-Only

- `admin_kube_config` (String)
- `id` (String) The ID of this resource.
- `kube_config` (String)

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 @@ -120,6 +120,7 @@ resource "spectrocloud_cluster_aks" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/cluster_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ resource "spectrocloud_cluster_aws" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand All @@ -166,6 +167,7 @@ Required:

Optional:

- `control_plane_lb` (String) Control plane load balancer type. Valid values are `Internet-facing` and `internal`. Defaults to `` (empty string).
- `vpc_id` (String)


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 @@ -114,6 +114,7 @@ resource "spectrocloud_cluster_azure" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_coxedge.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/cluster_edge_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down Expand Up @@ -76,6 +77,7 @@ Optional:
- `control_plane_as_worker` (Boolean) Whether this machine pool is a control plane and a worker. Defaults to `false`.
- `host_uids` (List of String, Deprecated)
- `node` (Block List) (see [below for nested schema](#nestedblock--machine_pool--node))
- `node_repave_interval` (Number) Minimum number of seconds node should be Ready, before the next node is selected for repave. Default value is `0`, Applicable only for worker pools.
- `taints` (Block List) (see [below for nested schema](#nestedblock--machine_pool--taints))
- `update_strategy` (String) Update strategy for the machine pool. Valid values are `RollingUpdateScaleOut` and `RollingUpdateScaleIn`.

Expand All @@ -88,6 +90,7 @@ Required:

Optional:

- `host_name` (String) Edge host name
- `static_ip` (String) Edge host static IP


Expand Down
2 changes: 2 additions & 0 deletions docs/resources/cluster_edge_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down Expand Up @@ -84,6 +85,7 @@ Optional:
- `control_plane` (Boolean) Whether this machine pool is a control plane. Defaults to `false`.
- `control_plane_as_worker` (Boolean) Whether this machine pool is a control plane and a worker. Defaults to `false`.
- `node` (Block List) (see [below for nested schema](#nestedblock--machine_pool--node))
- `node_repave_interval` (Number) Minimum number of seconds node should be Ready, before the next node is selected for repave. Default value is `0`, Applicable only for worker pools.
- `taints` (Block List) (see [below for nested schema](#nestedblock--machine_pool--taints))
- `update_strategy` (String) Update strategy for the machine pool. Valid values are `RollingUpdateScaleOut` and `RollingUpdateScaleIn`.

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 @@ -119,6 +119,7 @@ resource "spectrocloud_cluster_eks" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
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 @@ -111,6 +111,7 @@ resource "spectrocloud_cluster_gcp" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/cluster_libvirt.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down Expand Up @@ -82,6 +83,7 @@ Optional:
- `control_plane` (Boolean) Whether this machine pool is a control plane. Defaults to `false`.
- `control_plane_as_worker` (Boolean) Whether this machine pool is a control plane and a worker. Defaults to `false`.
- `node` (Block List) (see [below for nested schema](#nestedblock--machine_pool--node))
- `node_repave_interval` (Number) Minimum number of seconds node should be Ready, before the next node is selected for repave. Default value is `0`, Applicable only for worker pools.
- `taints` (Block List) (see [below for nested schema](#nestedblock--machine_pool--taints))
- `update_strategy` (String) Update strategy for the machine pool. Valid values are `RollingUpdateScaleOut` and `RollingUpdateScaleIn`.
- `xsl_template` (String) XSL template to use.
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 @@ -121,6 +121,7 @@ resource "spectrocloud_cluster_maas" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
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 @@ -112,6 +112,7 @@ resource "spectrocloud_cluster_openstack" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
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 @@ -42,6 +42,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
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 @@ -46,6 +46,7 @@ description: |-

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/virtual_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ resource "spectrocloud_virtual_cluster" "cluster" {
- `cluster_group_uid` (String)
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String)
- `force_delete` (Boolean) If set to `true`, the cluster will be force deleted and user has to manually clean up the provisioned cloud resources.
- `force_delete_delay` (Number) Delay duration in minutes to before invoking cluster force delete. Default and minimum is 20.
- `host_cluster_uid` (String)
Expand All @@ -78,6 +79,7 @@ resource "spectrocloud_virtual_cluster" "cluster" {

### Read-Only

- `admin_kube_config` (String) Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.
- `cloud_config_id` (String, Deprecated) ID of the cloud config used for the cluster. This cloud config must be of type `azure`.
- `id` (String) The ID of this resource.
- `kubeconfig` (String) Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.
Expand Down
9 changes: 8 additions & 1 deletion examples/data-sources/spectrocloud_cluster/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ resource "local_file" "kubeconfig" {
filename = "client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
}

resource "local_file" "adminkubeconfig" {
content = data.spectrocloud_cluster.cluster.admin_kube_config
filename = "admin-client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
13 changes: 0 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -716,21 +716,8 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08 h1:AnOC0U+ExlKBeT5yF2Pg8PPfVOfxwOUBS/5deOl1Q4Y=
github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08/go.mod h1:UnhUDpFEvtYh6m384r3xzj8/+Z6/hMp2O8whEMYVHec=
github.com/spectrocloud/hapi v1.14.1-0.20230713122351-f8bd7ba4aadb h1:wJyXW46nQ+Y3s0lw2dwnqWJzvmgUkFE6sOnLg74OBqQ=
github.com/spectrocloud/hapi v1.14.1-0.20230713122351-f8bd7ba4aadb/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230725063533-747bfb65273c/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230728115057-a06048fce005 h1:4cqQjre24hzbzNyzK/nFvJ2HRTltSSy0wWv7LfvhJac=
github.com/spectrocloud/hapi v1.14.1-0.20230728115057-a06048fce005/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230807064918-84ea4f44e8b6 h1:zNt40nfqO2dxUhsxyd1OtQxOOJ+6WZNQMb5EWZZaO24=
github.com/spectrocloud/hapi v1.14.1-0.20230807064918-84ea4f44e8b6/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230811064706-971744352a99 h1:chOe5BrA4YS8SMS6PDOZjy+kJG5RAAWAa0sVGFU5WrY=
github.com/spectrocloud/hapi v1.14.1-0.20230811064706-971744352a99/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230831024748-b41d1da96703 h1:rAVSr051yEXVidy+K5D/bAuFe734Bz6kXssHttycmVs=
github.com/spectrocloud/hapi v1.14.1-0.20230831024748-b41d1da96703/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230928114741-1670ab9a5e2b h1:Ws5/fRo/EDEt1rJgNEtd2E/w/IOOA+jOVWv3tw6aT+s=
github.com/spectrocloud/hapi v1.14.1-0.20230928114741-1670ab9a5e2b/go.mod h1:aI54jbfaSec1ikHSMOJQ7mMOTaRKpQTRCoMKamhBE9s=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230829045040-bf4cc9aa60e1 h1:gqnua/jMzX8fx9yt+niCxQ99XkzKiA+HF+LRbFbWYC8=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230829045040-bf4cc9aa60e1/go.mod h1:xrvueWGPSRdonQkTQvJgDSPe5FRbuqpPJj7Ko0/yxrQ=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230925161114-b76840d1207d h1:4VBWbaMTnMbURawJcOPlDrhNpxj78cxrPwMuh52pegw=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230925161114-b76840d1207d/go.mod h1:Om6X/eH6h787jrynu9NTAeuxFpC15E/Atco5kQwiM90=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
9 changes: 9 additions & 0 deletions spectrocloud/cluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ func toNtpServers(in map[string]interface{}) []string {

func toClusterConfig(d *schema.ResourceData) *models.V1ClusterConfigEntity {
return &models.V1ClusterConfigEntity{
ClusterMetaAttribute: toClusterMetaAttribute(d),
MachineManagementConfig: toMachineManagementConfig(d),
Resources: toClusterResourceConfig(d),
HostClusterConfig: toClusterHostConfigs(d),
Location: toClusterLocationConfigs(d),
}
}

func toClusterMetaAttribute(d *schema.ResourceData) string {
clusterMetadataAttribute := ""
if v, ok := d.GetOk("cluster_meta_attribute"); ok {
clusterMetadataAttribute = v.(string)
}
return clusterMetadataAttribute
}

func toMachineManagementConfig(d *schema.ResourceData) *models.V1MachineManagementConfig {
return &models.V1MachineManagementConfig{
OsPatchConfig: toOsPatchConfig(d),
Expand Down
22 changes: 22 additions & 0 deletions spectrocloud/cluster_common_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ func readCommonFields(c *client.V1Client, d *schema.ResourceData, cluster *model
return diag.FromErr(err), true
}

adminKubeConfig, err := c.GetClusterAdminKubeConfig(d.Id(), ClusterContext)
if err != nil {
return diag.FromErr(err), true
}
if err := d.Set("admin_kube_config", adminKubeConfig); err != nil {
return diag.FromErr(err), true
}

if err := d.Set("tags", flattenTags(cluster.Metadata.Labels)); err != nil {
return diag.FromErr(err), true
}
Expand Down Expand Up @@ -57,6 +65,14 @@ func readCommonFields(c *client.V1Client, d *schema.ResourceData, cluster *model
}
}

clusterAdditionalMeta := cluster.Spec.ClusterConfig.ClusterMetaAttribute
if clusterAdditionalMeta != "" {
err := d.Set("cluster_meta_attribute", clusterAdditionalMeta)
if err != nil {
return diag.FromErr(err), true
}
}

hostConfig := cluster.Spec.ClusterConfig.HostClusterConfig
if hostConfig != nil && *hostConfig.IsHostCluster {
flattenHostConfig := flattenHostConfig(hostConfig)
Expand Down Expand Up @@ -130,6 +146,12 @@ func updateCommonFields(d *schema.ResourceData, c *client.V1Client) (diag.Diagno
}
}

if d.HasChange("cluster_meta_attribute") {
if err := updateClusterAdditionalMetadata(c, d); err != nil {
return diag.FromErr(err), true
}
}

if d.HasChange("location_config") {
if err := updateLocationConfig(c, d); err != nil {
return diag.FromErr(err), true
Expand Down
37 changes: 25 additions & 12 deletions spectrocloud/cluster_common_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ func resourceMachinePoolEksHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%s-", m["capacity_type"].(string)))
buf.WriteString(fmt.Sprintf("%s-", m["max_price"].(string)))

for i, j := range m["az_subnets"].(map[string]interface{}) {
buf.WriteString(fmt.Sprintf("%s-%s", i, j.(string)))
keys := make([]string, 0, len(m["az_subnets"].(map[string]interface{})))
for k := range m["az_subnets"].(map[string]interface{}) {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
buf.WriteString(fmt.Sprintf("%s-%s", k, m["az_subnets"].(map[string]interface{})[k].(string)))
}

if m["eks_launch_template"] != nil {
Expand Down Expand Up @@ -194,8 +199,13 @@ func resourceMachinePoolTkeHash(v interface{}) int {
m := v.(map[string]interface{})
buf := CommonHash(m)

for i, j := range m["az_subnets"].(map[string]interface{}) {
buf.WriteString(fmt.Sprintf("%s-%s", i, j.(string)))
keys := make([]string, 0, len(m["az_subnets"].(map[string]interface{})))
for k := range m["az_subnets"].(map[string]interface{}) {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
buf.WriteString(fmt.Sprintf("%s-%s", k, m["az_subnets"].(map[string]interface{})[k].(string)))
}

return int(hash(buf.String()))
Expand Down Expand Up @@ -367,23 +377,26 @@ func HashStringMapList(v interface{}) string {
}

func HashStringMap(v interface{}) string {
if v == nil || len(v.(map[string]interface{})) == 0 {
if v == nil {
return ""
}

m, ok := v.(map[string]interface{})
if !ok || len(m) == 0 {
return ""
}

var b bytes.Buffer
m := v.(map[string]interface{})

keys := make([]string, 0)
// Create and sort the keys
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)

sortedKeys := make([]string, len(keys))
copy(sortedKeys, keys)
sort.Strings(sortedKeys)

for _, k := range sortedKeys {
// Construct the string based on sorted keys
for _, k := range keys {
b.WriteString(fmt.Sprintf("%s-%s", k, m[k].(string)))
}

Expand Down
10 changes: 10 additions & 0 deletions spectrocloud/cluster_common_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ func toUpdateClusterMetadata(d *schema.ResourceData) *models.V1ObjectMetaInputEn
Metadata: toClusterMeta(d),
}
}

func updateClusterAdditionalMetadata(c *client.V1Client, d *schema.ResourceData) error {
return c.UpdateAdditionalClusterMetadata(d.Id(), toUpdateClusterAdditionalMetadata(d))
}

func toUpdateClusterAdditionalMetadata(d *schema.ResourceData) *models.V1ClusterMetaAttributeEntity {
return &models.V1ClusterMetaAttributeEntity{
ClusterMetaAttribute: toClusterMetaAttribute(d),
}
}
22 changes: 18 additions & 4 deletions spectrocloud/cluster_common_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ 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)
}

func toAddonDeplProfiles(c *client.V1Client, d *schema.ResourceData) ([]*models.V1SpectroClusterProfileEntity, error) {
clusterUid := d.Get("cluster_uid").(string)
clusterContext := d.Get("cluster_context").(string)
clusterUid := ""
clusterContext := ""
// handling cluster attachment flow for cluster created outside terraform and attaching addon profile to it
if uid, ok := d.GetOk("cluster_uid"); ok && uid != nil {
clusterUid = uid.(string) //d.Get("cluster_uid").(string)
}
if ct, ok := d.GetOk("cluster_context"); ok && c != nil {
clusterContext = ct.(string) //d.Get("cluster_context").(string)
}
// handling cluster day 2 addon profile operation flow
if clusterUid == "" {
clusterUid = d.Id()
}
if clusterContext == "" {
clusterContext = d.Get("context").(string)
}

return toProfilesCommon(c, d, clusterUid, clusterContext)
}

Expand Down
Loading

0 comments on commit a89a3fd

Please sign in to comment.