From 7fbfbd462b7714c62e40634d3b93c7a5777dabf8 Mon Sep 17 00:00:00 2001 From: BBBmau Date: Wed, 8 May 2024 17:45:11 -0700 Subject: [PATCH] add source_model support for :copy --- mmv1/products/vertexai/Models.yaml | 199 +++++++++--------- .../vertex_ai_name_from_model.go.erb | 7 - .../vertex_ai_name_from_model.tmpl | 7 + ...ai_models.go.erb => vertex_ai_models.tmpl} | 0 .../terraform/encoders/vertex_ai_models.tmpl | 5 + .../examples/vertex_ai_model_basic.tf.erb | 13 -- .../vertex_ai_model_source_basic.tf.tmpl | 7 + ...ai_models.go.erb => vertex_ai_models.tmpl} | 0 8 files changed, 121 insertions(+), 117 deletions(-) delete mode 100644 mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.tmpl rename mmv1/templates/terraform/decoders/{vertex_ai_models.go.erb => vertex_ai_models.tmpl} (100%) create mode 100644 mmv1/templates/terraform/encoders/vertex_ai_models.tmpl delete mode 100644 mmv1/templates/terraform/examples/vertex_ai_model_basic.tf.erb create mode 100644 mmv1/templates/terraform/examples/vertex_ai_model_source_basic.tf.tmpl rename mmv1/templates/terraform/pre_create/{vertex_ai_models.go.erb => vertex_ai_models.tmpl} (100%) diff --git a/mmv1/products/vertexai/Models.yaml b/mmv1/products/vertexai/Models.yaml index 97fdd8deed3d..30680854e686 100644 --- a/mmv1/products/vertexai/Models.yaml +++ b/mmv1/products/vertexai/Models.yaml @@ -11,14 +11,14 @@ # See the License for the specific language governing permissions and # limitations under the License. ---- !ruby/object:Api::Resource +--- name: Models base_url: projects/{{project}}/locations/{{region}}/models create_url: 'projects/{{project}}/locations/{{region}}/modelsPRE_CREATE_REPLACE_ME' delete_url: '{{name}}' self_link: '{{name}}' -references: !ruby/object:Api::Resource::ReferenceLinks +references: guides: 'Official Documentation': 'https://cloud.google.com/vertex-ai/docs' api: 'https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.models' @@ -27,294 +27,303 @@ description: |- id_format: '{{name}}' autogen_async: false exclude_import: true -async: !ruby/object:Api::OpAsync +async: actions: - create - delete - operation: !ruby/object:Api::OpAsync::Operation + operation: path: 'name' base_url: '{{op_id}}' wait_ms: 1000 - result: !ruby/object:Api::OpAsync::Result + result: path: 'response' resource_inside_response: true - status: !ruby/object:Api::OpAsync::Status + status: path: 'done' complete: true allowed: - true - false - error: !ruby/object:Api::OpAsync::Error + error: path: 'error' message: 'message' -custom_code: !ruby/object:Provider::Terraform::CustomCode - decoder: templates/terraform/decoders/vertex_ai_models.go.erb - pre_create: templates/terraform/pre_create/vertex_ai_models.go.erb +custom_code: + encoder: templates/terraform/encoders/vertex_ai_models.tmpl + decoder: templates/terraform/decoders/vertex_ai_models.tmpl + pre_create: templates/terraform/pre_create/vertex_ai_models.tmpl examples: - - !ruby/object:Provider::Terraform::Examples - name: 'vertex_ai_model_basic' - skip_import_test: true + - name: 'vertex_ai_model_source_basic' + exclude_import_test: true primary_resource_id: 'model' vars: - name: 'test-model' + model_id: 'test-model' + test_env_vars: + project_name: :PROJECT_NAME parameters: - - !ruby/object:Api::Type::String + - type: String name: region description: The region of the Model. eg us-central1 url_param_only: true immutable: true default_from_api: true properties: - - !ruby/object:Api::Type::String + - type: String name: 'name' description: The name of the Model. This value may be up to 60 characters, and valid characters are [a-z0-9_]. The first character cannot be a number. output: true # url_param_only: true - custom_flatten: templates/terraform/custom_flatten/vertex_ai_name_from_model.go.erb - - !ruby/object:Api::Type::String + custom_flatten: templates/terraform/custom_flatten/vertex_ai_name_from_model.tmpl + - type: String name: 'description' description: Description of the Model. immutable: true - - !ruby/object:Api::Type::String + - type: String name: 'versionId' description: The version ID of the Model. immutable: true output: true - - !ruby/object:Api::Type::String + - type: String name: 'versionCreateTime' output: true description: | The timestamp of when this version was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. - - !ruby/object:Api::Type::String + - type: String name: 'versionUpdateTime' output: true description: | The timestamp of when this version was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. - - !ruby/object:Api::Type::String + - type: String name: 'versionDescription' output: true description: | The description of this version - - !ruby/object:Api::Type::String + - type: String name: 'metadataSchemaUri' immutable: true description: | Points to a YAML file stored on Google Cloud Storage describing additional information about the Model, that is specific to it. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'predictSchemata' description: | The schemata that describe formats of the Model's predictions and explanations as given and returned via PredictionService.Predict and PredictionService.Explain. properties: - - !ruby/object:Api::Type::String + - type: String name: instanceSchemaUri immutable: true description: | Points to a YAML file stored on Google Cloud Storage describing the format of a single instance, which are used in PredictRequest.instances, ExplainRequest.instances and BatchPredictionJob.input_config. - - !ruby/object:Api::Type::String + - type: String name: parametersSchemaUri immutable: true description: | Points to a YAML file stored on Google Cloud Storage describing the parameters of prediction and explanation via PredictRequest.parameters, ExplainRequest.parameters and BatchPredictionJob.model_parameters. - - !ruby/object:Api::Type::String + - type: String name: predictionSchemaUri immutable: true description: | Points to a YAML file stored on Google Cloud Storage describing the format of a single prediction produced by this Model, which are returned via PredictResponse.predictions, ExplainResponse.explanations, and BatchPredictionJob.output_config. - - !ruby/object:Api::Type::Array + - type: Array name: 'supportedExportFormats' output: true description: | The formats in which this Model may be exported. If empty, this Model is not available for export. - item_type: !ruby/object:Api::Type::NestedObject + item_type: + type: NestedObject properties: - - !ruby/object:Api::Type::String + - type: String name: id output: true description: | The ID of the export format. - - !ruby/object:Api::Type::Enum + - type: Enum name: exportableContent immutable: true description: | The content of this Model that may be exported. - values: + enum_values: - :ARTIFACT - :IMAGE - - !ruby/object:Api::Type::String + - type: String name: 'trainerPipeline' output: true description: | The resource name of the TrainingPipeline that uploaded this Model, if any. - - !ruby/object:Api::Type::String + - type: String name: 'pipelineJob' description: | This field is populated if the model is produced by a pipeline job. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'containerSpec' description: | The specification of the container that is to be used when deploying this Model. properties: - - !ruby/object:Api::Type::String + - type: String name: 'imageUri' required: true immutable: true description: URI of the Docker image to be used as the custom container for serving predictions. - - !ruby/object:Api::Type::Array + - type: Array name: 'command' immutable: true description: Specifies the command that runs when the container starts. This overrides the container's ENTRYPOINT. - item_type: Api::Type::String - - !ruby/object:Api::Type::Array + item_type: + type: String + - type: Array name: 'args' immutable: true description: Specifies arguments for the command that runs when the container starts. - item_type: Api::Type::String - - !ruby/object:Api::Type::Array + item_type: + type: String + - type: Array name: 'env' immutable: true description: List of environment variables to set in the container. - item_type: !ruby/object:Api::Type::NestedObject + item_type: + type: NestedObject properties: - - !ruby/object:Api::Type::String + - type: String name: 'name' required: true description: name of the environment variable. Must be a valid C identifier. - - !ruby/object:Api::Type::String + - type: String name: 'value' required: true description: Variables that reference a $(VAR_NAME) are expanded using the previous defined environment variables in the container and any service environment variables. - - !ruby/object:Api::Type::Array + - type: Array name: 'ports' immutable: true description: List of ports to expose from the container. - item_type: !ruby/object:Api::Type::NestedObject + item_type: + type: NestedObject properties: - - !ruby/object:Api::Type::Integer + - type: Integer name: 'containerPort' required: true description: The number of the port to expose on the pod's IP address. Must be a valid port number, between 1 and 65535 inclusive. - - !ruby/object:Api::Type::String + - type: String name: 'predictRoute' immutable: true description: HTTP path on the container to send prediction requests to. - - !ruby/object:Api::Type::String + - type: String name: 'healthRoute' immutable: true description: HTTP path on the container to send health checks to. - - !ruby/object:Api::Type::Array + - type: Array name: 'grpcPorts' immutable: true description: List of ports to expose from the container. - item_type: !ruby/object:Api::Type::NestedObject + item_type: + type: NestedObject properties: - - !ruby/object:Api::Type::Integer + - type: Integer name: 'containerPort' required: true description: The number of the port to expose on the pod's IP address. Must be a valid port number, between 1 and 65535 inclusive. - - !ruby/object:Api::Type::String + - type: String name: 'deploymentTimeout' immutable: true description: Deployment timeout. Limit for deployment timeout is 2 hours. - - !ruby/object:Api::Type::String + - type: String name: 'sharedMemorySizeMb' immutable: true description: The amount of the VM memory to reserve as the shared memory for the model in megabytes. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'startupProbe' immutable: true description: Specification for Kubernetes startup probe. properties: - - !ruby/object:Api::Type::Integer + - type: Integer name: 'periodSeconds' immutable: true default_value: 10 description: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. Must be less than timeoutSeconds. - - !ruby/object:Api::Type::Integer + - type: Integer name: 'timeoutSeconds' immutable: true default_value: 1 description: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. Must be greater or equal to periodSeconds. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'exec' description: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. Must be greater or equal to periodSeconds. properties: - - !ruby/object:Api::Type::String + - type: String name: 'command' description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'healthProbe' immutable: true description: Specification for Kubernetes readiness probe. properties: - - !ruby/object:Api::Type::Integer + - type: Integer name: 'periodSeconds' immutable: true default_value: 10 description: How often (in seconds) to perform the probe. Default to 10 seconds. Minimum value is 1. Must be less than timeoutSeconds. - - !ruby/object:Api::Type::Integer + - type: Integer name: 'timeoutSeconds' immutable: true default_value: 1 description: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. Must be greater or equal to periodSeconds. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'exec' description: Number of seconds after which the probe times out. Defaults to 1 second. Minimum value is 1. Must be greater or equal to periodSeconds. properties: - - !ruby/object:Api::Type::String + - type: String name: 'command' description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. - - !ruby/object:Api::Type::String + - type: String name: 'artifactUri' immutable: true description: | The path to the directory containing the Model artifact and any of its supporting files. - - !ruby/object:Api::Type::String + - type: String name: 'createTime' output: true description: | The timestamp of when the Model was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. - - !ruby/object:Api::Type::String + - type: String name: 'updateTime' output: true description: | The timestamp of when the MetadataStore was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. - - !ruby/object:Api::Type::String + - type: String name: 'displayName' description: The display name of the Model. The name can be up to 128 characters long and can consist of any UTF-8 characters. - - !ruby/object:Api::Type::String + - type: String name: 'etag' description: Used to perform consistent read-modify-write updates. output: true ignore_read: true - - !ruby/object:Api::Type::Array + - type: Array name: 'versionAliases' description: user provided version aliases so that a model version can be referenced via alias. - item_type: Api::Type::String - - !ruby/object:Api::Type::KeyValueLabels + item_type: + type: String + - type: KeyValueLabels name: 'labels' description: The labels with user-defined metadata to organize your Models. - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'encryptionSpec' immutable: true description: | Customer-managed encryption key spec for a MetadataStore. If set, this MetadataStore and all sub-resources of this MetadataStore will be secured by this key. properties: - - !ruby/object:Api::Type::String + - type: String name: 'kmsKeyName' description: | Required. The Cloud KMS resource identifier of the customer managed encryption key used to protect a resource. Has the form: projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key. The key needs to be in the same region as where the resource is created. immutable: true - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'metadata' description: An additional information about the Index properties: - - !ruby/object:Api::Type::String + - type: String name: 'contentsDeltaUri' required: true description: |- @@ -324,31 +333,31 @@ properties: Index field can be also updated as part of the same call. The expected structure and format of the files this URI points to is described at https://cloud.google.com/vertex-ai/docs/matching-engine/using-matching-engine#input-data-format - custom_flatten: templates/terraform/custom_flatten/vertex_ai_index_ignore_contents_delta_uri.go.erb - - !ruby/object:Api::Type::Boolean + custom_flatten: templates/terraform/custom_flatten/vertex_ai_index_ignore_contents_delta_uri.go.tmpl + - type: Boolean name: 'isCompleteOverwrite' description: |- If this field is set together with contentsDeltaUri when calling IndexService.UpdateIndex, then existing content of the Index will be replaced by the data from the contentsDeltaUri. default_value: false - custom_flatten: templates/terraform/custom_flatten/vertex_ai_index_ignore_is_complete_overwrite.go.erb - - !ruby/object:Api::Type::NestedObject + custom_flatten: templates/terraform/custom_flatten/vertex_ai_index_ignore_is_complete_overwrite.go.tmpl + - type: NestedObject name: 'config' immutable: true description: The configuration of the Matching Engine Index. properties: - - !ruby/object:Api::Type::Integer + - type: Integer name: 'dimensions' description: The number of dimensions of the input vectors. required: true - - !ruby/object:Api::Type::Integer + - type: Integer name: 'approximateNeighborsCount' description: |- The default number of neighbors to find via approximate search before exact reordering is performed. Exact reordering is a procedure where results returned by an approximate search algorithm are reordered via a more expensive distance computation. Required if tree-AH algorithm is used. - - !ruby/object:Api::Type::String + - type: String name: 'shardSize' description: |- Index data is split into equal parts to be processed. These are called "shards". @@ -358,7 +367,7 @@ properties: * SHARD_SIZE_LARGE: Large (50GB) immutable: true default_from_api: true - - !ruby/object:Api::Type::String + - type: String name: 'distanceMeasureType' description: |- The distance measure used in nearest neighbor search. The value must be one of the followings: @@ -367,7 +376,7 @@ properties: * COSINE_DISTANCE: Cosine Distance. Defined as 1 - cosine similarity. * DOT_PRODUCT_DISTANCE: Dot Product Distance. Defined as a negative of the dot product default_value: 'DOT_PRODUCT_DISTANCE' - - !ruby/object:Api::Type::String + - type: String name: 'featureNormType' description: |- Type of normalization to be carried out on each vector. The value must be one of the followings: @@ -375,13 +384,13 @@ properties: * NONE: No normalization type is specified. default_value: 'NONE' ignore_read: true - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'algorithmConfig' description: The configuration with regard to the algorithms used for efficient search. properties: - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'treeAhConfig' exactly_one_of: - treeAhConfig @@ -390,19 +399,19 @@ properties: Configuration options for using the tree-AH algorithm (Shallow tree + Asymmetric Hashing). Please refer to this paper for more details: https://arxiv.org/abs/1908.10396 properties: - - !ruby/object:Api::Type::Integer + - type: Integer name: 'leafNodeEmbeddingCount' description: Number of embeddings on each leaf node. The default value is 1000 if not set. default_value: 1000 - - !ruby/object:Api::Type::Integer + - type: Integer name: 'leafNodesToSearchPercent' description: |- The default percentage of leaf nodes that any query may be searched. Must be in range 1-100, inclusive. The default value is 10 (means 10%) if not set. default_value: 10 - - !ruby/object:Api::Type::NestedObject + - type: NestedObject name: 'bruteForceConfig' allow_empty_object: true send_empty_value: true @@ -413,14 +422,14 @@ properties: description: |- Configuration options for using brute force search, which simply implements the standard linear search in the database for each query. - - !ruby/object:Api::Type::String + - type: String name: 'sourceModel' at_least_one_of: - model - sourceModel description: | The resource name of the Model to copy. That Model must be in the same Project - - !ruby/object:Api::Type::ResourceRef + - type: ResourceRef name: 'model' resource: 'Model' imports: 'displayName' @@ -429,11 +438,7 @@ properties: - model description: | The Model to create. - - !ruby/object:Api::Type::String + - type: String name: 'modelID' description: | Copy sourceModel into a new Model with this ID. The ID will become the final component of the model resource name. - - !ruby/object:Api::Type::String - name: 'parentModel' - description: | - Specify this field to copy sourceModel into this existing Model as a new version. diff --git a/mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.go.erb b/mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.go.erb deleted file mode 100644 index d6dcef6856ec..000000000000 --- a/mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.go.erb +++ /dev/null @@ -1,7 +0,0 @@ -func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { - if d.Get("name").(string) == "" { - return v.(string) - } - - return d.Get("name") -} \ No newline at end of file diff --git a/mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.tmpl b/mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.tmpl new file mode 100644 index 000000000000..571b0f4bc9f0 --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/vertex_ai_name_from_model.tmpl @@ -0,0 +1,7 @@ +func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if d.Get("name").(string) == "" { + return v.(string) + } + + return d.Get("name") +} \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/vertex_ai_models.go.erb b/mmv1/templates/terraform/decoders/vertex_ai_models.tmpl similarity index 100% rename from mmv1/templates/terraform/decoders/vertex_ai_models.go.erb rename to mmv1/templates/terraform/decoders/vertex_ai_models.tmpl diff --git a/mmv1/templates/terraform/encoders/vertex_ai_models.tmpl b/mmv1/templates/terraform/encoders/vertex_ai_models.tmpl new file mode 100644 index 000000000000..3b2578cb5103 --- /dev/null +++ b/mmv1/templates/terraform/encoders/vertex_ai_models.tmpl @@ -0,0 +1,5 @@ +if obj["sourceModel"] != nil { + delete(obj, "labels") +} + +return obj, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/vertex_ai_model_basic.tf.erb b/mmv1/templates/terraform/examples/vertex_ai_model_basic.tf.erb deleted file mode 100644 index 4bbb7740aabc..000000000000 --- a/mmv1/templates/terraform/examples/vertex_ai_model_basic.tf.erb +++ /dev/null @@ -1,13 +0,0 @@ -resource "google_vertex_ai_models" "<%= ctx[:primary_resource_id] %>" { - display_name = "<%= ctx[:vars]['display_name'] %>" - description = "sample description" - labels = { - "key1" : "value1", - "key2" : "value2" - } - region = "us-central1" - encryption_spec { - kms_key_name = "<%= ctx[:vars]['kms_key_name'] %>" - } - depends_on = [google_kms_crypto_key_iam_member.crypto_key] -} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/vertex_ai_model_source_basic.tf.tmpl b/mmv1/templates/terraform/examples/vertex_ai_model_source_basic.tf.tmpl new file mode 100644 index 000000000000..5968647b24f4 --- /dev/null +++ b/mmv1/templates/terraform/examples/vertex_ai_model_source_basic.tf.tmpl @@ -0,0 +1,7 @@ +resource "google_vertex_ai_models" "{{$.PrimaryResourceId}}" { + model_id = "{{index $.Vars "model_id"}}" + project = "{{index $.TestEnvVars "project_name"}}" + source_model = "projects/{{index $.TestEnvVars "project_name"}}>/locations/us-central1/models/4469245519628878651" + + region = "us-central1" +} \ No newline at end of file diff --git a/mmv1/templates/terraform/pre_create/vertex_ai_models.go.erb b/mmv1/templates/terraform/pre_create/vertex_ai_models.tmpl similarity index 100% rename from mmv1/templates/terraform/pre_create/vertex_ai_models.go.erb rename to mmv1/templates/terraform/pre_create/vertex_ai_models.tmpl