55 "net/http"
66
77 dctapi "github.com/delphix/dct-sdk-go/v14"
8+ "github.com/hashicorp/terraform-plugin-log/tflog"
89 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011)
@@ -148,22 +149,22 @@ func resourceDatabasePostgressqlCreate(ctx context.Context, d *schema.ResourceDa
148149 req := client .SourcesApi .CreatePostgresSource (ctx )
149150
150151 apiRes , httpRes , err := req .PostgresSourceCreateParameters (* sourceCreateParameters ).Execute ()
151- if diags := apiErrorResponseHelper (apiRes , httpRes , err ); diags != nil {
152+ if diags := apiErrorResponseHelper (ctx , apiRes , httpRes , err ); diags != nil {
152153 return diags
153154 }
154155
155156 d .SetId (* apiRes .SourceId )
156157
157158 job_res , job_err := PollJobStatus (* apiRes .Job .Id , ctx , client )
158159 if job_err != "" {
159- ErrorLog . Printf ( "Job Polling failed but continuing with Source creation. Error: %s" , job_err )
160+ tflog . Error ( ctx , DLPX + ERROR + "Job Polling failed but continuing with Source creation. Error: " + job_err )
160161 }
161162
162- InfoLog . Printf ( "Job result is %s" , job_res )
163+ tflog . Info ( ctx , DLPX + INFO + "Job result is " + job_res )
163164
164165 if job_res == Failed || job_res == Canceled || job_res == Abandoned {
165166 d .SetId ("" )
166- ErrorLog . Printf ( "Job %s %s!" , job_res , * apiRes .Job .Id )
167+ tflog . Error ( ctx , DLPX + ERROR + "Job " + job_res + " " + * apiRes .Job .Id )
167168 return diag .Errorf ("[NOT OK] Job %s %s with error %s" , * apiRes .Job .Id , job_res , job_err )
168169 }
169170
@@ -182,20 +183,20 @@ func resourceDatabasePostgressqlRead(ctx context.Context, d *schema.ResourceData
182183
183184 source_id := d .Id ()
184185
185- res , diags := PollForObjectExistence (func () (interface {}, * http.Response , error ) {
186+ res , diags := PollForObjectExistence (ctx , func () (interface {}, * http.Response , error ) {
186187 return client .SourcesApi .GetSourceById (ctx , source_id ).Execute ()
187188 })
188189
189190 if diags != nil {
190- _ , diags := PollForObjectDeletion (func () (interface {}, * http.Response , error ) {
191+ _ , diags := PollForObjectDeletion (ctx , func () (interface {}, * http.Response , error ) {
191192 return client .SourcesApi .GetSourceById (ctx , source_id ).Execute ()
192193 })
193194 // This would imply error in poll for deletion so we just log and exit.
194195 if diags != nil {
195- ErrorLog . Printf ( "Error in polling of source for deletion." )
196+ tflog . Error ( ctx , DLPX + ERROR + "Error in polling of source for deletion." )
196197 } else {
197198 // diags will be nill in case of successful poll for deletion logic aka 404
198- ErrorLog . Printf ( "Error reading the source %s , removing from state." , source_id )
199+ tflog . Error ( ctx , DLPX + ERROR + "Error reading the source " + source_id + " , removing from state." )
199200 d .SetId ("" )
200201 }
201202
@@ -263,7 +264,7 @@ func resourceDatabasePostgressqlUpdate(ctx context.Context, d *schema.ResourceDa
263264
264265 res , httpRes , err := client .SourcesApi .UpdatePostgresSourceById (ctx , d .Get ("id" ).(string )).PostgresSourceUpdateParameters (* updateSourceParam ).Execute ()
265266
266- if diags := apiErrorResponseHelper (nil , httpRes , err ); diags != nil {
267+ if diags := apiErrorResponseHelper (ctx , nil , httpRes , err ); diags != nil {
267268 // revert and set the old value to the changed keys
268269 for _ , key := range changedKeys {
269270 old , _ := d .GetChange (key )
@@ -274,9 +275,9 @@ func resourceDatabasePostgressqlUpdate(ctx context.Context, d *schema.ResourceDa
274275
275276 job_status , job_err := PollJobStatus (* res .Job .Id , ctx , client )
276277 if job_err != "" {
277- WarnLog . Printf ( "Source Update Job Polling failed but continuing with update. Error :%v" , job_err )
278+ tflog . Warn ( ctx , DLPX + WARN + "Source Update Job Polling failed but continuing with update. Error :" + job_err )
278279 }
279- InfoLog . Printf ( "Job result is %s" , job_status )
280+ tflog . Info ( ctx , DLPX + INFO + "Job result is " + job_status )
280281 if isJobTerminalFailure (job_status ) {
281282 return diag .Errorf ("[NOT OK] Source-Update %s. JobId: %s / Error: %s" , job_status , * res .Job .Id , job_err )
282283 }
@@ -291,20 +292,20 @@ func resourceDatabasePostgressqlDelete(ctx context.Context, d *schema.ResourceDa
291292
292293 res , httpRes , err := client .SourcesApi .DeleteSource (ctx , source_id ).Execute ()
293294
294- if diags := apiErrorResponseHelper (res , httpRes , err ); diags != nil {
295+ if diags := apiErrorResponseHelper (ctx , res , httpRes , err ); diags != nil {
295296 return diags
296297 }
297298
298299 job_status , job_err := PollJobStatus (* res .Job .Id , ctx , client )
299300 if job_err != "" {
300- WarnLog . Printf ( "Job Polling failed but continuing with deletion. Error :%v" , job_err )
301+ tflog . Warn ( ctx , DLPX + WARN + "Job Polling failed but continuing with deletion. Error :" + job_err )
301302 }
302- InfoLog . Printf ( " Job result is %s" , job_status )
303+ tflog . Info ( ctx , DLPX + INFO + " Job result is " + job_status )
303304 if isJobTerminalFailure (job_status ) {
304305 return diag .Errorf ("[NOT OK] Source-Delete %s. JobId: %s / Error: %s" , job_status , * res .Job .Id , job_err )
305306 }
306307
307- _ , diags := PollForObjectDeletion (func () (interface {}, * http.Response , error ) {
308+ _ , diags := PollForObjectDeletion (ctx , func () (interface {}, * http.Response , error ) {
308309 return client .SourcesApi .GetSourceById (ctx , source_id ).Execute ()
309310 })
310311
0 commit comments