Skip to content

Commit ef4ee3d

Browse files
feat(vertexai): Make it possible to create a public Vertex AI Index Endpoint (#8852) (#15741)
Signed-off-by: Modular Magician <[email protected]>
1 parent f6dee26 commit ef4ee3d

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

.changelog/8852.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
vertexai: added `public_endpoint_enabled` to `google_vertex_ai_index_endpoint`
3+
```

google/services/vertexai/resource_vertex_ai_index_endpoint.go

+28
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ Private services access must already be configured for the network. If left unsp
7373
[Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/insert): 'projects/{project}/global/networks/{network}'.
7474
Where '{project}' is a project number, as in '12345', and '{network}' is network name.`,
7575
},
76+
"public_endpoint_enabled": {
77+
Type: schema.TypeBool,
78+
Optional: true,
79+
ForceNew: true,
80+
Description: `If true, the deployed index will be accessible through public endpoint.`,
81+
},
7682
"region": {
7783
Type: schema.TypeString,
7884
Optional: true,
@@ -94,6 +100,11 @@ Where '{project}' is a project number, as in '12345', and '{network}' is network
94100
Computed: true,
95101
Description: `The resource name of the Index.`,
96102
},
103+
"public_endpoint_domain_name": {
104+
Type: schema.TypeString,
105+
Computed: true,
106+
Description: `If publicEndpointEnabled is true, this field will be populated with the domain name to use for this index endpoint.`,
107+
},
97108
"update_time": {
98109
Type: schema.TypeString,
99110
Computed: true,
@@ -142,6 +153,12 @@ func resourceVertexAIIndexEndpointCreate(d *schema.ResourceData, meta interface{
142153
} else if v, ok := d.GetOkExists("network"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
143154
obj["network"] = networkProp
144155
}
156+
publicEndpointEnabledProp, err := expandVertexAIIndexEndpointPublicEndpointEnabled(d.Get("public_endpoint_enabled"), d, config)
157+
if err != nil {
158+
return err
159+
} else if v, ok := d.GetOkExists("public_endpoint_enabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(publicEndpointEnabledProp)) && (ok || !reflect.DeepEqual(v, publicEndpointEnabledProp)) {
160+
obj["publicEndpointEnabled"] = publicEndpointEnabledProp
161+
}
145162

146163
url, err := tpgresource.ReplaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/indexEndpoints")
147164
if err != nil {
@@ -272,6 +289,9 @@ func resourceVertexAIIndexEndpointRead(d *schema.ResourceData, meta interface{})
272289
if err := d.Set("network", flattenVertexAIIndexEndpointNetwork(res["network"], d, config)); err != nil {
273290
return fmt.Errorf("Error reading IndexEndpoint: %s", err)
274291
}
292+
if err := d.Set("public_endpoint_domain_name", flattenVertexAIIndexEndpointPublicEndpointDomainName(res["publicEndpointDomainName"], d, config)); err != nil {
293+
return fmt.Errorf("Error reading IndexEndpoint: %s", err)
294+
}
275295

276296
return nil
277297
}
@@ -466,6 +486,10 @@ func flattenVertexAIIndexEndpointNetwork(v interface{}, d *schema.ResourceData,
466486
return v
467487
}
468488

489+
func flattenVertexAIIndexEndpointPublicEndpointDomainName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
490+
return v
491+
}
492+
469493
func expandVertexAIIndexEndpointDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
470494
return v, nil
471495
}
@@ -488,3 +512,7 @@ func expandVertexAIIndexEndpointLabels(v interface{}, d tpgresource.TerraformRes
488512
func expandVertexAIIndexEndpointNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
489513
return v, nil
490514
}
515+
516+
func expandVertexAIIndexEndpointPublicEndpointEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
517+
return v, nil
518+
}

google/services/vertexai/resource_vertex_ai_index_endpoint_generated_test.go

