Skip to content

Commit d3aed19

Browse files
author
Uddipaan Hazarika
committed
404 poll error fix
1 parent 1fa05ac commit d3aed19

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

internal/provider/resource_appdata_dsource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@ func resourceDsourceRead(ctx context.Context, d *schema.ResourceData, meta inter
500500
return client.DSourcesAPI.GetDsourceById(ctx, dsource_id).Execute()
501501
})
502502

503+
if res == nil {
504+
tflog.Error(ctx, DLPX+ERROR+"Dsource not found: "+dsource_id+", removing from state. ")
505+
d.SetId("")
506+
return nil
507+
}
508+
503509
if diags != nil {
504510
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
505511
return client.DSourcesAPI.GetDsourceById(ctx, dsource_id).Execute()

internal/provider/resource_database_postgresql.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ func resourceDatabasePostgressqlRead(ctx context.Context, d *schema.ResourceData
190190
return client.SourcesAPI.GetSourceById(ctx, source_id).Execute()
191191
})
192192

193+
if res == nil {
194+
tflog.Error(ctx, DLPX+ERROR+"PostgreSQL source not found: "+source_id+", removing from state. ")
195+
d.SetId("")
196+
return nil
197+
}
198+
193199
if diags != nil {
194200
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
195201
return client.SourcesAPI.GetSourceById(ctx, source_id).Execute()

internal/provider/resource_environment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta i
419419
return client.EnvironmentsAPI.GetEnvironmentById(ctx, envId).Execute()
420420
})
421421

422+
if apiRes == nil {
423+
tflog.Error(ctx, DLPX+ERROR+"Environment not found: "+envId+", removing from state. ")
424+
d.SetId("")
425+
return nil
426+
}
427+
422428
if diags != nil {
423429
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
424430
return client.EnvironmentsAPI.GetEnvironmentById(ctx, envId).Execute()

internal/provider/resource_vdb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,12 @@ func resourceVdbRead(ctx context.Context, d *schema.ResourceData, meta interface
15361536
return client.VDBsAPI.GetVdbById(ctx, vdbId).Execute()
15371537
})
15381538

1539+
if res == nil {
1540+
tflog.Error(ctx, DLPX+ERROR+"VDB not found: "+vdbId+", removing from state. ")
1541+
d.SetId("")
1542+
return nil
1543+
}
1544+
15391545
if diags != nil {
15401546
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
15411547
return client.VDBsAPI.GetVdbById(ctx, vdbId).Execute()

internal/provider/utility.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ func PollForStatusCode(ctx context.Context, apiCall func() (interface{}, *http.R
8585
var httpRes *http.Response
8686
var err error
8787
for i := 0; maxRetry == 0 || i < maxRetry; i++ {
88-
if res, httpRes, err = apiCall(); httpRes.StatusCode == statusCode {
88+
res, httpRes, err = apiCall()
89+
if httpRes.StatusCode == statusCode {
8990
tflog.Info(ctx, DLPX+INFO+"[OK] Breaking poll - Status "+strconv.Itoa(statusCode)+" reached.")
9091
return res, nil
92+
} else if httpRes.StatusCode == http.StatusNotFound {
93+
tflog.Info(ctx, DLPX+INFO+"[404 Not found] Breaking poll - Status "+strconv.Itoa(statusCode)+" reached.")
94+
break
9195
}
9296
time.Sleep(time.Duration(STATUS_POLL_SLEEP_TIME) * time.Second)
9397
}

0 commit comments

Comments
 (0)