Skip to content

Commit 96c9a85

Browse files
committed
fix: resourceplanmodifiers for kubeconfig resource
Fix resourceplanmodifiers for `talos_cluster_kubeconfig_resource`. Also use pointer to set state everywhere, otherwise the provider shows some weird inconsistencies. Part of: #203 Signed-off-by: Noel Georgi <[email protected]>
1 parent 800573b commit 96c9a85

9 files changed

+22
-10
lines changed

pkg/talos/talos_client_configuration_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (d *talosClientConfigurationDataSource) Read(ctx context.Context, req datas
146146
state.TalosConfig = basetypes.NewStringValue(string(talosConfigStringBytes))
147147
state.ID = state.ClusterName
148148

149-
diags = resp.State.Set(ctx, state)
149+
diags = resp.State.Set(ctx, &state)
150150
resp.Diagnostics.Append(diags...)
151151

152152
if resp.Diagnostics.HasError() {

pkg/talos/talos_cluster_health_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (d *talosClusterHealthDataSource) Read(ctx context.Context, req datasource.
264264

265265
state.ID = basetypes.NewStringValue("cluster_health")
266266

267-
resp.Diagnostics.Append(resp.State.Set(ctx, state)...)
267+
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
268268

269269
if resp.Diagnostics.HasError() {
270270
return

pkg/talos/talos_cluster_kubeconfig_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (d *talosClusterKubeConfigDataSource) Read(ctx context.Context, req datasou
214214

215215
state.ID = basetypes.NewStringValue(clusterName)
216216

217-
diags = resp.State.Set(ctx, state)
217+
diags = resp.State.Set(ctx, &state)
218218
resp.Diagnostics.Append(diags...)
219219

220220
if resp.Diagnostics.HasError() {

pkg/talos/talos_cluster_kubeconfig_resource.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import (
1414
"github.com/hashicorp/terraform-plugin-framework/path"
1515
"github.com/hashicorp/terraform-plugin-framework/resource"
1616
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
17+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
18+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
19+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1720
"github.com/hashicorp/terraform-plugin-framework/types"
1821
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1922
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -63,6 +66,9 @@ func (r *talosClusterKubeConfigResource) Schema(ctx context.Context, _ resource.
6366
Attributes: map[string]schema.Attribute{
6467
"id": schema.StringAttribute{
6568
Computed: true,
69+
PlanModifiers: []planmodifier.String{
70+
stringplanmodifier.UseStateForUnknown(),
71+
},
6672
},
6773
"node": schema.StringAttribute{
6874
Required: true,
@@ -96,6 +102,9 @@ func (r *talosClusterKubeConfigResource) Schema(ctx context.Context, _ resource.
96102
Computed: true,
97103
Description: "The raw kubeconfig",
98104
Sensitive: true,
105+
PlanModifiers: []planmodifier.String{
106+
stringplanmodifier.UseStateForUnknown(),
107+
},
99108
},
100109
"kubernetes_client_configuration": schema.SingleNestedAttribute{
101110
Attributes: map[string]schema.Attribute{
@@ -119,6 +128,9 @@ func (r *talosClusterKubeConfigResource) Schema(ctx context.Context, _ resource.
119128
},
120129
Computed: true,
121130
Description: "The kubernetes client configuration",
131+
PlanModifiers: []planmodifier.Object{
132+
objectplanmodifier.UseStateForUnknown(),
133+
},
122134
},
123135
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{
124136
Create: true,
@@ -222,7 +234,7 @@ func (r *talosClusterKubeConfigResource) Create(ctx context.Context, req resourc
222234

223235
state.ID = basetypes.NewStringValue(clusterName)
224236

225-
diags = resp.State.Set(ctx, state)
237+
diags = resp.State.Set(ctx, &state)
226238
resp.Diagnostics.Append(diags...)
227239

228240
if resp.Diagnostics.HasError() {

pkg/talos/talos_machine_bootstrap_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (r *talosMachineBootstrapResource) UpgradeState(_ context.Context) map[int6
307307
}
308308

309309
// Set state to fully populated data
310-
diags = resp.State.Set(ctx, state)
310+
diags = resp.State.Set(ctx, &state)
311311
resp.Diagnostics.Append(diags...)
312312
if resp.Diagnostics.HasError() {
313313
return

pkg/talos/talos_machine_configuration_apply_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (p *talosMachineConfigurationApplyResource) UpgradeState(_ context.Context)
621621
}
622622

623623
// Set state to fully populated data
624-
diags = resp.State.Set(ctx, state)
624+
diags = resp.State.Set(ctx, &state)
625625
resp.Diagnostics.Append(diags...)
626626
if resp.Diagnostics.HasError() {
627627
return

pkg/talos/talos_machine_configuration_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (d *talosMachineConfigurationDataSource) Read(ctx context.Context, req data
278278
state.MachineConfiguration = basetypes.NewStringValue(machineConfiguration)
279279
state.ID = state.ClusterName
280280

281-
diags = resp.State.Set(ctx, state)
281+
diags = resp.State.Set(ctx, &state)
282282
resp.Diagnostics.Append(diags...)
283283

284284
if resp.Diagnostics.HasError() {

pkg/talos/talos_machine_disks_data_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (d *talosMachineDisksDataSource) Read(ctx context.Context, req datasource.R
422422

423423
state.ID = basetypes.NewStringValue("machine_disks")
424424

425-
diags = resp.State.Set(ctx, state)
425+
diags = resp.State.Set(ctx, &state)
426426
resp.Diagnostics.Append(diags...)
427427

428428
if resp.Diagnostics.HasError() {

pkg/talos/talos_machine_secrets_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ func (r *talosMachineSecretsResource) UpgradeState(_ context.Context) map[int64]
585585
}
586586

587587
// Set state to fully populated data
588-
diags = resp.State.Set(ctx, state)
588+
diags = resp.State.Set(ctx, &state)
589589
resp.Diagnostics.Append(diags...)
590590
if resp.Diagnostics.HasError() {
591591
return
@@ -632,7 +632,7 @@ func (r *talosMachineSecretsResource) ImportState(ctx context.Context, req resou
632632
}
633633

634634
// Set state to fully populated data
635-
diags := resp.State.Set(ctx, state)
635+
diags := resp.State.Set(ctx, &state)
636636
resp.Diagnostics.Append(diags...)
637637

638638
if resp.Diagnostics.HasError() {

0 commit comments

Comments
 (0)