hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.25k stars 1.7k forks source link

google_vertex_ai_index documents requied fields as optional #17804

Open natedogith1 opened 2 months ago

natedogith1 commented 2 months ago

Community Note

Terraform Version

Terraform v1.3.9 on linux_amd64

Affected Resource(s)

google_vertex_ai_index

Terraform Configuration

resource "google_vertex_ai_index" "index" {
  project             = var.project
  display_name        = local.display_name
  description         = var.description
  index_update_method = var.index_update_method
  region              = var.region
  labels              = var.labels
  metadata {
    contents_delta_uri    = var.contents_delta_uri
    is_complete_overwrite = var.is_complete_overwrite 
    config {
      dimensions                  = var.metadata_config.dimensions
      approximate_neighbors_count = var.metadata_config.approximate_neighbors_count
      shard_size                  = var.metadata_config.shard_size
      distance_measure_type       = var.metadata_config.distance_measure_type
      feature_norm_type           = var.metadata_config.feature_norm_type
      algorithm_config {}
    }
  }
}

Debug Output

No response

Expected Behavior

terraform plan should have failed, because terraform apply will fail

Actual Behavior

terraform plan passes, but terraform apply fails with the error: Error: Error creating Index: googleapi: Error 400: algorithmConfig is required but missing from the metadata.

Steps to reproduce

  1. terraform plan
  2. see that the plan succeeds
  3. terraform apply
  4. see that the apply fails due to algorithmConfig being required

Important Factoids

No response

References

No response

b/341993952

ggtisc commented 2 months ago

Hi @natedogith1 please provide the vars you are managing to replicate this issue (for sensitive data you can just put a comment like #provided)

natedogith1 commented 2 months ago

I haven't tested, but I expect you'd get a similar error with:

resource "google_vertex_ai_index" "index" {
  display_name = "test-index"
}
ggtisc commented 2 months ago

This example was replicated successfully without errors in terraform plan and terraform apply. I suggest you follow the next examples because everything indicates that the variables that you have declared in your metadata configuration are causing this error.

natedogith1 commented 2 months ago

Here's the error I get from terraform apply after adding each level of optional argument.

local.project_id is a project id, local.region is "europe-west3", local.contents_delta_gcs_uri is a gcs:// uri that points to an empty bucket.

resource "google_vertex_ai_index" "index" {
    project             = local.project_id
    display_name        = "test-display-name"
    index_update_method = "BATCH_UPDATE"
    region              = local.region
}

Error: Error creating Index: googleapi: Error 400: Index metadata is missing.

resource "google_vertex_ai_index" "index" {
    project             = local.project_id
    display_name        = "test-display-name"
    index_update_method = "BATCH_UPDATE"
    region              = local.region
    metadata {
        contents_delta_uri    = local.contents_delta_gcs_uri
        is_complete_overwrite = false
    }
}

Error: Error creating Index: googleapi: Error 400: dimensions is required but missing from Index metadata.

resource "google_vertex_ai_index" "index" {
    project             = local.project_id
    display_name        = "test-display-name"
    index_update_method = "BATCH_UPDATE"
    region              = local.region
    metadata {
        contents_delta_uri    = local.contents_delta_gcs_uri
        is_complete_overwrite = false
        config {
            dimensions                  = 3
        }
    }
}

Error: Error creating Index: googleapi: Error 400: algorithmConfig is required but missing from the metadata.

resource "google_vertex_ai_index" "index" {
    project             = local.project_id
    display_name        = "test-display-name"
    index_update_method = "BATCH_UPDATE"
    region              = local.region
    metadata {
        contents_delta_uri    = local.contents_delta_gcs_uri
        is_complete_overwrite = false
        config {
            dimensions                  = 3
            algorithm_config {
            }
        }
    }
}

Error: Error creating Index: googleapi: Error 400: algorithmConfig is required but missing from the metadata.

resource "google_vertex_ai_index" "index" {
    project             = local.project_id
    display_name        = "test-display-name"
    index_update_method = "BATCH_UPDATE"
    region              = local.region
    metadata {
        contents_delta_uri    = local.contents_delta_gcs_uri
        is_complete_overwrite = false
        config {
            dimensions                  = 3
            algorithm_config {
                brute_force_config {}
            }
        }
    }
}

Error: Error waiting to create Index: Error waiting for Creating Index: Error code 9, message: FAILED_PRECONDITION

ggtisc commented 2 months ago

Following the next configuration that is available on the shared link with your specifications everything was successfully replicated again without errors with the next configuration:

resource "google_storage_bucket" "bucket_17804" {
  name     = "vertex-ai-index-test-17804"
  location = "europe-west3"
  uniform_bucket_level_access = true
}

resource "google_vertex_ai_index" "google_vertex_ai_index_17804" {
    display_name        = "google-vertex-ai-index-17804"
    index_update_method = "BATCH_UPDATE"
    region              = "europe-west3"
    metadata {
        contents_delta_uri    = "gs://${google_storage_bucket.bucket_17804.name}/contents"
        is_complete_overwrite = false
        config {
            dimensions                  = 3
            algorithm_config {
                brute_force_config {}
            }
        }
    }
}

I suggest you check your user and account permissions and follow the documentation IO.

ggtisc commented 1 month ago

After a new replication with just this code the issue was confirmed:

resource "google_vertex_ai_index" "google_vertex_ai_index_17804" {
    display_name        = "google-vertex-ai-index-17804"
    index_update_method = "BATCH_UPDATE"
    region              = "europe-west3"
}

It is returning the next message even when the metadata appears as an optional argument in terraform registry:

Error: Error creating Index: googleapi: Error 400: Index metadata is missing.

JoyceYingZhu commented 1 month ago

metadata.contents_delta_uri is Required according to terraform registry