Skip to content

Commit 810f10d

Browse files
committed
DLPXECO-13068 Allow silent migration of toolkit_path for environments created before v4.0.0
1 parent 51ab348 commit 810f10d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

internal/provider/commons.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ var updatableEnvKeys = map[string]bool{
124124
"description": true,
125125
"tags": true,
126126
"hosts": true,
127+
"toolkit_path": true,
127128
"ignore_tag_changes": true,
128129
}
129130

@@ -136,6 +137,7 @@ var isDestructiveEnvUpdate = map[string]bool{
136137
"description": false,
137138
"tags": false,
138139
"hosts": true,
140+
"toolkit_path": false,
139141
"ignore_tag_changes": false,
140142
}
141143

internal/provider/resource_environment.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ func resourceEnvironment() *schema.Resource {
5656
"toolkit_path": {
5757
Type: schema.TypeString,
5858
Optional: true,
59+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
60+
// Suppress diff when transitioning from any value to empty/null
61+
// This allows silent migration from top-level toolkit_path to hosts.toolkit_path
62+
if new == "" || new == "null" {
63+
return true
64+
}
65+
// Suppress diff if both old and new are empty/null
66+
return (old == "" || old == "null") && (new == "" || new == "null")
67+
},
5968
},
6069
"username": {
6170
Type: schema.TypeString,
@@ -204,6 +213,17 @@ func resourceEnvironment() *schema.Resource {
204213
Type: schema.TypeBool,
205214
Default: true,
206215
Optional: true,
216+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
217+
// Don't suppress if user explicitly changed the value in their config
218+
rawConfig := d.GetRawConfig()
219+
if rawConfig.IsKnown() && !rawConfig.IsNull() {
220+
ignoreTagChangesAttr := rawConfig.GetAttr("ignore_tag_changes")
221+
if (ignoreTagChangesAttr.IsNull() || !ignoreTagChangesAttr.IsKnown()) && new == "true" && (old == "" || old == "null" || old == "<null>") {
222+
return true
223+
}
224+
}
225+
return false
226+
},
207227
},
208228
"tags": {
209229
Type: schema.TypeList,
@@ -562,6 +582,18 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i
562582
// its an import or upgrade, set to default value
563583
d.Set("os_type", "UNIX")
564584
}
585+
586+
// This handles import scenario where parameter is not in config
587+
rawConfig := d.GetRawConfig()
588+
if rawConfig.IsKnown() && !rawConfig.IsNull() {
589+
ignoreTagChangesAttr := rawConfig.GetAttr("ignore_tag_changes")
590+
if ignoreTagChangesAttr.IsNull() || !ignoreTagChangesAttr.IsKnown() {
591+
// Parameter not in config (import scenario) - set default
592+
d.Set("ignore_tag_changes", true)
593+
}
594+
} else {
595+
d.Set("ignore_tag_changes", true)
596+
}
565597

566598
envRes, _ := apiRes.(*dctapi.Environment)
567599
//d.SetId(envRes.GetId())

0 commit comments

Comments
 (0)