Skip to content

Commit df835d1

Browse files
committed
Parse Interface ID from serviceAttachmentNames for GCP
1 parent 11323f9 commit df835d1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pkg/controller/atlasproject/private_endpoint.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package atlasproject
33
import (
44
"context"
55
"errors"
6+
"regexp"
67

78
"go.mongodb.org/atlas/mongodbatlas"
89

@@ -178,13 +179,27 @@ func (a atlasPE) InterfaceEndpointID() string {
178179
return a.PrivateEndpoints[0]
179180
}
180181

181-
if len(a.EndpointGroupNames) != 0 {
182-
return a.EndpointGroupNames[0]
182+
if len(a.ServiceAttachmentNames) != 0 {
183+
return parseInterfaceIDForGCP(a.ServiceAttachmentNames)
183184
}
184185

185186
return ""
186187
}
187188

189+
func parseInterfaceIDForGCP(serviceAttachmentNames []string) string {
190+
if len(serviceAttachmentNames) < 1 {
191+
return ""
192+
}
193+
194+
expr := regexp.MustCompile(`(\w+)-\d$`)
195+
matches := expr.FindStringSubmatch(serviceAttachmentNames[0])
196+
if len(matches) < 2 {
197+
return ""
198+
}
199+
200+
return matches[1]
201+
}
202+
188203
func getAllPrivateEndpoints(client mongodbatlas.Client, projectID string) (result []atlasPE, err error) {
189204
providers := []string{"AWS", "AZURE", "GCP"}
190205
for _, provider := range providers {

0 commit comments

Comments
 (0)