forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for google_vertex_ai_tensorboard resource (GoogleCloudP…
…latform#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
- Loading branch information
1 parent
a859950
commit 6167505
Showing
6 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
mmv1/templates/terraform/custom_import/vertex_ai_tensorboard_import.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
config := meta.(*Config) | ||
if err := parseImportId([]string{ | ||
"projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/tensorboards/(?P<name>[^/]+)", | ||
"(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)", | ||
"(?P<region>[^/]+)/(?P<name>[^/]+)", | ||
"(?P<name>[^/]+)", | ||
}, 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 |
9 changes: 9 additions & 0 deletions
9
mmv1/templates/terraform/examples/vertex_ai_tensorboard.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
resource "google_vertex_ai_tensorboard" "<%= ctx[:primary_resource_id] %>" { | ||
display_name = "<%= ctx[:vars]['display_name'] %>" | ||
description = "sample description" | ||
labels = { | ||
"key1" : "value1", | ||
"key2" : "value2" | ||
} | ||
region = "us-central1" | ||
} |
21 changes: 21 additions & 0 deletions
21
mmv1/templates/terraform/examples/vertex_ai_tensorboard_full.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
resource "google_vertex_ai_tensorboard" "<%= 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] | ||
} | ||
|
||
resource "google_kms_crypto_key_iam_member" "crypto_key" { | ||
crypto_key_id = "<%= ctx[:vars]['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" {} |
89 changes: 89 additions & 0 deletions
89
mmv1/third_party/terraform/tests/resource_vertex_ai_tensorboard_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |