-
Notifications
You must be signed in to change notification settings - Fork 17
Initial work on Query command for List Resource #531
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
954b002
Initial work on Query command for List Resource
rainkwan 99e9c88
Added helper/resource parts for query
rainkwan 870fff0
Moved files
rainkwan ede917c
But what if we comment out print statements?
rainkwan 06d2573
What if we are more specific and say `.tfquery.hcl`
rainkwan 236218d
Updating to version 1.14 for query_test.go
rainkwan 6ea1fa2
Update testing_new.go
rainkwan f0814f9
Update helper/resource/query/query_test.go
rainkwan 9b8369b
Update internal/plugintest/working_dir.go
rainkwan a0fa1d8
Update internal/teststep/file.go
rainkwan 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 hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package query_test | ||
|
|
||
| import ( | ||
| "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/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/teststep" | ||
| ) | ||
|
|
||
| func examplecloudResource() testprovider.Resource { | ||
| return testprovider.Resource{ | ||
| CreateResponse: &resource.CreateResponse{ | ||
| NewState: tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| "name": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope"), | ||
| "name": tftypes.NewValue(tftypes.String, "somevalue"), | ||
| }, | ||
| ), | ||
| NewIdentity: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| }, | ||
| )), | ||
| }, | ||
| ReadResponse: &resource.ReadResponse{ | ||
| NewState: tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| "name": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope"), | ||
| "name": tftypes.NewValue(tftypes.String, "somevalue"), | ||
| }, | ||
| ), | ||
| NewIdentity: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| }, | ||
| )), | ||
| }, | ||
| ImportStateResponse: &resource.ImportStateResponse{ | ||
| State: tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| "location": tftypes.String, | ||
| "name": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| "location": tftypes.NewValue(tftypes.String, "westeurope"), | ||
| "name": tftypes.NewValue(tftypes.String, "somevalue"), | ||
| }, | ||
| ), | ||
| Identity: teststep.Pointer(tftypes.NewValue( | ||
| tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "id": tftypes.String, | ||
| }, | ||
| }, | ||
| map[string]tftypes.Value{ | ||
| "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), | ||
| }, | ||
| )), | ||
| }, | ||
| SchemaResponse: &resource.SchemaResponse{ | ||
| Schema: &tfprotov6.Schema{ | ||
| Block: &tfprotov6.SchemaBlock{ | ||
| Attributes: []*tfprotov6.SchemaAttribute{ | ||
| ComputedStringAttribute("id"), | ||
| RequiredStringAttribute("location"), | ||
| RequiredStringAttribute("name"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| IdentitySchemaResponse: &resource.IdentitySchemaResponse{ | ||
| Schema: &tfprotov6.ResourceIdentitySchema{ | ||
| Version: 1, | ||
| IdentityAttributes: []*tfprotov6.ResourceIdentitySchemaAttribute{ | ||
| { | ||
| Name: "id", | ||
| Type: tftypes.String, | ||
| RequiredForImport: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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,63 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package query_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
| r "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/list" | ||
| "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
| ) | ||
|
|
||
| func TestQuery(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| r.UnitTest(t, r.TestCase{ | ||
| TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
| tfversion.SkipBelow(tfversion.Version1_14_0), // Query mode requires Terraform 1.13.0 or later | ||
| }, | ||
| ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
| "examplecloud": providerserver.NewProviderServer(testprovider.Provider{ | ||
| ListResources: map[string]testprovider.ListResource{ | ||
| "examplecloud_containerette": { | ||
| SchemaResponse: &list.SchemaResponse{ | ||
| Schema: &tfprotov6.Schema{ | ||
| Block: &tfprotov6.SchemaBlock{ | ||
| Attributes: []*tfprotov6.SchemaAttribute{ | ||
| ComputedStringAttribute("id"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ListResultsStream: &list.ListResultsStream{ | ||
| Results: func(push func(list.ListResult) bool) { | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| Resources: map[string]testprovider.Resource{ | ||
| "examplecloud_containerette": examplecloudResource(), | ||
| }, | ||
| }), | ||
| }, | ||
| Steps: []r.TestStep{ | ||
| { | ||
| Query: true, | ||
| Config: ` | ||
| provider "examplecloud" {} | ||
| list "examplecloud_containerette" "test" { | ||
| provider = examplecloud | ||
|
|
||
| config { | ||
| id = "bat" | ||
| } | ||
| }`, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
This file contains hidden or 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,66 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package query_test | ||
|
|
||
| import ( | ||
| "github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
| "github.com/hashicorp/terraform-plugin-go/tftypes" | ||
| ) | ||
|
|
||
| func RequiredBoolAttribute(name string) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.Bool, | ||
| Required: true, | ||
| } | ||
| } | ||
|
|
||
| func OptionalComputedListAttribute(name string, elementType tftypes.Type) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.List{ElementType: elementType}, | ||
| Optional: true, | ||
| Computed: true, | ||
| } | ||
| } | ||
|
|
||
| func RequiredListAttribute(name string, elementType tftypes.Type) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.List{ElementType: elementType}, | ||
| Required: true, | ||
| } | ||
| } | ||
|
|
||
| func RequiredNumberAttribute(name string) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.Number, | ||
| Required: true, | ||
| } | ||
| } | ||
|
|
||
| func ComputedStringAttribute(name string) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.String, | ||
| Computed: true, | ||
| } | ||
| } | ||
|
|
||
| func OptionalStringAttribute(name string) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.String, | ||
| Optional: true, | ||
| } | ||
| } | ||
|
|
||
| func RequiredStringAttribute(name string) *tfprotov6.SchemaAttribute { | ||
| return &tfprotov6.SchemaAttribute{ | ||
| Name: name, | ||
| Type: tftypes.String, | ||
| Required: true, | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.