-
Notifications
You must be signed in to change notification settings - Fork 17
What if ... ImportBlockWithResourceIdentity #431
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
Changes from 4 commits
c75a3db
09bd9b5
55b88aa
daee136
ff949e2
bc4b461
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -454,6 +454,14 @@ type ExternalProvider struct { | |||||
| Source string // the provider source | ||||||
| } | ||||||
|
|
||||||
| type ImportStateKind byte | ||||||
|
|
||||||
| const ( | ||||||
| TerraformImportCommand ImportStateKind = iota | ||||||
|
||||||
| TerraformImportCommand ImportStateKind = iota | |
| ImportCommandWithId ImportStateKind = iota |
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.
If we can generate config on our first try, then the usefulness of this is secondary.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package resource | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
| "github.com/hashicorp/terraform-plugin-go/tftypes" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
| ) | ||
|
|
||
| func TestTest_TestStep_ImportBlockVerify(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| UnitTest(t, TestCase{ | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| // import blocks are only available in v1.5.0 and later | ||
| tfversion.SkipBelow(tfversion.Version1_5_0), | ||
| }, | ||
| ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
| "examplecloud": providerserver.NewProviderServer(testprovider.Provider{ | ||
| Resources: map[string]testprovider.Resource{ | ||
| "examplecloud_bucket": exampleCloudBucketResource(t), | ||
| }, | ||
| }), | ||
| }, | ||
| Steps: []TestStep{ | ||
| { | ||
| Config: ` | ||
| resource "examplecloud_bucket" "storage" { | ||
| bucket = "test-bucket" | ||
| description = "A bucket for testing." | ||
| }`, | ||
| }, | ||
| { | ||
| ImportState: true, | ||
| ImportStateKind: ImportBlockWithResourceIdentity, | ||
| ResourceName: "examplecloud_bucket.storage", | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func exampleCloudBucketResource(t *testing.T) testprovider.Resource { | ||
| t.Helper() | ||
|
|
||
| return testprovider.Resource{ | ||
| CreateResponse: &resource.CreateResponse{ | ||
| NewResourceIdentityData: tftypes.NewValue( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New and shiny! |
||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "region": tftypes.String, | ||
| "bucket": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "region": tftypes.NewValue(tftypes.String, "test-region"), | ||
| "bucket": tftypes.NewValue(tftypes.String, "test-bucket"), | ||
| }, | ||
| ), | ||
| NewState: tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "bucket": tftypes.String, | ||
| "description": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "bucket": tftypes.NewValue(tftypes.String, "test-bucket"), | ||
| "description": tftypes.NewValue(tftypes.String, "A bucket for testing."), | ||
| }, | ||
| ), | ||
| }, | ||
| ImportStateResponse: &resource.ImportStateResponse{}, | ||
| SchemaResponse: &resource.SchemaResponse{ | ||
| Schema: &tfprotov6.Schema{ | ||
| Block: &tfprotov6.SchemaBlock{ | ||
| Attributes: []*tfprotov6.SchemaAttribute{ | ||
| { | ||
| Name: "bucket", | ||
| Type: tftypes.String, | ||
| Required: true, | ||
| }, | ||
| { | ||
| Name: "description", | ||
| Type: tftypes.String, | ||
| Optional: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
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.
Naming is ... naming.
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.
The thought is: we're expanding to 3 sub-modes of import testing. Make it explicit, not inferred.
TerraformImportCommand is what we do today & will be the compatibility default.