-
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 7 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" | ||
} |
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) | ||
} |
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.
Why do these tests use
skip_import_test
?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.
It's because we need to use
ImportStateVerifyIgnore: []string{"region", "project"}
instead ofImportStateVerifyIgnore: []string{"region"}
. There is a difference in thename
field (projects/{project}/locations/{location}/tensorboards/{tensorboard}
) of imported resources where instead of project_id we are getting project_number. Hence, I've usedskip_import_test
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 think that should be fine, since
name
is an output-only field.You can use
ignore_read_extra
here & above instead ofskip_import_test
to just ignore the one additional field:If the API returns project numbers - will users get a permadiff if they try to set the
project
field using a project id?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.
No, User won't face state drift if the
project
field is set to project id. It's just that import is forming thename
field using thereplaceVars
function which takes the project_id and this gets changed when the resource is successfully imported.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 examples to include
ignore_read_extra
for the tests.