Skip to content

Commit 90590f1

Browse files
committed
add VPC endpoints restriction's FSM logic to cover the resource deletion outside terraform
Signed-off-by: Dmitry Kisler <admin@dkisler.com> #209
1 parent 54b9c65 commit 90590f1

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

provider/resource_vpc_endpoint_restriction.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package provider
33
import (
44
"context"
55
"fmt"
6+
"net/http"
67
"strings"
78

9+
"github.com/hashicorp/terraform-plugin-log/tflog"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1012
neon "github.com/kislerdm/neon-sdk-go"
@@ -115,11 +117,29 @@ func resourceVPCEndpointRestrictionCreateRetry(ctx context.Context, d *schema.Re
115117
}
116118

117119
func resourceVPCEndpointRestrictionReadRetry(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
118-
return projectReadiness.Retry(resourceVPCEndpointRestrictionRead, ctx, d, meta)
120+
return projectReadiness.RetryWithFallback(resourceVPCEndpointRestrictionRead, ctx, d, meta, map[int]FallbackFn{
121+
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
122+
tflog.Debug(ctx, "VPC endpoint's restriction not found, removing from state",
123+
map[string]interface{}{
124+
"project_id": d.Get("project_id"),
125+
"vpc_endpoint_id": d.Get("vpc_endpoint_id"),
126+
})
127+
d.SetId("")
128+
return nil
129+
}})
119130
}
120131

121132
func resourceVPCEndpointRestrictionDeleteRetry(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
122-
return projectReadiness.Retry(resourceVPCEndpointRestrictionDelete, ctx, d, meta)
133+
return projectReadiness.RetryWithFallback(resourceVPCEndpointRestrictionDelete, ctx, d, meta, map[int]FallbackFn{
134+
http.StatusNotFound: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
135+
d.SetId("")
136+
return nil
137+
},
138+
http.StatusUnprocessableEntity: func(ctx context.Context, d *schema.ResourceData, meta interface{}) error {
139+
d.SetId("")
140+
return nil
141+
},
142+
})
123143
}
124144

125145
func resourceVPCEndpointRestrictionImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {

0 commit comments

Comments
 (0)