Skip to content
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
3 changes: 3 additions & 0 deletions .changelog/18889.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_vertex_ai_rag_corpus`
```
184 changes: 184 additions & 0 deletions google-beta/services/vertexai/list_vertex_ai_rag_corpus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
// Copyright IBM Corp. 2014, 2026
// SPDX-License-Identifier: MPL-2.0

// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This code is generated by Magic Modules using the following:
//
// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/vertexai/RagCorpus.yaml
// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/list_resource.go.tmpl
//
// DO NOT EDIT this file directly. Any changes made to this file will be
// overwritten during the next generation cycle.
//
// ----------------------------------------------------------------------------

package vertexai

import (
"context"
"errors"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/list"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/registry"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func init() {
registry.FrameworkListResource{
Name: "google_vertex_ai_rag_corpus",
ProductName: "VertexAI",
Func: NewVertexAIRagCorpusListResource,
}.Register()
}

var _ list.ListResource = &VertexAIRagCorpusListResource{}

type VertexAIRagCorpusListResource struct {
tpgresource.ListResourceMetadata
}

func NewVertexAIRagCorpusListResource() list.ListResource {
listR := &VertexAIRagCorpusListResource{}
listR.TypeName = "google_vertex_ai_rag_corpus"
listR.SDKv2Resource = ResourceVertexAIRagCorpus()
listR.ListConfigFields = []tpgresource.ListConfigField{
{Name: "region", Kind: tpgresource.ListConfigKindString, Optional: false},
{Name: "project", Kind: tpgresource.ListConfigKindString, Optional: true},
}
return listR
}

// VertexAIRagCorpusListModel matches ListResourceMetadata.ListConfigFields (tfsdk names and types).
type VertexAIRagCorpusListModel struct {
Region types.String `tfsdk:"region"`
Project types.String `tfsdk:"project"`
}

func (listR *VertexAIRagCorpusListResource) List(ctx context.Context, listReq list.ListRequest, stream *list.ListResultsStream) {
var data VertexAIRagCorpusListModel
diags := listReq.Config.Get(ctx, &data)
if diags.HasError() {
stream.Results = list.ListResultsStreamDiagnostics(diags)
return
}
if listR.Client == nil {
diags = append(diags, diag.NewErrorDiagnostic(
"Provider not configured",
"The Google provider client is not available; ensure the provider is configured (e.g. credentials and default project).",
))
stream.Results = list.ListResultsStreamDiagnostics(diags)
return
}
region := listR.GetRegion(data.Region)
project := listR.GetProject(data.Project)

errStreamClosed := errors.New("stream closed")
stream.Results = func(push func(list.ListResult) bool) {
err := ListVertexAIRagCorpuss(
listR.Client,
region,
project,
func(rd *schema.ResourceData) error {
result := listReq.NewListResult(ctx)

if err := listR.SetResult(ctx, listReq.IncludeResource, &result, rd, "name"); err != nil {
return err
}

if !push(result) {
return errStreamClosed
}
return nil
},
)
// A closed stream is not an error: return without pushing again.
if err == nil || errors.Is(err, errStreamClosed) {
return
}
diags.AddError("API Error", err.Error())
result := listReq.NewListResult(ctx)
result.Diagnostics = diags
push(result)
}
}

func ListVertexAIRagCorpuss(config *transport_tpg.Config,
region string,
project string,
callback func(*schema.ResourceData) error,
) error {
resourceData := ResourceVertexAIRagCorpus().Data(&terraform.InstanceState{})
if region != "" {
if err := resourceData.Set("region", region); err != nil {
return fmt.Errorf("error setting region on temporary resource data: %w", err)
}
}
if project != "" {
if err := resourceData.Set("project", project); err != nil {
return fmt.Errorf("error setting project on temporary resource data: %w", err)
}
}

url, err := tpgresource.ReplaceVars(resourceData, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/ragCorpora")
if err != nil {
return err
}
billingProject := project
if bp, err := tpgresource.GetBillingProject(resourceData, config); err == nil {
billingProject = bp
}

userAgent, err := tpgresource.GenerateUserAgentString(resourceData, config.UserAgent)
if err != nil {
return err
}
return transport_tpg.ListPages(transport_tpg.ListPagesOptions{
Config: config,
TempData: resourceData,
Resource: ResourceVertexAIRagCorpus(),
ListURL: url,
BillingProject: billingProject,
UserAgent: userAgent,
ItemName: "ragCorpora",
Flattener: func(res map[string]interface{}, d *schema.ResourceData, config *transport_tpg.Config) error {
headers := make(http.Header)
var err error
if v, ok := res["name"]; ok && v != nil {
if err := d.Set("name", v); err != nil {
return fmt.Errorf("error setting name: %w", err)
}
}
if v, ok := res["region"]; ok && v != nil {
if s, ok := v.(string); ok {
v = tpgresource.GetResourceNameFromSelfLink(s)
}
if err := d.Set("region", v); err != nil {
return fmt.Errorf("error setting region: %w", err)
}
}
if err = ResourceVertexAIRagCorpusFlatten(d, config, res, config, project, userAgent, billingProject, url, headers); err != nil {
return err
}
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/ragCorpora/{{name}}")
if err != nil {
return fmt.Errorf("error constructing id: %w", err)
}
d.SetId(id)
return nil
},
Callback: callback,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright IBM Corp. 2014, 2026
// SPDX-License-Identifier: MPL-2.0

// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This code is generated by Magic Modules using the following:
//
// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/vertexai/RagCorpus.yaml
// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/samples/base_configs/query_test_file.go.tmpl
//
// DO NOT EDIT this file directly. Any changes made to this file will be
// overwritten during the next generation cycle.
//
// ----------------------------------------------------------------------------

package vertexai_test

import (
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/querycheck"
"github.com/hashicorp/terraform-plugin-testing/querycheck/queryfilter"
"github.com/hashicorp/terraform-plugin-testing/tfversion"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
_ "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/resourcemanager"
_ "github.com/hashicorp/terraform-provider-google-beta/google-beta/services/vertexai"
)

var (
_ = strings.Trim
_ = envvar.TestEnvVar
_ = time.Now
)

func TestAccVertexAIRagCorpusListQuery_generated(t *testing.T) {

t.Parallel()

randomSuffix := acctest.RandString(t, 10)
context := map[string]interface{}{
"display_name": "tf-test-rag-corpus" + randomSuffix,
"region": envvar.GetTestRegionFromEnv(),
"project": envvar.GetTestProjectFromEnv(),
"random_suffix": randomSuffix,
}

var listDisplayName acctest.ListDisplayName
var listScope acctest.ListScopeCapture
acctest.VcrTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_14_0),
},
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckVertexAIRagCorpusDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccVertexAIRagCorpus_vertexAiRagCorpusBasicExample(context),
Check: resource.ComposeTestCheckFunc(
listDisplayName.Capture(
"google_vertex_ai_rag_corpus.example",
[]string{
"name",
},
),
listScope.Capture(map[string]string{
"region": "google_vertex_ai_rag_corpus.example",
}),
),
},
{
Query: true,
Config: testAccVertexAIRagCorpus_vertexAiRagCorpusBasicExampleListQuery(context),
ConfigVariables: listScope.AsConfigVariables(),
QueryResultChecks: []querycheck.QueryResultCheck{
querycheck.ExpectLengthAtLeast("google_vertex_ai_rag_corpus.list_query", 1),
querycheck.ExpectResourceDisplayName(
"google_vertex_ai_rag_corpus.list_query",
queryfilter.ByDisplayName(listDisplayName.CheckValue()),
listDisplayName.CheckValue(),
),
},
},
},
})
}

func testAccVertexAIRagCorpus_vertexAiRagCorpusBasicExampleListQuery(context map[string]interface{}) string {
return acctest.Nprintf(`
variable "region" { type = string }
list "google_vertex_ai_rag_corpus" "list_query" {
provider = google
limit = 10000
config {
region = var.region
}
}
`, context)
}
Loading