Skip to content

Commit e49fa7e

Browse files
authored
Fix an issue with kubernetes_node_taint (#2077)
1 parent ded42cd commit e49fa7e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

.changelog/2077.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:bug
2+
`resource/kubernetes_node_taint`: Fix an issue when updating taint does not update the ID in the state file.
3+
4+
```

kubernetes/resource_kubernetes_node_taint.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13-
v1 "k8s.io/api/core/v1"
1413
"k8s.io/apimachinery/pkg/api/errors"
1514
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1615
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1716
"k8s.io/apimachinery/pkg/types"
1817
)
1918

20-
var taintMap = map[string]v1.TaintEffect{
21-
"NoExecute": v1.TaintEffectNoExecute,
22-
"NoSchedule": v1.TaintEffectNoSchedule,
23-
"PreferNoSchedule": v1.TaintEffectPreferNoSchedule,
24-
}
25-
2619
func resourceKubernetesNodeTaint() *schema.Resource {
2720
return &schema.Resource{
2821
CreateContext: resourceKubernetesNodeTaintCreate,
@@ -172,7 +165,8 @@ func resourceKubernetesNodeTaintUpdate(ctx context.Context, d *schema.ResourceDa
172165
FieldManager: d.Get("field_manager").(string),
173166
Force: ptrToBool(d.Get("force").(bool)),
174167
}
175-
if _, err := nodeApi.Patch(ctx, nodeName, types.ApplyPatchType, patchBytes, patchOpts); err != nil {
168+
node, err := nodeApi.Patch(ctx, nodeName, types.ApplyPatchType, patchBytes, patchOpts)
169+
if err != nil {
176170
if errors.IsConflict(err) {
177171
return diag.Diagnostics{{
178172
Severity: diag.Error,
@@ -186,11 +180,12 @@ func resourceKubernetesNodeTaintUpdate(ctx context.Context, d *schema.ResourceDa
186180
if d.Id() == "" {
187181
return nil
188182
}
183+
184+
d.SetId(nodeTaintToId(node.Name, d.Get("taint").([]interface{})))
189185
return resourceKubernetesNodeTaintRead(ctx, d, m)
190186
}
191187

192-
func nodeTaintToId(nodeName string, taints []interface{}) string {
193-
var id string = fmt.Sprintf("%s", nodeName)
188+
func nodeTaintToId(id string, taints []interface{}) string {
194189
for _, t := range taints {
195190
taint := t.(map[string]interface{})
196191
id += fmt.Sprintf(",%s=%s:%s", taint["key"], taint["value"], taint["effect"])

0 commit comments

Comments
 (0)