Skip to content

Commit

Permalink
feat(vertexai): Make it possible to create a public Vertex AI Index E…
Browse files Browse the repository at this point in the history
…ndpoint (#8852) (#15741)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 6, 2023
1 parent f6dee26 commit ef4ee3d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/8852.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
vertexai: added `public_endpoint_enabled` to `google_vertex_ai_index_endpoint`
```
28 changes: 28 additions & 0 deletions google/services/vertexai/resource_vertex_ai_index_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ Private services access must already be configured for the network. If left unsp
[Format](https://cloud.google.com/compute/docs/reference/rest/v1/networks/insert): 'projects/{project}/global/networks/{network}'.
Where '{project}' is a project number, as in '12345', and '{network}' is network name.`,
},
"public_endpoint_enabled": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `If true, the deployed index will be accessible through public endpoint.`,
},
"region": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -94,6 +100,11 @@ Where '{project}' is a project number, as in '12345', and '{network}' is network
Computed: true,
Description: `The resource name of the Index.`,
},
"public_endpoint_domain_name": {
Type: schema.TypeString,
Computed: true,
Description: `If publicEndpointEnabled is true, this field will be populated with the domain name to use for this index endpoint.`,
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -142,6 +153,12 @@ func resourceVertexAIIndexEndpointCreate(d *schema.ResourceData, meta interface{
} else if v, ok := d.GetOkExists("network"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) {
obj["network"] = networkProp
}
publicEndpointEnabledProp, err := expandVertexAIIndexEndpointPublicEndpointEnabled(d.Get("public_endpoint_enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("public_endpoint_enabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(publicEndpointEnabledProp)) && (ok || !reflect.DeepEqual(v, publicEndpointEnabledProp)) {
obj["publicEndpointEnabled"] = publicEndpointEnabledProp
}

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

return nil
}
Expand Down Expand Up @@ -466,6 +486,10 @@ func flattenVertexAIIndexEndpointNetwork(v interface{}, d *schema.ResourceData,
return v
}

func flattenVertexAIIndexEndpointPublicEndpointDomainName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandVertexAIIndexEndpointDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand All @@ -488,3 +512,7 @@ func expandVertexAIIndexEndpointLabels(v interface{}, d tpgresource.TerraformRes
func expandVertexAIIndexEndpointNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandVertexAIIndexEndpointPublicEndpointEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestAccVertexAIIndexEndpoint_vertexAiIndexEndpointExample(t *testing.T) {
ResourceName: "google_vertex_ai_index_endpoint.index_endpoint",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "region"},
ImportStateVerifyIgnore: []string{"etag", "public_endpoint_enabled", "region"},
},
},
})
Expand Down Expand Up @@ -93,6 +93,47 @@ data "google_project" "project" {}
`, context)
}

func TestAccVertexAIIndexEndpoint_vertexAiIndexEndpointWithPublicEndpointExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"network_name": acctest.BootstrapSharedTestNetwork(t, "vertex-ai-index-endpoint"),
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckVertexAIIndexEndpointDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccVertexAIIndexEndpoint_vertexAiIndexEndpointWithPublicEndpointExample(context),
},
{
ResourceName: "google_vertex_ai_index_endpoint.index_endpoint",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "public_endpoint_enabled", "region"},
},
},
})
}

func testAccVertexAIIndexEndpoint_vertexAiIndexEndpointWithPublicEndpointExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_vertex_ai_index_endpoint" "index_endpoint" {
display_name = "sample-endpoint"
description = "A sample vertex endpoint with an public endpoint"
region = "us-central1"
labels = {
label-one = "value-one"
}
public_endpoint_enabled = true
}
`, context)
}

func testAccCheckVertexAIIndexEndpointDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
27 changes: 27 additions & 0 deletions website/docs/r/vertex_ai_index_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ data "google_compute_network" "vertex_network" {
data "google_project" "project" {}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Vertex Ai Index Endpoint With Public Endpoint


```hcl
resource "google_vertex_ai_index_endpoint" "index_endpoint" {
display_name = "sample-endpoint"
description = "A sample vertex endpoint with an public endpoint"
region = "us-central1"
labels = {
label-one = "value-one"
}
public_endpoint_enabled = true
}
```

## Argument Reference

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

* `public_endpoint_enabled` -
(Optional)
If true, the deployed index will be accessible through public endpoint.

* `region` -
(Optional)
The region of the index endpoint. eg us-central1
Expand All @@ -123,6 +147,9 @@ In addition to the arguments listed above, the following computed attributes are
* `update_time` -
The timestamp of when the Index was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.

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


## Timeouts

Expand Down

0 comments on commit ef4ee3d

Please sign in to comment.