@@ -66,6 +66,23 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource
66
66
config := m .(authctx.TanzuContext )
67
67
68
68
err := populateDataFromServer (ctx , config , scopedFullnameData , data )
69
+ if err != nil {
70
+ if clienterrors .IsNotFoundError (err ) {
71
+ if ! helper .IsContextCallerSet (ctx ) {
72
+ * data = schema.ResourceData {}
73
+
74
+ return diags
75
+ } else if helper .IsDeleteState (ctx ) {
76
+ // d.SetId("") is automatically called assuming delete returns no errors, but
77
+ // it is added here for explicitness.
78
+ _ = schema .RemoveFromState (data , m )
79
+
80
+ return diags
81
+ }
82
+ }
83
+
84
+ return diag .FromErr (err )
85
+ }
69
86
70
87
// remove the existing cluster level resource from state if it is now
71
88
// managed at the cluster group level.
@@ -83,22 +100,6 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource
83
100
}
84
101
}
85
102
86
- if err != nil {
87
- if clienterrors .IsNotFoundError (err ) {
88
- if ! helper .IsContextCallerSet (ctx ) {
89
- * data = schema.ResourceData {}
90
-
91
- return diags
92
- } else if helper .IsDeleteState (ctx ) {
93
- // d.SetId("") is automatically called assuming delete returns no errors, but
94
- // it is added here for explicitness.
95
- _ = schema .RemoveFromState (data , m )
96
-
97
- return diags
98
- }
99
- }
100
- }
101
-
102
103
return diags
103
104
}
104
105
@@ -228,6 +229,10 @@ func populateDataFromServer(ctx context.Context, config authctx.TanzuContext, sc
228
229
229
230
resp , err := config .TMCConnection .DataProtectionService .DataProtectionResourceServiceList (scopedFullnameData .FullnameCluster )
230
231
if err != nil || resp == nil {
232
+ if clienterrors .IsUnauthorizedError (err ) {
233
+ authctx .RefreshUserAuthContext (& config , clienterrors .IsUnauthorizedError , err )
234
+ continue
235
+ }
231
236
return errors .Wrap (err , "list data protections" )
232
237
}
233
238
0 commit comments