Skip to content

Commit f334216

Browse files
logging changes
1 parent 90f4dd1 commit f334216

File tree

8 files changed

+108
-96
lines changed

8 files changed

+108
-96
lines changed

internal/provider/commons.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ const (
1010
Abandoned string = "ABANDONED"
1111
JOB_STATUS_SLEEP_TIME int = 5
1212
STATUS_POLL_SLEEP_TIME int = 20
13+
DLPX string = "[DELPHIX] "
14+
INFO string = "[INFO] "
15+
WARN string = "[WARN] "
16+
ERROR string = "[ERROR] "
1317
)

internal/provider/resource_appdata_dsource.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77

88
dctapi "github.com/delphix/dct-sdk-go/v14"
9+
"github.com/hashicorp/terraform-plugin-log/tflog"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1112
)
@@ -463,22 +464,22 @@ func resourceAppdataDsourceCreate(ctx context.Context, d *schema.ResourceData, m
463464
req := client.DSourcesApi.LinkAppdataDatabase(ctx)
464465

465466
apiRes, httpRes, err := req.AppDataDSourceLinkSourceParameters(*appDataDSourceLinkSourceParameters).Execute()
466-
if diags := apiErrorResponseHelper(apiRes, httpRes, err); diags != nil {
467+
if diags := apiErrorResponseHelper(ctx, apiRes, httpRes, err); diags != nil {
467468
return diags
468469
}
469470

470471
d.SetId(*apiRes.DsourceId)
471472

472473
job_res, job_err := PollJobStatus(*apiRes.Job.Id, ctx, client)
473474
if job_err != "" {
474-
ErrorLog.Printf("Job Polling failed but continuing with dSource creation. Error: %s", job_err)
475+
tflog.Error(ctx, DLPX+ERROR+"Job Polling failed but continuing with dSource creation. Error: "+job_err)
475476
}
476477

477-
InfoLog.Printf("Job result is %s", job_res)
478+
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_res)
478479

479480
if job_res == Failed || job_res == Canceled || job_res == Abandoned {
480481
d.SetId("")
481-
ErrorLog.Printf("Job %s %s!", job_res, *apiRes.Job.Id)
482+
tflog.Error(ctx, DLPX+ERROR+"Job "+job_res+" "+*apiRes.Job.Id+"!")
482483
return diag.Errorf("[NOT OK] Job %s %s with error %s", *apiRes.Job.Id, job_res, job_err)
483484
}
484485

@@ -499,20 +500,20 @@ func resourceDsourceRead(ctx context.Context, d *schema.ResourceData, meta inter
499500

500501
dsource_id := d.Id()
501502

502-
res, diags := PollForObjectExistence(func() (interface{}, *http.Response, error) {
503+
res, diags := PollForObjectExistence(ctx, func() (interface{}, *http.Response, error) {
503504
return client.DSourcesApi.GetDsourceById(ctx, dsource_id).Execute()
504505
})
505506

506507
if diags != nil {
507-
_, diags := PollForObjectDeletion(func() (interface{}, *http.Response, error) {
508+
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
508509
return client.DSourcesApi.GetDsourceById(ctx, dsource_id).Execute()
509510
})
510511
// This would imply error in poll for deletion so we just log and exit.
511512
if diags != nil {
512-
ErrorLog.Printf("Error in polling of dSource for deletion.")
513+
tflog.Error(ctx, DLPX+ERROR+"Error in polling of dSource for deletion.")
513514
} else {
514515
// diags will be nil in case of successful poll for deletion logic aka 404
515-
ErrorLog.Printf("Error reading the dSource %s, removing from state.", dsource_id)
516+
tflog.Error(ctx, DLPX+ERROR+"Error reading the dSource "+dsource_id+", removing from state.")
516517
d.SetId("")
517518
}
518519

@@ -570,20 +571,20 @@ func resourceDsourceDelete(ctx context.Context, d *schema.ResourceData, meta int
570571

571572
res, httpRes, err := client.DSourcesApi.DeleteDsource(ctx).DeleteDSourceRequest(*deleteDsourceParams).Execute()
572573

573-
if diags := apiErrorResponseHelper(res, httpRes, err); diags != nil {
574+
if diags := apiErrorResponseHelper(ctx, res, httpRes, err); diags != nil {
574575
return diags
575576
}
576577

577578
job_status, job_err := PollJobStatus(*res.Id, ctx, client)
578579
if job_err != "" {
579-
WarnLog.Printf("Job Polling failed but continuing with deletion. Error :%v", job_err)
580+
tflog.Warn(ctx, DLPX+WARN+"Job Polling failed but continuing with deletion. Error :"+job_err)
580581
}
581-
InfoLog.Printf("Job result is %s", job_status)
582+
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_status)
582583
if isJobTerminalFailure(job_status) {
583584
return diag.Errorf("[NOT OK] dSource-Delete %s. JobId: %s / Error: %s", job_status, *res.Id, job_err)
584585
}
585586

586-
_, diags := PollForObjectDeletion(func() (interface{}, *http.Response, error) {
587+
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
587588
return client.DSourcesApi.GetDsourceById(ctx, dsourceId).Execute()
588589
})
589590

internal/provider/resource_database_postgresql.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
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

internal/provider/resource_environment.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"github.com/hashicorp/terraform-plugin-log/tflog"
56
"net/http"
67

78
dctapi "github.com/delphix/dct-sdk-go/v14"
@@ -386,15 +387,15 @@ func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta
386387
apiReq := client.EnvironmentsApi.CreateEnvironment(ctx)
387388
apiRes, httpRes, err := apiReq.EnvironmentCreateParameters(*createEnvParams).Execute()
388389

389-
if diags := apiErrorResponseHelper(apiRes, httpRes, err); diags != nil {
390+
if diags := apiErrorResponseHelper(ctx, apiRes, httpRes, err); diags != nil {
390391
return diags
391392
}
392393

393394
d.SetId(apiRes.GetEnvironmentId())
394395
job_status, job_err := PollJobStatus(*apiRes.Job.Id, ctx, client)
395396

396397
if job_err != "" {
397-
ErrorLog.Printf("Job Polling failed but continuing with env creation. Error: %v", job_err)
398+
tflog.Error(ctx, DLPX+ERROR+"Job Polling failed but continuing with env creation. Error: "+job_err)
398399
}
399400

400401
if isJobTerminalFailure(job_status) {
@@ -413,18 +414,18 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i
413414
client := meta.(*apiClient).client
414415
envId := d.Id()
415416

416-
apiRes, diags := PollForObjectExistence(func() (interface{}, *http.Response, error) {
417+
apiRes, diags := PollForObjectExistence(ctx, func() (interface{}, *http.Response, error) {
417418
return client.EnvironmentsApi.GetEnvironmentById(ctx, envId).Execute()
418419
})
419420

420421
if diags != nil {
421-
_, diags := PollForObjectDeletion(func() (interface{}, *http.Response, error) {
422+
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
422423
return client.EnvironmentsApi.GetEnvironmentById(ctx, envId).Execute()
423424
})
424425
if diags != nil {
425-
ErrorLog.Printf("Error in polling of environment for deletion.")
426+
tflog.Error(ctx, DLPX+ERROR+"Error in polling of environment for deletion.")
426427
} else {
427-
ErrorLog.Printf("Error Env-Read failed for EnvId:%s. Removing from state file.", envId)
428+
tflog.Error(ctx, DLPX+ERROR+"Error Env-Read failed for EnvId: "+envId+". Removing from state file.")
428429
d.SetId("")
429430
}
430431
return nil
@@ -439,7 +440,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i
439440
}
440441

441442
func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
442-
InfoLog.Printf("Not Implemented: resourceEnvironmentUpdate")
443+
tflog.Info(ctx, DLPX+INFO+"Not Implemented: resourceEnvironmentUpdate")
443444
var diags diag.Diagnostics
444445
return diags
445446
}
@@ -451,18 +452,18 @@ func resourceEnvironmentDelete(ctx context.Context, d *schema.ResourceData, meta
451452

452453
apiRes, httpRes, err := client.EnvironmentsApi.DeleteEnvironment(ctx, envId).Execute()
453454

454-
if diags := apiErrorResponseHelper(apiRes, httpRes, err); diags != nil {
455+
if diags := apiErrorResponseHelper(ctx, apiRes, httpRes, err); diags != nil {
455456
return diags
456457
}
457458

458459
job_status, job_err := PollJobStatus(*apiRes.Job.Id, ctx, client)
459460
if job_err != "" {
460-
ErrorLog.Printf("Job Polling failed but continuing with env deletion. Error: %v", job_err)
461+
tflog.Error(ctx, DLPX+ERROR+"Job Polling failed but continuing with env deletion. Error: "+job_err)
461462
}
462463
if isJobTerminalFailure(job_status) {
463464
return diag.Errorf("[NOT OK] Env-Delete %s. JobId: %s / Error: %s", job_status, *apiRes.Job.Id, job_err)
464465
}
465-
_, diags := PollForObjectDeletion(func() (interface{}, *http.Response, error) {
466+
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
466467
return client.EnvironmentsApi.GetEnvironmentById(ctx, envId).Execute()
467468
})
468469

internal/provider/resource_oracle_dsource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"github.com/hashicorp/terraform-plugin-log/tflog"
56

67
dctapi "github.com/delphix/dct-sdk-go/v14"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -716,22 +717,22 @@ func resourceOracleDsourceCreate(ctx context.Context, d *schema.ResourceData, me
716717
req := client.DSourcesApi.LinkOracleDatabase(ctx)
717718

718719
apiRes, httpRes, err := req.OracleDSourceLinkSourceParameters(*oracleDSourceLinkSourceParameters).Execute()
719-
if diags := apiErrorResponseHelper(apiRes, httpRes, err); diags != nil {
720+
if diags := apiErrorResponseHelper(ctx, apiRes, httpRes, err); diags != nil {
720721
return diags
721722
}
722723

723724
d.SetId(*apiRes.DsourceId)
724725

725726
job_res, job_err := PollJobStatus(*apiRes.Job.Id, ctx, client)
726727
if job_err != "" {
727-
ErrorLog.Printf("Job Polling failed but continuing with dSource creation. Error: %s", job_err)
728+
tflog.Error(ctx, DLPX+ERROR+"Job Polling failed but continuing with dSource creation. Error: "+job_err)
728729
}
729730

730-
InfoLog.Printf("Job result is %s", job_res)
731+
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_res)
731732

732733
if job_res == Failed || job_res == Canceled || job_res == Abandoned {
733734
d.SetId("")
734-
ErrorLog.Printf("Job %s %s!", job_res, *apiRes.Job.Id)
735+
tflog.Error(ctx, DLPX+ERROR+"Job "+job_res+" "+*apiRes.Job.Id+"!")
735736
return diag.Errorf("[NOT OK] Job %s %s with error %s", *apiRes.Job.Id, job_res, job_err)
736737
}
737738

0 commit comments

Comments
 (0)