Skip to content

Commit 1715254

Browse files
committed
unify log and id setting
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
1 parent 5360c02 commit 1715254

6 files changed

Lines changed: 21 additions & 14 deletions

File tree

provider/resource_branch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ func resourceBranchImport(ctx context.Context, d *schema.ResourceData, meta inte
270270
}
271271

272272
if diags := projectReadiness.Retry(resourceBranchRead, ctx, d, meta); diags.HasError() {
273+
d.SetId("")
273274
return nil, errors.New(diags[0].Summary)
274275
}
275276
return []*schema.ResourceData{d}, nil

provider/resource_database.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,12 @@ func resourceDatabaseReadRetry(ctx context.Context, d *schema.ResourceData, meta
9393
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
9494
tflog.Debug(ctx, "database not found, removing from state",
9595
map[string]interface{}{
96-
"project_id": d.Get("project_id"),
97-
"branch_id": d.Get("branch_id"),
98-
"database_id": d.Id(),
96+
"id": d.Id(),
97+
"project_id": d.Get("project_id"),
98+
"branch_id": d.Get("branch_id"),
9999
})
100100
d.SetId("")
101-
tflog.Debug(ctx, "recreating database", map[string]interface{}{
102-
"project_id": d.Get("project_id"), "branch_id": d.Get("branch_id"),
103-
})
104-
return resourceDatabaseCreate(ctx, d, meta)
101+
return nil
105102
}})
106103
}
107104

@@ -152,9 +149,11 @@ func resourceDatabaseUpdate(ctx context.Context, d *schema.ResourceData, meta in
152149
func resourceDatabaseDeleteRetry(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
153150
return projectReadiness.RetryWithFallback(resourceDatabaseDelete, ctx, d, meta, map[int]FallbackFn{
154151
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
152+
d.SetId("")
155153
return nil
156154
},
157155
http.StatusUnprocessableEntity: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
156+
d.SetId("")
158157
return nil
159158
},
160159
})

provider/resource_endpoint.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ func resourceEndpointReadRetry(ctx context.Context, d *schema.ResourceData, meta
240240
map[int]FallbackFn{
241241
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
242242
tflog.Debug(ctx, "endpoint not found, removing from state",
243-
map[string]interface{}{"endpoint_id": d.Id()})
243+
map[string]interface{}{
244+
"id": d.Id(),
245+
"project_id": d.Get("project_id"),
246+
"branch_id": d.Get("branch_id"),
247+
})
244248
d.SetId("")
245249
return nil
246250
}})
@@ -313,6 +317,7 @@ func resourceEndpointImport(ctx context.Context, d *schema.ResourceData, meta in
313317
return nil, err
314318
}
315319
if diags := projectReadiness.Retry(resourceEndpointRead, ctx, d, meta); diags.HasError() {
320+
d.SetId("")
316321
return nil, errors.New(diags[0].Summary)
317322
}
318323
return []*schema.ResourceData{d}, nil

provider/resource_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ func resourceProjectReadRetry(ctx context.Context, d *schema.ResourceData, meta
10551055
return projectReadiness.RetryWithFallback(resourceProjectRead, ctx, d, meta, map[int]FallbackFn{
10561056
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
10571057
tflog.Debug(ctx, "project not found, deleting from the state",
1058-
map[string]interface{}{"project_id": d.Id()})
1058+
map[string]interface{}{"id": d.Id()})
10591059
d.SetId("")
10601060
return nil
10611061
}})

provider/resource_role.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ func resourceRoleReadRetry(ctx context.Context, d *schema.ResourceData, meta int
115115
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
116116
tflog.Debug(ctx, "role not found, removing from state",
117117
map[string]interface{}{
118-
"project_id": d.Get("project_id"), "branch_id": d.Get("project_id"),
119-
"name": d.Get("name"),
118+
"name": d.Get("name"),
119+
"project_id": d.Get("project_id"),
120+
"branch_id": d.Get("project_id"),
120121
})
121122
d.SetId("")
122123
return nil
@@ -194,6 +195,7 @@ func resourceRoleImport(ctx context.Context, d *schema.ResourceData, meta interf
194195

195196
setResourceAttrsFromComplexID(d, r)
196197
if diags := projectReadiness.Retry(resourceRoleRead, ctx, d, meta); diags.HasError() {
198+
d.SetId("")
197199
return nil, errors.New(diags[0].Summary)
198200
}
199201
return []*schema.ResourceData{d}, nil

provider/resource_vpc_endpoint_assignment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ func resourceVPCEndpointAssignmentReadRetry(ctx context.Context, d *schema.Resou
100100
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
101101
tflog.Debug(ctx, "VPC endpoint assignment not found, removing from state",
102102
map[string]interface{}{
103-
"org_id": d.Get("org_id"),
104-
"region_id": d.Get("region_id"),
105-
"vpc_endpoint_id": d.Get("vpc_endpoint_id"),
103+
"id": d.Get("vpc_endpoint_id"),
104+
"org_id": d.Get("org_id"),
105+
"region_id": d.Get("region_id"),
106106
})
107107
d.SetId("")
108108
return nil

0 commit comments

Comments
 (0)