forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemorystore_instance.go.erb
42 lines (35 loc) · 1.23 KB
/
memorystore_instance.go.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Retrieve pscAutoConnections from API response
v, ok := res["pscAutoConnections"]
if !ok {
return nil, fmt.Errorf("pscAutoConnections field not found in API response")
}
connections, ok := v.([]interface{})
if !ok {
return nil, fmt.Errorf("pscAutoConnections is not an array")
}
transformed := make([]interface{}, 0, len(connections))
uniqueConnections := make(map[string]bool) // Track unique project+network combos
for _, raw := range connections {
connectionData, ok := raw.(map[string]interface{})
if !ok || len(connectionData) < 1 {
return nil, fmt.Errorf("Invalid or empty psc connection data: %v", raw)
}
projectID, ok := connectionData["projectId"].(string)
if !ok {
return nil, fmt.Errorf("invalid project ID in psc connection: %v", connectionData)
}
networkID, ok := connectionData["network"].(string)
if !ok {
return nil, fmt.Errorf("invalid network ID in psc connection: %v", connectionData)
}
uniqueKey := projectID + networkID
if !uniqueConnections[uniqueKey] { // Check for uniqueness
uniqueConnections[uniqueKey] = true
transformed = append(transformed, map[string]interface{}{
"project_id": projectID,
"network": networkID,
})
}
}
d.Set("desired_psc_auto_connections", transformed)
return res, nil