@@ -9,52 +9,51 @@ import (
99
1010 "github.com/hashicorp/terraform-plugin-framework/diag"
1111 "github.com/hashicorp/terraform-plugin-framework/types"
12- "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1312 console "github.com/pluralsh/console-client-go"
1413)
1514
1615type cluster struct {
17- Id types.String `tfsdk:"id"`
18- InsertedAt types.String `tfsdk:"inserted_at"`
19- Name types.String `tfsdk:"name"`
20- Handle types.String `tfsdk:"handle"`
21- Version types.String `tfsdk:"version"`
22- DesiredVersion types.String `tfsdk:"desired_version"`
23- ProviderId types.String `tfsdk:"provider_id"`
24- Cloud types.String `tfsdk:"cloud"`
25- Protect types.Bool `tfsdk:"protect"`
26- Tags types.Map `tfsdk:"tags"`
27- Metadata types.String `tfsdk:"metadata"`
28- Bindings * common.ClusterBindings `tfsdk:"bindings"`
29- NodePools types.Map `tfsdk:"node_pools"`
30- CloudSettings * ClusterCloudSettings `tfsdk:"cloud_settings"`
31- HelmRepoUrl types.String `tfsdk:"helm_repo_url"`
32- HelmValues types.String `tfsdk:"helm_values"`
33- Kubeconfig * Kubeconfig `tfsdk:"kubeconfig"`
34- }
35-
36- func (c * cluster ) NodePoolsAttribute (ctx context.Context , d diag.Diagnostics ) []* console.NodePoolAttributes {
37- result := make ([]* console.NodePoolAttributes , 0 , len (c .NodePools .Elements ()))
38- nodePools := make (map [string ]common.ClusterNodePool , len (c .NodePools .Elements ()))
39- d .Append (c .NodePools .ElementsAs (ctx , & nodePools , false )... )
40-
41- for _ , nodePool := range nodePools {
42- var nodePoolCloudSettings * common.NodePoolCloudSettings
43- d .Append (nodePool .CloudSettings .As (ctx , nodePoolCloudSettings , basetypes.ObjectAsOptions {})... )
44-
45- result = append (result , & console.NodePoolAttributes {
46- Name : nodePool .Name .ValueString (),
47- MinSize : nodePool .MinSize .ValueInt64 (),
48- MaxSize : nodePool .MaxSize .ValueInt64 (),
49- InstanceType : nodePool .InstanceType .ValueString (),
50- Labels : nodePool .LabelsAttribute (ctx , d ),
51- Taints : nodePool .TaintsAttribute (ctx , d ),
52- CloudSettings : nodePoolCloudSettings .Attributes (),
53- })
54- }
55-
56- return result
57- }
16+ Id types.String `tfsdk:"id"`
17+ InsertedAt types.String `tfsdk:"inserted_at"`
18+ Name types.String `tfsdk:"name"`
19+ Handle types.String `tfsdk:"handle"`
20+ // Version types.String `tfsdk:"version"`
21+ // DesiredVersion types.String `tfsdk:"desired_version"`
22+ // ProviderId types.String `tfsdk:"provider_id"`
23+ // Cloud types.String `tfsdk:"cloud"`
24+ Protect types.Bool `tfsdk:"protect"`
25+ Tags types.Map `tfsdk:"tags"`
26+ Metadata types.String `tfsdk:"metadata"`
27+ Bindings * common.ClusterBindings `tfsdk:"bindings"`
28+ // NodePools types.Map `tfsdk:"node_pools"`
29+ // CloudSettings *ClusterCloudSettings `tfsdk:"cloud_settings"`
30+ HelmRepoUrl types.String `tfsdk:"helm_repo_url"`
31+ HelmValues types.String `tfsdk:"helm_values"`
32+ Kubeconfig * Kubeconfig `tfsdk:"kubeconfig"`
33+ }
34+
35+ // func (c *cluster) NodePoolsAttribute(ctx context.Context, d diag.Diagnostics) []*console.NodePoolAttributes {
36+ // result := make([]*console.NodePoolAttributes, 0, len(c.NodePools.Elements()))
37+ // nodePools := make(map[string]common.ClusterNodePool, len(c.NodePools.Elements()))
38+ // d.Append(c.NodePools.ElementsAs(ctx, &nodePools, false)...)
39+
40+ // for _, nodePool := range nodePools {
41+ // var nodePoolCloudSettings *common.NodePoolCloudSettings
42+ // d.Append(nodePool.CloudSettings.As(ctx, nodePoolCloudSettings, basetypes.ObjectAsOptions{})...)
43+
44+ // result = append(result, &console.NodePoolAttributes{
45+ // Name: nodePool.Name.ValueString(),
46+ // MinSize: nodePool.MinSize.ValueInt64(),
47+ // MaxSize: nodePool.MaxSize.ValueInt64(),
48+ // InstanceType: nodePool.InstanceType.ValueString(),
49+ // Labels: nodePool.LabelsAttribute(ctx, d),
50+ // Taints: nodePool.TaintsAttribute(ctx, d),
51+ // CloudSettings: nodePoolCloudSettings.Attributes(),
52+ // })
53+ // }
54+
55+ // return result
56+ // }
5857
5958func (c * cluster ) TagsAttribute (ctx context.Context , d diag.Diagnostics ) []* console.TagAttributes {
6059 result := make ([]* console.TagAttributes , 0 )
@@ -70,28 +69,28 @@ func (c *cluster) TagsAttribute(ctx context.Context, d diag.Diagnostics) []*cons
7069
7170func (c * cluster ) Attributes (ctx context.Context , d diag.Diagnostics ) console.ClusterAttributes {
7271 return console.ClusterAttributes {
73- Name : c .Name .ValueString (),
74- Handle : c .Handle .ValueStringPointer (),
75- ProviderID : c .ProviderId .ValueStringPointer (),
76- Version : c .Version .ValueStringPointer (),
77- Protect : c .Protect .ValueBoolPointer (),
78- CloudSettings : c .CloudSettings .Attributes (),
72+ Name : c .Name .ValueString (),
73+ Handle : c .Handle .ValueStringPointer (),
74+ // ProviderID: c.ProviderId.ValueStringPointer(),
75+ // Version: c.Version.ValueStringPointer(),
76+ Protect : c .Protect .ValueBoolPointer (),
77+ // CloudSettings: c.CloudSettings.Attributes(),
7978 ReadBindings : c .Bindings .ReadAttributes (ctx , d ),
8079 WriteBindings : c .Bindings .WriteAttributes (ctx , d ),
8180 Tags : c .TagsAttribute (ctx , d ),
82- NodePools : c .NodePoolsAttribute (ctx , d ),
83- Metadata : c .Metadata .ValueStringPointer (),
81+ // NodePools: c.NodePoolsAttribute(ctx, d),
82+ Metadata : c .Metadata .ValueStringPointer (),
8483 }
8584}
8685
8786func (c * cluster ) UpdateAttributes (ctx context.Context , d diag.Diagnostics ) console.ClusterUpdateAttributes {
8887 return console.ClusterUpdateAttributes {
89- Version : c .Version .ValueStringPointer (),
90- Handle : c .Handle .ValueStringPointer (),
91- Protect : c .Protect .ValueBoolPointer (),
92- NodePools : c .NodePoolsAttribute (ctx , d ),
93- Metadata : c .Metadata .ValueStringPointer (),
94- Tags : c .TagsAttribute (ctx , d ),
88+ // Version: c.Version.ValueStringPointer(),
89+ Handle : c .Handle .ValueStringPointer (),
90+ Protect : c .Protect .ValueBoolPointer (),
91+ // NodePools: c.NodePoolsAttribute(ctx, d),
92+ Metadata : c .Metadata .ValueStringPointer (),
93+ Tags : c .TagsAttribute (ctx , d ),
9594 }
9695}
9796
@@ -106,11 +105,11 @@ func (c *cluster) From(cl *console.ClusterFragment, ctx context.Context, d diag.
106105 c .InsertedAt = types .StringPointerValue (cl .InsertedAt )
107106 c .Name = types .StringValue (cl .Name )
108107 c .Handle = types .StringPointerValue (cl .Handle )
109- c .DesiredVersion = c .ClusterVersionFrom (cl .Version , cl .CurrentVersion )
108+ // c.DesiredVersion = c.ClusterVersionFrom(cl.Provider, cl.Version, cl.CurrentVersion)
110109 c .Protect = types .BoolPointerValue (cl .Protect )
111110 c .Tags = common .ClusterTagsFrom (cl .Tags , d )
112- c .ProviderId = common .ClusterProviderIdFrom (cl .Provider )
113- c .NodePools = common .ClusterNodePoolsFrom (cl .NodePools , c .NodePools , ctx , d )
111+ // c.ProviderId = common.ClusterProviderIdFrom(cl.Provider)
112+ // c.NodePools = common.ClusterNodePoolsFrom(cl.NodePools, c.NodePools, ctx, d)
114113 c .Metadata = types .StringValue (string (metadata ))
115114}
116115
@@ -119,14 +118,18 @@ func (c *cluster) FromCreate(cc *console.CreateCluster, ctx context.Context, d d
119118 c .InsertedAt = types .StringPointerValue (cc .CreateCluster .InsertedAt )
120119 c .Name = types .StringValue (cc .CreateCluster .Name )
121120 c .Handle = types .StringPointerValue (cc .CreateCluster .Handle )
122- c .DesiredVersion = c .ClusterVersionFrom (cc .CreateCluster .Version , cc .CreateCluster .CurrentVersion )
121+ // c.DesiredVersion = c.ClusterVersionFrom(cc.CreateCluster.Provider, cc.CreateCluster.Version, cc.CreateCluster.CurrentVersion)
123122 c .Protect = types .BoolPointerValue (cc .CreateCluster .Protect )
124123 c .Tags = common .ClusterTagsFrom (cc .CreateCluster .Tags , d )
125- c .ProviderId = common .ClusterProviderIdFrom (cc .CreateCluster .Provider )
126- c .NodePools = common .ClusterNodePoolsFrom (cc .CreateCluster .NodePools , c .NodePools , ctx , d )
124+ // c.ProviderId = common.ClusterProviderIdFrom(cc.CreateCluster.Provider)
125+ // c.NodePools = common.ClusterNodePoolsFrom(cc.CreateCluster.NodePools, c.NodePools, ctx, d)
127126}
128127
129- func (c * cluster ) ClusterVersionFrom (version , currentVersion * string ) types.String {
128+ func (c * cluster ) ClusterVersionFrom (prov * console.ClusterProviderFragment , version , currentVersion * string ) types.String {
129+ if prov == nil {
130+ return types .StringValue ("unknown" )
131+ }
132+
130133 if version != nil && len (* version ) > 0 {
131134 return types .StringPointerValue (version )
132135 }
@@ -139,19 +142,15 @@ func (c *cluster) ClusterVersionFrom(version, currentVersion *string) types.Stri
139142}
140143
141144func (c * cluster ) HasKubeconfig () bool {
142- return c .Kubeconfig != nil || (c .CloudSettings != nil && c .CloudSettings .BYOK != nil && c .CloudSettings .BYOK .Kubeconfig != nil )
145+ return c .Kubeconfig != nil // || (c.CloudSettings != nil && c.CloudSettings.BYOK != nil && c.CloudSettings.BYOK.Kubeconfig != nil)
143146}
144147
145148func (c * cluster ) GetKubeconfig () * Kubeconfig {
146149 if ! c .HasKubeconfig () {
147150 return nil
148151 }
149152
150- if c .Kubeconfig != nil {
151- return c .Kubeconfig
152- }
153-
154- return c .CloudSettings .BYOK .Kubeconfig
153+ return c .Kubeconfig
155154}
156155
157156type ClusterCloudSettings struct {
0 commit comments