-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for google_vertex_ai_tensorboard resource #6759
Merged
melinath
merged 8 commits into
GoogleCloudPlatform:main
from
AlfatahB:vertexai-add-tensorboard-resource
Nov 17, 2022
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd1e781
Added support for google_vertex_ai_tensorboard resource
AlfatahB f1050f6
Merge branch 'main' of https://github.com/GoogleCloudPlatform/magic-m…
AlfatahB 619bfc0
Added full test case for google_vertex_ai_tensorboard resource
AlfatahB 2471425
Added import support for google_vertex_ai_tensorboard
AlfatahB a8f4d07
Added Full and Update test cases for google_vertex_ai_tensorboard
AlfatahB ac4c6d7
Merge branch 'main' of https://github.com/GoogleCloudPlatform/magic-m…
AlfatahB f037336
Updated the full test of google_vertex_ai_tensorboard
AlfatahB db5c5ad
Updated examples to include import test for vertex_ai_tensorboard
AlfatahB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" | ||
} |
152 changes: 152 additions & 0 deletions
152
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,152 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccVertexAITensorboard_Full(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_Full(random_suffix), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccVertexAITensorboard_Full(random_suffix string) string { | ||
return fmt.Sprintf(` | ||
data "google_project" "project" { | ||
} | ||
resource "google_kms_key_ring" "keyring" { | ||
name = "keyring-%s" | ||
location = "us-central1" | ||
} | ||
resource "google_kms_crypto_key" "example-key" { | ||
name = "crypto-key-%s" | ||
key_ring = google_kms_key_ring.keyring.id | ||
rotation_period = "100000s" | ||
lifecycle { | ||
prevent_destroy = false | ||
} | ||
} | ||
resource "google_kms_crypto_key_iam_binding" "crypto_key_encrypt" { | ||
crypto_key_id = google_kms_crypto_key.example-key.id | ||
role = "roles/cloudkms.cryptoKeyEncrypter" | ||
members = [ | ||
"serviceAccount:service-${data.google_project.project.number}@gcp-sa-aiplatform.iam.gserviceaccount.com", | ||
] | ||
} | ||
resource "google_kms_crypto_key_iam_binding" "crypto_key_decrypt" { | ||
crypto_key_id = google_kms_crypto_key.example-key.id | ||
role = "roles/cloudkms.cryptoKeyDecrypter" | ||
members = [ | ||
"serviceAccount:service-${data.google_project.project.number}@gcp-sa-aiplatform.iam.gserviceaccount.com", | ||
] | ||
} | ||
resource "google_vertex_ai_tensorboard" "tensorboard" { | ||
depends_on = [google_kms_crypto_key_iam_binding.crypto_key_encrypt, google_kms_crypto_key_iam_binding.crypto_key_decrypt] | ||
display_name = "%s" | ||
description = "sample description" | ||
labels = { | ||
"key1" : "value1", | ||
"key2" : "value2" | ||
} | ||
region = "us-central1" | ||
encryption_spec { | ||
kms_key_name = google_kms_crypto_key.example-key.id | ||
} | ||
} | ||
`, random_suffix, random_suffix, random_suffix) | ||
} | ||
|
||
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) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please switch this test to use BootstrapKMSKeyInLocation - it looks like this might even let you switch to generating the test using an example. For example:
magic-modules/mmv1/products/vertexai/terraform.yaml
Line 35 in 2fecbdf
Using the bootstrapped crypto keys lets us limit the number of crypto keys created, which is important since they can't be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the test to use BootstrapKMSKeyInLocation.