Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vertexai): Make it possible to use Private Service Connect in Vertex AI Index Endpoint #8851

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions mmv1/products/vertexai/IndexEndpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ examples:
network_name: "network-name"
test_vars_overrides:
network_name: 'acctest.BootstrapSharedTestNetwork(t, "vertex-ai-index-endpoint")'
- !ruby/object:Provider::Terraform::Examples
name: "vertex_ai_index_endpoint_with_psc"
primary_resource_id: "index_endpoint"
- !ruby/object:Provider::Terraform::Examples
name: "vertex_ai_index_endpoint_with_false_psc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add skip_doc to skip the documentation generation for this example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it in 600459b.

primary_resource_id: "index_endpoint"
# It's not distinguishable if the psc is false or not set, so we need to skip the test.
skip_import_test: true
skip_docs: true
- !ruby/object:Provider::Terraform::Examples
name: "vertex_ai_index_endpoint_with_public_endpoint"
primary_resource_id: "index_endpoint"
Expand Down Expand Up @@ -102,6 +111,28 @@ properties:
[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.
immutable: true
conflicts:
- privateServiceConnectConfig
- !ruby/object:Api::Type::NestedObject
name: privateServiceConnectConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll likely need to have default_from_api here to prevent permadiff since we always write this block back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it in f3aecd4.

immutable: true
default_from_api: true
description: |-
Optional. Configuration for private service connect. `network` and `privateServiceConnectConfig` are mutually exclusive.
shotarok marked this conversation as resolved.
Show resolved Hide resolved
conflicts:
- network
custom_flatten: templates/terraform/custom_flatten/vertex_ai_index_endpoint_private_service_connect_config.go.erb
properties:
- !ruby/object:Api::Type::Boolean
name: enablePrivateServiceConnect
description: If set to true, the IndexEndpoint is created without private service access.
immutable: true
required: true
- !ruby/object:Api::Type::Array
name: projectAllowlist
description: A list of Projects from which the forwarding rule will target the service attachment.
item_type: Api::Type::String
immutable: true
- !ruby/object:Api::Type::Boolean
name: publicEndpointEnabled
immutable: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<%# The license inside this block applies to this file.
# Copyright 2023 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
transformed := make(map[string]interface{})

if v == nil {
// Disabled by default, but API will not return object if value is false
transformed["enable_private_service_connect"] = false
return []interface{}{transformed}
}

original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}

transformed["enable_private_service_connect"] =
flattenVertexAIIndexEndpointPrivateServiceConnectConfigEnablePrivateServiceConnect(original["enablePrivateServiceConnect"], d, config)
transformed["project_allowlist"] =
flattenVertexAIIndexEndpointPrivateServiceConnectConfigProjectAllowlist(original["projectAllowlist"], d, config)
return []interface{}{transformed}
}

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

func flattenVertexAIIndexEndpointPrivateServiceConnectConfigProjectAllowlist(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "google_vertex_ai_index_endpoint" "<%= ctx[:primary_resource_id] %>" {
display_name = "sample-endpoint"
description = "A sample vertex endpoint"
region = "us-central1"
labels = {
label-one = "value-one"
}

private_service_connect_config {
enable_private_service_connect = false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "google_vertex_ai_index_endpoint" "<%= ctx[:primary_resource_id] %>" {
display_name = "sample-endpoint"
description = "A sample vertex endpoint"
region = "us-central1"
labels = {
label-one = "value-one"
}

private_service_connect_config {
enable_private_service_connect = true
project_allowlist = [
data.google_project.project.number,
]
}
}

data "google_project" "project" {}