Skip to content

Commit 6fb0ea2

Browse files
author
rnarenpujari
committed
Fix deref for dataprotection resource
1 parent 6878b5c commit 6fb0ea2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

internal/resources/dataprotection/resource_enable_data_protection.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,19 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource
6767

6868
err := populateDataFromServer(ctx, config, scopedFullnameData, data)
6969

70+
// remove the existing cluster level resource from state if it is now
71+
// managed at the cluster group level.
7072
if scopedFullnameData.Scope == scope.ClusterScope {
71-
metaData := data.Get(common.MetaKey).([]interface{})[0].(map[string]interface{})
72-
annotations := metaData[common.AnnotationsKey].(map[string]interface{})
73+
value, ok := data.GetOk(common.MetaKey)
74+
if ok && len(value.([]interface{})) > 0 {
75+
metaData := value.([]interface{})[0].(map[string]interface{})
76+
annotations := metaData[common.AnnotationsKey].(map[string]interface{})
7377

74-
if _, ok := annotations[commonscope.BatchUIDAnnotationKey]; ok {
75-
_ = schema.RemoveFromState(data, m)
78+
if _, ok := annotations[commonscope.BatchUIDAnnotationKey]; ok {
79+
_ = schema.RemoveFromState(data, m)
7680

77-
return diags
81+
return diags
82+
}
7883
}
7984
}
8085

0 commit comments

Comments
 (0)