Skip to content

Commit 7c0bd04

Browse files
Add google_vertex_ai_model_garden_enable_model (beta) resource (#18036)
1 parent 203efc5 commit 7c0bd04

4 files changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright 2025 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: ModelGardenEnableModel
16+
api_resource_type_kind: PublisherModel
17+
description: |
18+
Enables a Model Garden publisher model for a project so that it can be
19+
deployed. This calls the synchronous
20+
`ModelGardenService.EnableModel` method, which checks that the prerequisites
21+
for the model are met (for example, a completed questionnaire and accepted
22+
consents, or an active Private Offer) before enabling it.
23+
24+
~> **Note:** The underlying API does not provide a way to disable a model
25+
once it has been enabled, so destroying this resource only removes it from
26+
Terraform state and does not affect the project's enablement status.
27+
references:
28+
guides:
29+
Use models in Model Garden: https://cloud.google.com/vertex-ai/generative-ai/docs/model-garden/use-models
30+
Overview of Model Garden: https://cloud.google.com/vertex-ai/generative-ai/docs/model-garden/explore-models
31+
api: https://cloud.google.com/vertex-ai/docs/reference/rest/v1beta1/projects.publishers.models/enableModel
32+
docs:
33+
# Only available in the v1beta1 (beta) API surface.
34+
min_version: beta
35+
base_url: projects/{{project}}/{{publisher_model_name}}:enableModel
36+
create_url: projects/{{project}}/{{publisher_model_name}}:enableModel
37+
self_link: projects/{{project}}/{{publisher_model_name}}
38+
id_format: projects/{{project}}/{{publisher_model_name}}
39+
immutable: true
40+
# EnableModel is a synchronous action-only method with no Read, Delete, or
41+
# Import support, so the lifecycle is create-only.
42+
exclude_read: true
43+
exclude_delete: true
44+
exclude_import: true
45+
exclude_sweeper: true
46+
timeouts:
47+
insert_minutes: 20
48+
custom_code:
49+
post_create: templates/terraform/post_create/resource_vertexai_model_garden_enable_model.go.tmpl
50+
examples:
51+
- name: vertex_ai_model_garden_enable_model_basic
52+
min_version: beta
53+
primary_resource_id: enable
54+
# Handwritten test required since the resource does not support read,
55+
# delete, or import.
56+
exclude_test: true
57+
vars:
58+
publisher_model_name: publishers/google/models/paligemma@paligemma-224-float32
59+
parameters:
60+
- name: publisherModelName
61+
type: String
62+
description: |-
63+
The resource name of the Model Garden publisher model to enable.
64+
Format: `publishers/{publisher}/models/{publisher_model}`, optionally
65+
with a version suffix, for example
66+
`publishers/google/models/paligemma@paligemma-224-float32`.
67+
min_version: beta
68+
immutable: true
69+
url_param_only: true
70+
required: true
71+
properties:
72+
- name: publisherEndpoint
73+
type: String
74+
description: |
75+
Output only. The publisher endpoint that the project is enabled for.
76+
Format:
77+
`projects/{project}/locations/{location}/publishers/{publisher}/models/{publisher_model}`.
78+
min_version: beta
79+
output: true
80+
- name: enablementState
81+
type: Enum
82+
description: |
83+
Output only. The result of the model enablement.
84+
min_version: beta
85+
output: true
86+
enum_values:
87+
- ENABLEMENT_STATE_UNSPECIFIED
88+
- ENABLEMENT_STATE_SUCCEEDED
89+
- ENABLEMENT_STATE_FAILED
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "google_vertex_ai_model_garden_enable_model" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
publisher_model_name = "{{index $.Vars "publisher_model_name"}}"
4+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
log.Printf("[DEBUG] Beginning post_create for Vertex AI Model Garden EnableModel %q", d.Id())
2+
3+
// EnableModel is a synchronous method, so the create response (res) already
4+
// contains the EnableModelResponse body. Surface the output-only fields and
5+
// validate that the enablement actually succeeded.
6+
7+
if enablementState, ok := res["enablementState"].(string); ok {
8+
log.Printf("[DEBUG] EnableModel enablement state for %q: %s", d.Id(), enablementState)
9+
if err := d.Set("enablement_state", enablementState); err != nil {
10+
return fmt.Errorf("Error setting enablement_state: %s", err)
11+
}
12+
if enablementState == "ENABLEMENT_STATE_FAILED" {
13+
// The API call returned successfully but reported that the model could
14+
// not be enabled (e.g. unmet prerequisites). Fail the apply and clear
15+
// the ID so the resource is not recorded as created.
16+
d.SetId("")
17+
return fmt.Errorf("Error enabling Model Garden model %q: API returned enablement state ENABLEMENT_STATE_FAILED", d.Get("publisher_model_name"))
18+
}
19+
} else {
20+
log.Printf("[WARN] No enablementState returned by enableModel for %q", d.Id())
21+
}
22+
23+
if publisherEndpoint, ok := res["publisherEndpoint"].(string); ok {
24+
log.Printf("[DEBUG] EnableModel publisher endpoint for %q: %s", d.Id(), publisherEndpoint)
25+
if err := d.Set("publisher_endpoint", publisherEndpoint); err != nil {
26+
return fmt.Errorf("Error setting publisher_endpoint: %s", err)
27+
}
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package vertexai_test
2+
{{- if ne $.TargetVersionName "ga" }}
3+
4+
import (
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"github.com/hashicorp/terraform-provider-google/google/envvar"
10+
)
11+
12+
// EnableModel is a beta-only, synchronous, action-only resource. It has no
13+
// Read, Delete, or Import support, so this test only verifies that an apply
14+
// succeeds and that the output-only fields are populated. There is no inverse
15+
// "disable" API, so destroying the resource is a no-op and CheckDestroy is
16+
// intentionally omitted.
17+
func TestAccVertexAIModelGardenEnableModel_basic(t *testing.T) {
18+
t.Parallel()
19+
20+
context := map[string]interface{}{
21+
"project_id": envvar.GetTestProjectFromEnv(),
22+
"random_suffix": acctest.RandString(t, 10),
23+
}
24+
25+
acctest.VcrTest(t, resource.TestCase{
26+
PreCheck: func() { acctest.AccTestPreCheck(t) },
27+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
28+
Steps: []resource.TestStep{
29+
{
30+
Config: testAccVertexAIModelGardenEnableModel_basic(context),
31+
Check: resource.ComposeTestCheckFunc(
32+
resource.TestCheckResourceAttrSet(
33+
"google_vertex_ai_model_garden_enable_model.enable", "enablement_state"),
34+
resource.TestCheckResourceAttrSet(
35+
"google_vertex_ai_model_garden_enable_model.enable", "publisher_endpoint"),
36+
),
37+
},
38+
},
39+
})
40+
}
41+
42+
func testAccVertexAIModelGardenEnableModel_basic(context map[string]interface{}) string {
43+
return acctest.Nprintf(`
44+
resource "google_vertex_ai_model_garden_enable_model" "enable" {
45+
provider = google-beta
46+
project = "%{project_id}"
47+
publisher_model_name = "publishers/google/models/paligemma@paligemma-224-float32"
48+
}
49+
`, context)
50+
}
51+
52+
{{ end }}

0 commit comments

Comments
 (0)