Skip to content

Commit cdddead

Browse files
author
Uddipaan Hazarika
committed
tag update failure fix
1 parent e130268 commit cdddead

File tree

7 files changed

+262
-239
lines changed

7 files changed

+262
-239
lines changed

internal/provider/commons.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var updatableVdbKeys = map[string]bool{
5252
"mount_point": true,
5353
"tags": true,
5454
"database_name": true,
55+
"ignore_tag_changes": true,
5556
}
5657

5758
var isDestructiveVdbUpdate = map[string]bool{
@@ -89,6 +90,7 @@ var isDestructiveVdbUpdate = map[string]bool{
8990
"new_dbid": false,
9091
"mount_point": true,
9192
"tags": false,
93+
"ignore_tag_changes": false,
9294
}
9395

9496
var updatableOracleDsourceKeys = map[string]bool{
@@ -109,28 +111,31 @@ var updatableOracleDsourceKeys = map[string]bool{
109111
"ops_pre_sync": true,
110112
"ops_pre_log_sync": true,
111113
"ops_post_sync": true,
114+
"ignore_tag_changes": true,
112115
}
113116

114117
var updatableEnvKeys = map[string]bool{
115-
"name": true,
116-
"cluster_home": true,
117-
"connector_port": true,
118-
"username": true,
119-
"password": true,
120-
"description": true,
121-
"tags": true,
122-
"hosts": true,
118+
"name": true,
119+
"cluster_home": true,
120+
"connector_port": true,
121+
"username": true,
122+
"password": true,
123+
"description": true,
124+
"tags": true,
125+
"hosts": true,
126+
"ignore_tag_changes": true,
123127
}
124128

125129
var isDestructiveEnvUpdate = map[string]bool{
126-
"name": false,
127-
"cluster_home": true,
128-
"connector_port": true,
129-
"username": true,
130-
"password": true,
131-
"description": false,
132-
"tags": false,
133-
"hosts": true,
130+
"name": false,
131+
"cluster_home": true,
132+
"connector_port": true,
133+
"username": true,
134+
"password": true,
135+
"description": false,
136+
"tags": false,
137+
"hosts": true,
138+
"ignore_tag_changes": false,
134139
}
135140

136141
var updatableAppdataDsourceKeys = map[string]bool{
@@ -145,4 +150,5 @@ var updatableAppdataDsourceKeys = map[string]bool{
145150
"ops_pre_sync": true,
146151
"ops_post_sync": true,
147152
"tags": true,
153+
"ignore_tag_changes": true,
148154
}

internal/provider/resource_appdata_dsource.go

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package provider
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
76
"net/http"
7+
"reflect"
88
"strings"
99

1010
dctapi "github.com/delphix/dct-sdk-go/v25"
@@ -87,12 +87,6 @@ func resourceAppdataDsource() *schema.Resource {
8787
Type: schema.TypeBool,
8888
Default: true,
8989
Optional: true,
90-
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
91-
if old != new {
92-
tflog.Info(context.Background(), "updating ignore_tag_changes is not allowed. plan changes are suppressed")
93-
}
94-
return d.Id() != ""
95-
},
9690
},
9791
"tags": {
9892
Type: schema.TypeList,
@@ -110,14 +104,11 @@ func resourceAppdataDsource() *schema.Resource {
110104
},
111105
},
112106
},
113-
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
114-
ignore_tag_changes, _ := d.GetOk("ignore_tag_changes")
115-
if ignore_tag_changes.(bool) {
107+
DiffSuppressFunc: func(_, old, new string, d *schema.ResourceData) bool {
108+
if ignore, ok := d.GetOk("ignore_tag_changes"); ok && ignore.(bool) {
116109
return true
117-
} else {
118-
tflog.Debug(context.Background(), fmt.Sprintf("\n [DEBUG] tag changes suppressed : %v", ignore_tag_changes))
119-
return false
120110
}
111+
return false
121112
},
122113
},
123114
"ops_pre_sync": {
@@ -697,35 +688,38 @@ func resourceDsourceUpdate(ctx context.Context, d *schema.ResourceData, meta int
697688
updateAppdataDsource.SetOpsPostSync([]dctapi.SourceOperation{})
698689
}
699690
}
691+
// check if the updateAppdataDsource is not empty
692+
if !isStructEmpty(updateAppdataDsource) {
693+
tflog.Debug(ctx, "updating appdata dsource")
694+
res, httpRes, err := client.DSourcesAPI.UpdateAppdataDsourceById(ctx, dsourceId).UpdateAppDataDSourceParameters(*updateAppdataDsource).Execute()
700695

701-
res, httpRes, err := client.DSourcesAPI.UpdateAppdataDsourceById(ctx, dsourceId).UpdateAppDataDSourceParameters(*updateAppdataDsource).Execute()
702-
703-
if diags := apiErrorResponseHelper(ctx, nil, httpRes, err); diags != nil {
704-
// revert and set the old value to the changed keys
705-
revertChanges(d, changedKeys)
706-
return diags
707-
}
708-
709-
if res != nil {
710-
job_status, job_err := PollJobStatus(res.Job.GetId(), ctx, client)
711-
if job_err != "" {
712-
tflog.Warn(ctx, DLPX+WARN+"Appdata Dsource Update Job Polling failed but continuing with update. Error: "+job_err)
696+
if diags := apiErrorResponseHelper(ctx, nil, httpRes, err); diags != nil {
697+
// revert and set the old value to the changed keys
698+
revertChanges(d, changedKeys)
699+
return diags
713700
}
714-
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_status)
715-
if isJobTerminalFailure(job_status) {
716-
return diag.Errorf("[NOT OK] Appdata Dsource Update %s. JobId: %s / Error: %s", job_status, res.Job.GetId(), job_err)
701+
702+
if res != nil {
703+
job_status, job_err := PollJobStatus(res.Job.GetId(), ctx, client)
704+
if job_err != "" {
705+
tflog.Warn(ctx, DLPX+WARN+"Appdata Dsource Update Job Polling failed but continuing with update. Error: "+job_err)
706+
}
707+
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_status)
708+
if isJobTerminalFailure(job_status) {
709+
return diag.Errorf("[NOT OK] Appdata Dsource Update %s. JobId: %s / Error: %s", job_status, res.Job.GetId(), job_err)
710+
}
717711
}
718712
}
719-
if d.HasChanges(
720-
"tags",
721-
) { // tags update
722-
tflog.Debug(ctx, "updating tags")
723-
if d.HasChange("tags") {
713+
714+
// update tags
715+
if !d.Get("ignore_tag_changes").(bool) {
716+
oldTags, newTags := d.GetChange("tags")
717+
if !reflect.DeepEqual(oldTags, newTags) {
718+
tflog.Debug(ctx, "updating tags")
724719
// delete old tag
725720
tflog.Debug(ctx, "deleting old tags")
726-
oldTag, newTag := d.GetChange("tags")
727-
if len(toTagArray(oldTag)) != 0 {
728-
tflog.Debug(ctx, "tag to be deleted: "+toTagArray(oldTag)[0].GetKey()+" "+toTagArray(oldTag)[0].GetValue())
721+
if len(toTagArray(oldTags)) != 0 {
722+
tflog.Debug(ctx, "tag to be deleted: "+toTagArray(oldTags)[0].GetKey()+" "+toTagArray(oldTags)[0].GetValue())
729723
deleteTag := *dctapi.NewDeleteTag()
730724
tagDelResp, tagDelErr := client.DSourcesAPI.DeleteTagsDsource(ctx, dsourceId).DeleteTag(deleteTag).Execute()
731725
if diags := apiErrorResponseHelper(ctx, nil, tagDelResp, tagDelErr); diags != nil {
@@ -734,9 +728,9 @@ func resourceDsourceUpdate(ctx context.Context, d *schema.ResourceData, meta int
734728
}
735729
}
736730
// create tag
737-
if len(toTagArray(newTag)) != 0 {
731+
if len(toTagArray(newTags)) != 0 {
738732
tflog.Info(ctx, "creating new tags")
739-
_, httpResp, tagCrtErr := client.DSourcesAPI.CreateTagsDsource(ctx, dsourceId).TagsRequest(*dctapi.NewTagsRequest(toTagArray(newTag))).Execute()
733+
_, httpResp, tagCrtErr := client.DSourcesAPI.CreateTagsDsource(ctx, dsourceId).TagsRequest(*dctapi.NewTagsRequest(toTagArray(newTags))).Execute()
740734
if diags := apiErrorResponseHelper(ctx, nil, httpResp, tagCrtErr); diags != nil {
741735
revertChanges(d, changedKeys)
742736
return diags

internal/provider/resource_database_postgresql.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func resourceSource() *schema.Resource {
111111
"tags": {
112112
Type: schema.TypeList,
113113
Optional: true,
114+
Computed: true,
114115
Elem: &schema.Resource{
115116
Schema: map[string]*schema.Schema{
116117
"key": {
@@ -123,6 +124,12 @@ func resourceSource() *schema.Resource {
123124
},
124125
},
125126
},
127+
DiffSuppressFunc: func(_, old, new string, d *schema.ResourceData) bool {
128+
if ignore, ok := d.GetOk("ignore_tag_changes"); ok && ignore.(bool) {
129+
return true
130+
}
131+
return false
132+
},
126133
},
127134
},
128135
Importer: &schema.ResourceImporter{

0 commit comments

Comments
 (0)