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

Implement terraform code to provision Vertex AI resources #27979

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

# Overview

This module provisions a
[Vertex AI Featurestore](https://cloud.google.com/vertex-ai/docs/featurestore).

# Requirements and Usage

See [Google Cloud Platform requirements](../../../google-cloud-platform/README.md)
for details on requirements
and usage.

## 1. Initialize the terraform module

```
cd .test-infra/terraform/google-cloud-platform/vertex-ai-featurestore
terraform init
```

## 2. Create a *.tfvars file

Create a `*.tfvars` file in the same directory as this module.

```
cd .test-infra/terraform/google-cloud-platform/vertex-ai-featurestore
touch vars.tfvars
```

See [Examples](#examples) below for some example `*.tfvars` files.

## 3. Apply the terraform module.

```
cd .test-infra/terraform/google-cloud-platform/vertex-ai-featurestore
terraform apply -var-file=vars.tfvars
```

# Examples

## synthea.tfvars

This directory holds a [synthea.tfvars](synthea.tfvars) to generate an
example Vertex AI Featurestore based on data generated from
https://github.com/synthetichealth/synthea
and stored in Google Cloud FHIR Store with BigQuery streaming.
See: https://cloud.google.com/healthcare-api/docs/how-tos/fhir-bigquery-streaming
for more details.

To apply using this `*.tfvars` file:

```
cd .test-infra/terraform/google-cloud-platform/vertex-ai-featurestore
terraform apply -var-file=synthea.tfvars
```

You will be prompted for any remaining unset variables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

provider "google" {
project = var.project
}

resource "google_project_service" "required" {
service = "aiplatform.googleapis.com"
disable_on_destroy = false
}

resource "random_string" "postfix" {
length = 6
upper = false
special = false
}

resource "google_vertex_ai_featurestore" "default" {
depends_on = [google_project_service.required]
name = "${var.featurestore.name_prefix}_${random_string.postfix.result}"
region = var.region
online_serving_config {
fixed_node_count = var.featurestore.fixed_node_count
}
}

resource "google_vertex_ai_featurestore_entitytype" "entities" {
depends_on = [google_project_service.required]
for_each = var.featurestore.entity_types
name = each.key
featurestore = google_vertex_ai_featurestore.default.id
description = each.value.description
monitoring_config {

categorical_threshold_config {
value = 0.3
}

numerical_threshold_config {
value = 0.3
}

snapshot_analysis {
disabled = false
monitoring_interval_days = 1
staleness_days = 21
}
}
}

locals {
features = flatten([
for entitytype_name, entitytype in var.featurestore.entity_types : [
for feature_name, feature_type in entitytype.features : {
entitytype_name = entitytype_name
feature_name = feature_name
feature_type = feature_type
}
]
])
features_map = tomap({
for feature in local.features :
"${feature["entitytype_name"]}.${feature["feature_name"]}" => feature
})
}

resource "google_vertex_ai_featurestore_entitytype_feature" "features" {
depends_on = [google_project_service.required]
for_each = local.features_map
name = each.value["feature_name"]
entitytype = google_vertex_ai_featurestore_entitytype.entities[each.value["entitytype_name"]].id
value_type = each.value["feature_type"]
}
Loading