Skip to content

Commit 8d659c8

Browse files
committed
Fix vertex_ai_index_endpoint_deployed_index import without provider region
1 parent 5b9f0d7 commit 8d659c8

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

mmv1/templates/terraform/custom_import/vertex_ai_index_endpoint_deployed_index.go.tmpl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@ if err := tpgresource.ParseImportId([]string{
77
return nil, err
88
}
99

10+
// The Read URL is templated on '{{"{{"}}region{{"}}"}}' (https://{{"{{"}}region{{"}}"}}-aiplatform.googleapis.com/...),
11+
// so extract region (and project) from the index_endpoint path. Otherwise an
12+
// import that doesn't set provider-level region/zone fails with
13+
// "Cannot determine region".
14+
indexEndpointRe := regexp.MustCompile(`^projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/indexEndpoints/[^/]+$`)
15+
if m := indexEndpointRe.FindStringSubmatch(d.Get("index_endpoint").(string)); m != nil {
16+
if err := d.Set("project", m[1]); err != nil {
17+
return nil, fmt.Errorf("Error setting project: %s", err)
18+
}
19+
if err := d.Set("region", m[2]); err != nil {
20+
return nil, fmt.Errorf("Error setting region: %s", err)
21+
}
22+
}
23+
1024
// Replace import id for the resource id
1125
id, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}index_endpoint{{"}}"}}/deployedIndex/{{"{{"}}deployed_index_id{{"}}"}}")
1226
if err != nil {
1327
return nil, fmt.Errorf("Error constructing id: %s", err)
1428
}
1529
d.SetId(id)
1630

17-
return []*schema.ResourceData{d}, nil
31+
return []*schema.ResourceData{d}, nil

0 commit comments

Comments
 (0)