-
Notifications
You must be signed in to change notification settings - Fork 16
discovery: query mode #528
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
base: main
Are you sure you want to change the base?
Conversation
"github.com/hashicorp/terraform-plugin-testing/internal/teststep" | ||
) | ||
|
||
func examplecloudResource() testprovider.Resource { |
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.
Copied from ../importstate
.
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Query: 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.
Query mode!
@@ -0,0 +1,66 @@ | |||
// Copyright (c) HashiCorp, Inc. |
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.
Copied from ../importstate
.
@@ -254,7 +255,10 @@ func runNewTest(ctx context.Context, t testing.T, c TestCase, helper *plugintest | |||
|
|||
testStepConfig = teststep.Configuration(confRequest) | |||
|
|||
err = wd.SetConfig(ctx, testStepConfig, step.ConfigVariables) | |||
if !step.Query { |
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.
For purposes of this PR, SetConfig
and SetQuery
are 2 different things because one writes/manages a .tf
file and one writes/manages a .tfquery.hcl
file.
Does if !step.Query
feel right here? Likely not. The goal of this PR is more make-it-work than make-it-right/make-it-well-factored 😃
t.Fatalf("Step %d/%d error running query: %s", stepNumber, len(c.Steps), err) | ||
} | ||
|
||
fmt.Printf("Step %d/%d Query Output:\n%s\n", stepNumber, len(c.Steps), queryOut) |
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.
This simply echoes the Terraform output. So a test only fails if terraform query
fails.
In the real world, we would make assertions, call "query checks," ...
@@ -444,3 +526,38 @@ func (wd *WorkingDir) Schemas(ctx context.Context) (*tfjson.ProviderSchemas, err | |||
|
|||
return providerSchemas, err | |||
} | |||
|
|||
func (wd *WorkingDir) Query(ctx context.Context) ([]string, error) { |
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.
This function is a temporary solution until https://github.com/hashicorp/terraform-exec supports the query
subcommand.
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.
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 merged the PR:
go get github.com/hashicorp/terraform-exec@061a850a52d2e3a408d33066da3601983067b3d9
logging.HelperResourceTrace(ctx, "Called Terraform CLI providers query command") | ||
|
||
output := buffer.String() | ||
return []string{output}, nil |
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.
Someday, https://github.com/hashicorp/terraform-json may parse this output. Until then, we may want to json-decode it.
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package testprovider |
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.
testprovider
and testsdk
are internal implementations based on terraform-plugin-go. They are independent of SDKv2 and Framework.
Description
This pull request is not intended to be merged. It is a rugged, working proof-of-concept that identifies the wiring that would enable a
terraform query
acceptance test.cc: @stephybun @rainkwan fyi
Rollback Plan
Changes to Security Controls
None