+42-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestAccVertexAIIndexEndpoint_vertexAiIndexEndpointExample(t *testing.T) {
5050
ResourceName: "google_vertex_ai_index_endpoint.index_endpoint",
5151
ImportState: true,
5252
ImportStateVerify: true,
53-
ImportStateVerifyIgnore: []string{"etag", "region"},
53+
ImportStateVerifyIgnore: []string{"etag", "public_endpoint_enabled", "region"},
5454
},
5555
},
5656
})
@@ -93,6 +93,47 @@ data "google_project" "project" {}
9393
`, context)
9494
}
9595

96+
func TestAccVertexAIIndexEndpoint_vertexAiIndexEndpointWithPublicEndpointExample(t *testing.T) {
97+
t.Parallel()
98+
99+
context := map[string]interface{}{
100+
"network_name": acctest.BootstrapSharedTestNetwork(t, "vertex-ai-index-endpoint"),
101+
"random_suffix": acctest.RandString(t, 10),
102+
}
103+
104+
acctest.VcrTest(t, resource.TestCase{
105+
PreCheck: func() { acctest.AccTestPreCheck(t) },
106+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
107+
CheckDestroy: testAccCheckVertexAIIndexEndpointDestroyProducer(t),
108+
Steps: []resource.TestStep{
109+
{
110+
Config: testAccVertexAIIndexEndpoint_vertexAiIndexEndpointWithPublicEndpointExample(context),
111+
},
112+
{
113+
ResourceName: "google_vertex_ai_index_endpoint.index_endpoint",
114+
ImportState: true,
115+
ImportStateVerify: true,
116+
ImportStateVerifyIgnore: []string{"etag", "public_endpoint_enabled", "region"},
117+
},
118+
},
119+
})
120+
}
121+
122+
func testAccVertexAIIndexEndpoint_vertexAiIndexEndpointWithPublicEndpointExample(context map[string]interface{}) string {
123+
return acctest.Nprintf(`
124+
resource "google_vertex_ai_index_endpoint" "index_endpoint" {
125+
display_name = "sample-endpoint"
126+
description = "A sample vertex endpoint with an public endpoint"
127+
region = "us-central1"
128+
labels = {
129+
label-one = "value-one"
130+
}
131+
132+
public_endpoint_enabled = true
133+
}
134+
`, context)
135+
}
136+
96137
func testAccCheckVertexAIIndexEndpointDestroyProducer(t *testing.T) func(s *terraform.State) error {
97138
return func(s *terraform.State) error {
98139
for name, rs := range s.RootModule().Resources {

website/docs/r/vertex_ai_index_endpoint.html.markdown

+27
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ data "google_compute_network" "vertex_network" {
6868
6969
data "google_project" "project" {}
7070
```
71+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
72+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=vertex_ai_index_endpoint_with_public_endpoint&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
73+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
74+
</a>
75+
</div>
76+
## Example Usage - Vertex Ai Index Endpoint With Public Endpoint
77+
78+
79+
```hcl
80+
resource "google_vertex_ai_index_endpoint" "index_endpoint" {
81+
display_name = "sample-endpoint"
82+
description = "A sample vertex endpoint with an public endpoint"
83+
region = "us-central1"
84+
labels = {
85+
label-one = "value-one"
86+
}
87+
88+
public_endpoint_enabled = true
89+
}
90+
```
7191

7292
## Argument Reference
7393

@@ -97,6 +117,10 @@ The following arguments are supported:
97117
[Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/insert): `projects/{project}/global/networks/{network}`.
98118
Where `{project}` is a project number, as in `12345`, and `{network}` is network name.
99119

120+
* `public_endpoint_enabled` -
121+
(Optional)
122+
If true, the deployed index will be accessible through public endpoint.
123+
100124
* `region` -
101125
(Optional)
102126
The region of the index endpoint. eg us-central1
@@ -123,6 +147,9 @@ In addition to the arguments listed above, the following computed attributes are
123147
* `update_time` -
124148
The timestamp of when the Index was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
125149

150+
* `public_endpoint_domain_name` -
151+
If publicEndpointEnabled is true, this field will be populated with the domain name to use for this index endpoint.
152+
126153

127154
## Timeouts
128155

0 commit comments

Comments
 (0)