-
Notifications
You must be signed in to change notification settings - Fork 9.8k
list-resource/aws_vpc #44609
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
list-resource/aws_vpc #44609
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
75350a7
Adds Resource Identity to `aws_vpc`
gdavison f117086
Corrects `aws_iam_role` List Resource factory name
gdavison 2d8b6d8
Adds check for corresponding resource type when generating list resou…
gdavison bdc6380
Factors out reading `aws_vpc`
gdavison 077b4e2
Removes duplicate `VPCVPC` in generated VPC tests
gdavison e3adf45
Adds `aws_vpc` List Resource
gdavison a08a1a4
Adds region override for `aws_vpc`
gdavison 535702c
Adds test for `aws_vpc` `filter`
gdavison 31fbd0e
Adds test to validate that default VPC is not included
gdavison 8f1547f
Includes `querycheck.ExpectNoIdentity`
gdavison 93b442b
Validates that default VPC is not included in results
gdavison d0be6aa
Improves check description
gdavison e833428
Corrects `package` statement for `knownvalue`
gdavison 733069b
Adds `tfknownvalue.StringPtrExact`
gdavison 2893df9
Uses `tfknownvalue.StringPtrExact` for `aws_vpc`
gdavison 8b6a76a
Removes comment
gdavison 1856b77
Explicitly checks for excluded resources in `TestAccVPC_List_Filtered`
gdavison 11c11d5
Adds attribute `vpc_ids` to `aws_vpc`
gdavison 00cbce0
Tests mixing `vpc_ids` and `filter` in `aws_vpc`
gdavison b2157a8
Adds validator to exclude default VPC from `filter`
gdavison c0278a2
Filter out default VPC cloud-side
gdavison eecb25f
Adds `tfstatecheck.StateValue`
gdavison 5c792e1
Uses `tfstatecheck.StateValue` in `aws_vpc` tests
gdavison 3687d15
Allows `@Testing(plannableImportAction)` to be before `@Testing(impor…
gdavison a7a480e
Adds documentation for `aws_vpc`
gdavison 97bb24f
Uses fork of `github.com/hashicorp/terraform-plugin-testing`
gdavison 36e7967
Removes unneeded sleep in list tests
gdavison e1b97a6
Handles `NotFound` errors when reading `aws_vpc`
gdavison d6e7284
Adds logging
gdavison 6a237c4
Adds `tflint-ignore: terraform_unused_declarations`
gdavison cee7396
`go mod tidy`
gdavison d172e30
Updates Semgrep rule `setfield-without-assign` to support assigning a…
gdavison 8627358
Corrects documentation example
gdavison 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-log/tflog" | ||
| ) | ||
|
|
||
| func noAssignment() { | ||
| ctx := context.Background() | ||
|
|
||
| // ruleid: setfield-without-assign | ||
| tflog.SetField(ctx, "field", "value") | ||
| } | ||
|
|
||
| func assigned() { | ||
| ctx := context.Background() | ||
|
|
||
| // ok: setfield-without-assign | ||
| ctx = tflog.SetField(ctx, "field", "value") | ||
| } | ||
|
|
||
| func returnedContext() context.Context { | ||
| ctx := context.Background() | ||
|
|
||
| // ok: setfield-without-assign | ||
| return tflog.SetField(ctx, "field", "value") | ||
| } | ||
|
|
||
| func declareAndAssign_SameName() { | ||
| ctx := context.Background() | ||
|
|
||
| for i := 0; i < 1; i++ { | ||
| // ok: setfield-without-assign | ||
| ctx := tflog.SetField(ctx, "field", "value") | ||
| } | ||
| } | ||
|
|
||
| func declareAndAssign_Rename() { | ||
| outerCtx := context.Background() | ||
|
|
||
| for i := 0; i < 1; i++ { | ||
| // ok: setfield-without-assign | ||
| innerCtx := tflog.SetField(outerCtx, "field", "value") | ||
| } | ||
| } |
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
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
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
2 changes: 1 addition & 1 deletion
2
internal/acctest/knownvalue/regional_arn_regexp_ignore_account.go
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,46 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package knownvalue | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/knownvalue" | ||
| ) | ||
|
|
||
| var _ knownvalue.Check = stringPtrExact[string]{} | ||
|
|
||
| type stringPtrExact[T ~string] struct { | ||
| value *T | ||
| } | ||
|
|
||
| func (v stringPtrExact[T]) CheckValue(other any) error { | ||
| otherVal, ok := other.(string) | ||
|
|
||
| if !ok { | ||
| return fmt.Errorf("expected string value for StringPtrExact check, got: %T", other) | ||
| } | ||
|
|
||
| if otherVal != string(*v.value) { | ||
| return fmt.Errorf("expected value %s for StringPtrExact check, got: %s", *v.value, otherVal) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // String returns the string representation of the value. | ||
| func (v stringPtrExact[T]) String() string { | ||
| return string(*v.value) | ||
| } | ||
|
|
||
| // StringExact returns a Check for asserting equality between the | ||
| // supplied string and a value passed to the CheckValue method. | ||
| func StringPtrExact[T ~string](value *T) stringPtrExact[T] { | ||
| if value == nil { | ||
| panic("value must not be nil") | ||
| } | ||
| return stringPtrExact[T]{ | ||
| value: value, | ||
| } | ||
| } |
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,106 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package statecheck | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-testing/knownvalue" | ||
| "github.com/hashicorp/terraform-plugin-testing/statecheck" | ||
| "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" | ||
| ) | ||
|
|
||
| type stateValue struct { | ||
| resourceAddress string | ||
| attributePath tfjsonpath.Path | ||
| value *string | ||
| } | ||
|
|
||
| func StateValue() stateValue { | ||
| return stateValue{} | ||
| } | ||
|
|
||
| // GetStateValue sets the resource address and attribute path to check and stores the state value. | ||
| // Calls to GetStateValue occur before any TestStep is run. | ||
| func (v *stateValue) GetStateValue(resourceAddress string, attributePath tfjsonpath.Path) statecheck.StateCheck { | ||
| v.resourceAddress = resourceAddress | ||
| v.attributePath = attributePath | ||
|
|
||
| return newStateValueStateChecker(v) | ||
| } | ||
|
|
||
| // Value checks the stored state value against the provided value. | ||
| // Calls to Value occur before any TestStep is run. | ||
| func (v *stateValue) Value() knownvalue.Check { | ||
| return newStateValueKnownValueChecker(v) | ||
| } | ||
|
|
||
| type stateValueStateChecker struct { | ||
| base Base | ||
| stateValue *stateValue | ||
| } | ||
|
|
||
| func newStateValueStateChecker(stateValue *stateValue) stateValueStateChecker { | ||
| return stateValueStateChecker{ | ||
| base: NewBase(stateValue.resourceAddress), | ||
| stateValue: stateValue, | ||
| } | ||
| } | ||
|
|
||
| func (vc stateValueStateChecker) CheckState(ctx context.Context, request statecheck.CheckStateRequest, response *statecheck.CheckStateResponse) { | ||
| resource, ok := vc.base.ResourceFromState(request, response) | ||
| if !ok { | ||
| return | ||
| } | ||
|
|
||
| value, err := tfjsonpath.Traverse(resource.AttributeValues, vc.stateValue.attributePath) | ||
| if err != nil { | ||
| response.Error = err | ||
| return | ||
| } | ||
|
|
||
| stringVal, ok := value.(string) | ||
| if !ok { | ||
| response.Error = fmt.Errorf("expected string value for StateValue check, got: %T", value) | ||
| return | ||
| } | ||
|
|
||
| vc.stateValue.value = &stringVal | ||
| } | ||
|
|
||
| type stateValueKnownValueChecker struct { | ||
| stateValue *stateValue | ||
| } | ||
|
|
||
| func newStateValueKnownValueChecker(stateValue *stateValue) stateValueKnownValueChecker { | ||
| return stateValueKnownValueChecker{ | ||
| stateValue: stateValue, | ||
| } | ||
| } | ||
|
|
||
| func (vc stateValueKnownValueChecker) CheckValue(other any) error { | ||
| if vc.stateValue.value == nil { | ||
| return fmt.Errorf("state value has not been set") | ||
| } | ||
|
|
||
| otherVal, ok := other.(string) | ||
|
|
||
| if !ok { | ||
| return fmt.Errorf("expected string value for StateValue check, got: %T", other) | ||
| } | ||
|
|
||
| if otherVal != *vc.stateValue.value { | ||
| return fmt.Errorf("expected value %s for StateValue check, got: %s", *vc.stateValue.value, otherVal) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (vc stateValueKnownValueChecker) String() string { | ||
| if vc.stateValue.value == nil { | ||
| return "error: state value has not been set" | ||
| } | ||
| return fmt.Sprintf("%s (from state: %q %q)", *vc.stateValue.value, vc.stateValue.resourceAddress, vc.stateValue.attributePath.String()) | ||
| } |
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.
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.
Note to future selves - remove once hashicorp/terraform-plugin-testing#564 is merged.