@@ -3,8 +3,8 @@ package provider
33import (
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
0 commit comments