From 3b4be7e3ac32e528bedc03926bf39d4cdc0286d5 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 17 Nov 2022 20:28:10 +0000 Subject: [PATCH] Added support for google_vertex_ai_tensorboard resource (#6759) * Added support for google_vertex_ai_tensorboard resource * Added full test case for google_vertex_ai_tensorboard resource * Added import support for google_vertex_ai_tensorboard * Added Full and Update test cases for google_vertex_ai_tensorboard * Updated the full test of google_vertex_ai_tensorboard * Updated examples to include import test for vertex_ai_tensorboard Signed-off-by: Modular Magician --- .changelog/6759.txt | 3 + google/provider.go | 5 +- google/resource_vertex_ai_tensorboard.go | 524 ++++++++++++++++++ ...ce_vertex_ai_tensorboard_generated_test.go | 148 +++++ google/resource_vertex_ai_tensorboard_test.go | 89 +++ .../r/vertex_ai_tensorboard.html.markdown | 169 ++++++ 6 files changed, 936 insertions(+), 2 deletions(-) create mode 100644 .changelog/6759.txt create mode 100644 google/resource_vertex_ai_tensorboard.go create mode 100644 google/resource_vertex_ai_tensorboard_generated_test.go create mode 100644 google/resource_vertex_ai_tensorboard_test.go create mode 100644 website/docs/r/vertex_ai_tensorboard.html.markdown diff --git a/.changelog/6759.txt b/.changelog/6759.txt new file mode 100644 index 00000000000..554a465eaa8 --- /dev/null +++ b/.changelog/6759.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_vertex_ai_tensorboard` +``` diff --git a/google/provider.go b/google/provider.go index cca70d7c0c4..14b1db5798b 100644 --- a/google/provider.go +++ b/google/provider.go @@ -925,9 +925,9 @@ func Provider() *schema.Provider { return provider } -// Generated resources: 246 +// Generated resources: 247 // Generated IAM resources: 150 -// Total generated resources: 396 +// Total generated resources: 397 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -1313,6 +1313,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_tags_tag_value_iam_policy": ResourceIamPolicy(TagsTagValueIamSchema, TagsTagValueIamUpdaterProducer, TagsTagValueIdParseFunc), "google_tags_tag_binding": resourceTagsTagBinding(), "google_tpu_node": resourceTPUNode(), + "google_vertex_ai_tensorboard": resourceVertexAITensorboard(), "google_vertex_ai_dataset": resourceVertexAIDataset(), "google_vertex_ai_endpoint": resourceVertexAIEndpoint(), "google_vertex_ai_featurestore": resourceVertexAIFeaturestore(), diff --git a/google/resource_vertex_ai_tensorboard.go b/google/resource_vertex_ai_tensorboard.go new file mode 100644 index 00000000000..76fe94e6fe6 --- /dev/null +++ b/google/resource_vertex_ai_tensorboard.go @@ -0,0 +1,524 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceVertexAITensorboard() *schema.Resource { + return &schema.Resource{ + Create: resourceVertexAITensorboardCreate, + Read: resourceVertexAITensorboardRead, + Update: resourceVertexAITensorboardUpdate, + Delete: resourceVertexAITensorboardDelete, + + Importer: &schema.ResourceImporter{ + State: resourceVertexAITensorboardImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(20 * time.Minute), + Update: schema.DefaultTimeout(20 * time.Minute), + Delete: schema.DefaultTimeout(20 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "display_name": { + Type: schema.TypeString, + Required: true, + Description: `User provided name of this Tensorboard.`, + }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: `Description of this Tensorboard.`, + }, + "encryption_spec": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Description: `Customer-managed encryption key spec for a Tensorboard. If set, this Tensorboard and all sub-resources of this Tensorboard will be secured by this key.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "kms_key_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `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.`, + }, + }, + }, + }, + "labels": { + Type: schema.TypeMap, + Optional: true, + Description: `The labels with user-defined metadata to organize your Tensorboards.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "region": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + Description: `The region of the tensorboard. eg us-central1`, + }, + "blob_storage_path_prefix": { + Type: schema.TypeString, + Computed: true, + Description: `Consumer project Cloud Storage path prefix used to store blob data, which can either be a bucket or directory. Does not end with a '/'.`, + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: `The timestamp of when the Tensorboard was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `Name of the Tensorboard.`, + }, + "run_count": { + Type: schema.TypeString, + Computed: true, + Description: `The number of Runs stored in this Tensorboard.`, + }, + "update_time": { + Type: schema.TypeString, + Computed: true, + Description: `The timestamp of when the Tensorboard was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + UseJSONNumber: true, + } +} + +func resourceVertexAITensorboardCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + displayNameProp, err := expandVertexAITensorboardDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandVertexAITensorboardDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + encryptionSpecProp, err := expandVertexAITensorboardEncryptionSpec(d.Get("encryption_spec"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("encryption_spec"); !isEmptyValue(reflect.ValueOf(encryptionSpecProp)) && (ok || !reflect.DeepEqual(v, encryptionSpecProp)) { + obj["encryptionSpec"] = encryptionSpecProp + } + labelsProp, err := expandVertexAITensorboardLabels(d.Get("labels"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + url, err := replaceVars(d, config, "{{VertexAIBasePath}}projects/{{project}}/locations/{{region}}/tensorboards") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Tensorboard: %#v", obj) + billingProject := "" + + project, err := getProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Tensorboard: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating Tensorboard: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + // Use the resource in the operation response to populate + // identity fields and d.Id() before read + var opRes map[string]interface{} + err = vertexAIOperationWaitTimeWithResponse( + config, res, &opRes, project, "Creating Tensorboard", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + + return fmt.Errorf("Error waiting to create Tensorboard: %s", err) + } + + if err := d.Set("name", flattenVertexAITensorboardName(opRes["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Tensorboard %q: %#v", d.Id(), res) + + return resourceVertexAITensorboardRead(d, meta) +} + +func resourceVertexAITensorboardRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{VertexAIBasePath}}{{name}}") + if err != nil { + return err + } + + billingProject := "" + + project, err := getProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Tensorboard: %s", err) + } + billingProject = project + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("VertexAITensorboard %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + + if err := d.Set("name", flattenVertexAITensorboardName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("display_name", flattenVertexAITensorboardDisplayName(res["displayName"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("description", flattenVertexAITensorboardDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("encryption_spec", flattenVertexAITensorboardEncryptionSpec(res["encryptionSpec"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("blob_storage_path_prefix", flattenVertexAITensorboardBlobStoragePathPrefix(res["blobStoragePathPrefix"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("run_count", flattenVertexAITensorboardRunCount(res["runCount"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("create_time", flattenVertexAITensorboardCreateTime(res["createTime"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("update_time", flattenVertexAITensorboardUpdateTime(res["updateTime"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + if err := d.Set("labels", flattenVertexAITensorboardLabels(res["labels"], d, config)); err != nil { + return fmt.Errorf("Error reading Tensorboard: %s", err) + } + + return nil +} + +func resourceVertexAITensorboardUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + project, err := getProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Tensorboard: %s", err) + } + billingProject = project + + obj := make(map[string]interface{}) + displayNameProp, err := expandVertexAITensorboardDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandVertexAITensorboardDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + labelsProp, err := expandVertexAITensorboardLabels(d.Get("labels"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + url, err := replaceVars(d, config, "{{VertexAIBasePath}}{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Tensorboard %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("display_name") { + updateMask = append(updateMask, "displayName") + } + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + + if d.HasChange("labels") { + updateMask = append(updateMask, "labels") + } + // updateMask is a URL parameter but not present in the schema, so replaceVars + // won't set it + url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating Tensorboard %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating Tensorboard %q: %#v", d.Id(), res) + } + + err = vertexAIOperationWaitTime( + config, res, project, "Updating Tensorboard", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } + + return resourceVertexAITensorboardRead(d, meta) +} + +func resourceVertexAITensorboardDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + project, err := getProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Tensorboard: %s", err) + } + billingProject = project + + url, err := replaceVars(d, config, "{{VertexAIBasePath}}{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Tensorboard %q", d.Id()) + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "Tensorboard") + } + + err = vertexAIOperationWaitTime( + config, res, project, "Deleting Tensorboard", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting Tensorboard %q: %#v", d.Id(), res) + return nil +} + +func resourceVertexAITensorboardImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{ + "projects/(?P[^/]+)/locations/(?P[^/]+)/tensorboards/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "projects/{{project}}/locations/{{region}}/tensorboards/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + if err := d.Set("name", id); err != nil { + return nil, fmt.Errorf("Error setting name for import: %s", err) + } + + return []*schema.ResourceData{d}, nil +} + +func flattenVertexAITensorboardName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardDisplayName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardEncryptionSpec(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["kms_key_name"] = + flattenVertexAITensorboardEncryptionSpecKmsKeyName(original["kmsKeyName"], d, config) + return []interface{}{transformed} +} +func flattenVertexAITensorboardEncryptionSpecKmsKeyName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardBlobStoragePathPrefix(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardRunCount(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardCreateTime(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardUpdateTime(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenVertexAITensorboardLabels(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func expandVertexAITensorboardDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVertexAITensorboardDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVertexAITensorboardEncryptionSpec(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedKmsKeyName, err := expandVertexAITensorboardEncryptionSpecKmsKeyName(original["kms_key_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedKmsKeyName); val.IsValid() && !isEmptyValue(val) { + transformed["kmsKeyName"] = transformedKmsKeyName + } + + return transformed, nil +} + +func expandVertexAITensorboardEncryptionSpecKmsKeyName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandVertexAITensorboardLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) { + if v == nil { + return map[string]string{}, nil + } + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + return m, nil +} diff --git a/google/resource_vertex_ai_tensorboard_generated_test.go b/google/resource_vertex_ai_tensorboard_generated_test.go new file mode 100644 index 00000000000..fbd78640ca2 --- /dev/null +++ b/google/resource_vertex_ai_tensorboard_generated_test.go @@ -0,0 +1,148 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccVertexAITensorboard_vertexAiTensorboardExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVertexAITensorboardDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAITensorboard_vertexAiTensorboardExample(context), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + }, + }) +} + +func testAccVertexAITensorboard_vertexAiTensorboardExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_vertex_ai_tensorboard" "tensorboard" { + display_name = "terraform%{random_suffix}" + description = "sample description" + labels = { + "key1" : "value1", + "key2" : "value2" + } + region = "us-central1" +} +`, context) +} + +func TestAccVertexAITensorboard_vertexAiTensorboardFullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "kms_key_name": BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name, + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVertexAITensorboardDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAITensorboard_vertexAiTensorboardFullExample(context), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + }, + }) +} + +func testAccVertexAITensorboard_vertexAiTensorboardFullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_vertex_ai_tensorboard" "tensorboard" { + display_name = "terraform%{random_suffix}" + description = "sample description" + labels = { + "key1" : "value1", + "key2" : "value2" + } + region = "us-central1" + encryption_spec { + kms_key_name = "%{kms_key_name}" + } + depends_on = [google_kms_crypto_key_iam_member.crypto_key] +} + +resource "google_kms_crypto_key_iam_member" "crypto_key" { + crypto_key_id = "%{kms_key_name}" + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-aiplatform.iam.gserviceaccount.com" +} + +data "google_project" "project" {} +`, context) +} + +func testAccCheckVertexAITensorboardDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_vertex_ai_tensorboard" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := googleProviderConfig(t) + + url, err := replaceVarsForTest(config, rs, "{{VertexAIBasePath}}{{name}}") + if err != nil { + return err + } + + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) + if err == nil { + return fmt.Errorf("VertexAITensorboard still exists at %s", url) + } + } + + return nil + } +} diff --git a/google/resource_vertex_ai_tensorboard_test.go b/google/resource_vertex_ai_tensorboard_test.go new file mode 100644 index 00000000000..fd294810aea --- /dev/null +++ b/google/resource_vertex_ai_tensorboard_test.go @@ -0,0 +1,89 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccVertexAITensorboard_Update(t *testing.T) { + t.Parallel() + + random_suffix := "tf-test-" + randString(t, 10) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVertexAITensorboardDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccVertexAITensorboard_Update(random_suffix, random_suffix, random_suffix, random_suffix), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + { + Config: testAccVertexAITensorboard_Update(random_suffix+"new", random_suffix, random_suffix, random_suffix), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + { + Config: testAccVertexAITensorboard_Update(random_suffix+"new", random_suffix+"new", random_suffix, random_suffix), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + { + Config: testAccVertexAITensorboard_Update(random_suffix+"new", random_suffix+"new", random_suffix+"new", random_suffix), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + { + Config: testAccVertexAITensorboard_Update(random_suffix+"new", random_suffix+"new", random_suffix+"new", random_suffix+"new"), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + { + Config: testAccVertexAITensorboard_Update(random_suffix, random_suffix, random_suffix, random_suffix), + }, + { + ResourceName: "google_vertex_ai_tensorboard.tensorboard", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"region", "project"}, + }, + }, + }) +} + +func testAccVertexAITensorboard_Update(displayName, description, labelKey, labelVal string) string { + return fmt.Sprintf(` +resource "google_vertex_ai_tensorboard" "tensorboard" { + display_name = "%s" + description = "%s" + labels = { + "%s" : "%s", + } + region = "us-central1" +} +`, displayName, description, labelKey, labelVal) +} diff --git a/website/docs/r/vertex_ai_tensorboard.html.markdown b/website/docs/r/vertex_ai_tensorboard.html.markdown new file mode 100644 index 00000000000..c98d972f575 --- /dev/null +++ b/website/docs/r/vertex_ai_tensorboard.html.markdown @@ -0,0 +1,169 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Vertex AI" +page_title: "Google: google_vertex_ai_tensorboard" +description: |- + Tensorboard is a physical database that stores users' training metrics. +--- + +# google\_vertex\_ai\_tensorboard + +Tensorboard is a physical database that stores users' training metrics. A default Tensorboard is provided in each region of a GCP project. If needed users can also create extra Tensorboards in their projects. + + +To get more information about Tensorboard, see: + +* [API documentation](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.tensorboards) +* How-to Guides + * [Official Documentation](https://cloud.google.com/vertex-ai/docs) + + +## Example Usage - Vertex Ai Tensorboard + + +```hcl +resource "google_vertex_ai_tensorboard" "tensorboard" { + display_name = "terraform" + description = "sample description" + labels = { + "key1" : "value1", + "key2" : "value2" + } + region = "us-central1" +} +``` + +## Example Usage - Vertex Ai Tensorboard Full + + +```hcl +resource "google_vertex_ai_tensorboard" "tensorboard" { + display_name = "terraform" + description = "sample description" + labels = { + "key1" : "value1", + "key2" : "value2" + } + region = "us-central1" + encryption_spec { + kms_key_name = "kms-name" + } + depends_on = [google_kms_crypto_key_iam_member.crypto_key] +} + +resource "google_kms_crypto_key_iam_member" "crypto_key" { + crypto_key_id = "kms-name" + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + member = "serviceAccount:service-${data.google_project.project.number}@gcp-sa-aiplatform.iam.gserviceaccount.com" +} + +data "google_project" "project" {} +``` + +## Argument Reference + +The following arguments are supported: + + +* `display_name` - + (Required) + User provided name of this Tensorboard. + + +- - - + + +* `description` - + (Optional) + Description of this Tensorboard. + +* `encryption_spec` - + (Optional) + Customer-managed encryption key spec for a Tensorboard. If set, this Tensorboard and all sub-resources of this Tensorboard will be secured by this key. + Structure is [documented below](#nested_encryption_spec). + +* `labels` - + (Optional) + The labels with user-defined metadata to organize your Tensorboards. + +* `region` - + (Optional) + The region of the tensorboard. eg us-central1 + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +The `encryption_spec` block supports: + +* `kms_key_name` - + (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. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `{{name}}` + +* `name` - + Name of the Tensorboard. + +* `blob_storage_path_prefix` - + Consumer project Cloud Storage path prefix used to store blob data, which can either be a bucket or directory. Does not end with a '/'. + +* `run_count` - + The number of Runs stored in this Tensorboard. + +* `create_time` - + The timestamp of when the Tensorboard was created in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. + +* `update_time` - + The timestamp of when the Tensorboard was last updated in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 20 minutes. +- `update` - Default is 20 minutes. +- `delete` - Default is 20 minutes. + +## Import + + +Tensorboard can be imported using any of these accepted formats: + +``` +$ terraform import google_vertex_ai_tensorboard.default projects/{{project}}/locations/{{region}}/tensorboards/{{name}} +$ terraform import google_vertex_ai_tensorboard.default {{project}}/{{region}}/{{name}} +$ terraform import google_vertex_ai_tensorboard.default {{region}}/{{name}} +$ terraform import google_vertex_ai_tensorboard.default {{name}} +``` + +## User Project Overrides + +This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).