Skip to content
Merged
Show file tree
Hide file tree
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 Oct 3, 2025
f117086
Corrects `aws_iam_role` List Resource factory name
gdavison Oct 3, 2025
2d8b6d8
Adds check for corresponding resource type when generating list resou…
gdavison Oct 3, 2025
bdc6380
Factors out reading `aws_vpc`
gdavison Oct 3, 2025
077b4e2
Removes duplicate `VPCVPC` in generated VPC tests
gdavison Oct 3, 2025
e3adf45
Adds `aws_vpc` List Resource
gdavison Oct 4, 2025
a08a1a4
Adds region override for `aws_vpc`
gdavison Oct 4, 2025
535702c
Adds test for `aws_vpc` `filter`
gdavison Oct 6, 2025
31fbd0e
Adds test to validate that default VPC is not included
gdavison Oct 6, 2025
8f1547f
Includes `querycheck.ExpectNoIdentity`
gdavison Oct 6, 2025
93b442b
Validates that default VPC is not included in results
gdavison Oct 6, 2025
d0be6aa
Improves check description
gdavison Oct 6, 2025
e833428
Corrects `package` statement for `knownvalue`
gdavison Oct 6, 2025
733069b
Adds `tfknownvalue.StringPtrExact`
gdavison Oct 6, 2025
2893df9
Uses `tfknownvalue.StringPtrExact` for `aws_vpc`
gdavison Oct 6, 2025
8b6a76a
Removes comment
gdavison Oct 6, 2025
1856b77
Explicitly checks for excluded resources in `TestAccVPC_List_Filtered`
gdavison Oct 6, 2025
11c11d5
Adds attribute `vpc_ids` to `aws_vpc`
gdavison Oct 6, 2025
00cbce0
Tests mixing `vpc_ids` and `filter` in `aws_vpc`
gdavison Oct 6, 2025
b2157a8
Adds validator to exclude default VPC from `filter`
gdavison Oct 6, 2025
c0278a2
Filter out default VPC cloud-side
gdavison Oct 7, 2025
eecb25f
Adds `tfstatecheck.StateValue`
gdavison Oct 7, 2025
5c792e1
Uses `tfstatecheck.StateValue` in `aws_vpc` tests
gdavison Oct 7, 2025
3687d15
Allows `@Testing(plannableImportAction)` to be before `@Testing(impor…
gdavison Oct 7, 2025
a7a480e
Adds documentation for `aws_vpc`
gdavison Oct 8, 2025
97bb24f
Uses fork of `github.com/hashicorp/terraform-plugin-testing`
gdavison Oct 8, 2025
36e7967
Removes unneeded sleep in list tests
gdavison Oct 9, 2025
e1b97a6
Handles `NotFound` errors when reading `aws_vpc`
gdavison Oct 9, 2025
d6e7284
Adds logging
gdavison Oct 10, 2025
6a237c4
Adds `tflint-ignore: terraform_unused_declarations`
gdavison Oct 10, 2025
cee7396
`go mod tidy`
gdavison Oct 10, 2025
d172e30
Updates Semgrep rule `setfield-without-assign` to support assigning a…
gdavison Oct 10, 2025
8627358
Corrects documentation example
gdavison Oct 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .ci/semgrep/tflog/tflog.go
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")
}
}
2 changes: 1 addition & 1 deletion .ci/semgrep/tflog/tflog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ rules:
message: The return value of "tflog.SetField" must be used
patterns:
- pattern: tflog.SetField(...)
- pattern-not-inside: $CTX = tflog.SetField($CTX, ...)
- pattern-not-inside: $CTX1 = tflog.SetField($CTX2, ...)
- pattern-not-inside: return tflog.SetField($CTX, ...)
severity: ERROR
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/pquerna/otp v1.5.0
github.com/shopspring/decimal v1.4.0
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.63.0
go.opentelemetry.io/otel v1.38.0
golang.org/x/crypto v0.43.0
golang.org/x/text v0.30.0
golang.org/x/tools v0.38.0
Expand Down Expand Up @@ -370,8 +372,6 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/zclconf/go-cty v1.17.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.63.0 // indirect
go.opentelemetry.io/otel v1.38.0 // indirect
go.opentelemetry.io/otel/metric v1.38.0 // indirect
go.opentelemetry.io/otel/trace v1.38.0 // indirect
golang.org/x/exp v0.0.0-20220921023135-46d9e7742f1e // indirect
Expand All @@ -386,3 +386,5 @@ require (
)

replace github.com/hashicorp/terraform-plugin-log => github.com/gdavison/terraform-plugin-log v0.0.0-20230928191232-6c653d8ef8fb

replace github.com/hashicorp/terraform-plugin-testing => github.com/gdavison/terraform-plugin-testing v0.0.0-20251008214752-cb22fd14f84d
Copy link
Member

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.

4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/gdavison/terraform-plugin-log v0.0.0-20230928191232-6c653d8ef8fb h1:HM67IMNxlkqGxAM5ymxMg2ANCcbL4oEr5cy+tGZ6fNo=
github.com/gdavison/terraform-plugin-log v0.0.0-20230928191232-6c653d8ef8fb/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/gdavison/terraform-plugin-testing v0.0.0-20251008214752-cb22fd14f84d h1:m3Al87LjSaNb/GWqj//HUPwYlkhxTpYO7Z5nlSF3dpY=
github.com/gdavison/terraform-plugin-testing v0.0.0-20251008214752-cb22fd14f84d/go.mod h1:LEK/JDcSM5eupLL8D0j/CIarlOTrl2wSmQE20mX/xSU=
github.com/gertd/go-pluralize v0.2.1 h1:M3uASbVjMnTsPb0PNqg+E/24Vwigyo/tvyMTtAlLgiA=
github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkHVpZvoOp8zk=
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
Expand Down Expand Up @@ -685,8 +687,6 @@ github.com/hashicorp/terraform-plugin-mux v0.21.0 h1:QsEYnzSD2c3zT8zUrUGqaFGhV/Z
github.com/hashicorp/terraform-plugin-mux v0.21.0/go.mod h1:Qpt8+6AD7NmL0DS7ASkN0EXpDQ2J/FnnIgeUr1tzr5A=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1 h1:mlAq/OrMlg04IuJT7NpefI1wwtdpWudnEmjuQs04t/4=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.38.1/go.mod h1:GQhpKVvvuwzD79e8/NZ+xzj+ZpWovdPAe8nfV/skwNU=
github.com/hashicorp/terraform-plugin-testing v1.14.0-beta.1 h1:caWmY2Fv/KgDAXU7IVjcBDfIdmr/n6VRYhCLxNmlaXs=
github.com/hashicorp/terraform-plugin-testing v1.14.0-beta.1/go.mod h1:jVm3pD9uQAT0X2RSEdcqjju2bCGv5f73DGZFU4v7EAU=
github.com/hashicorp/terraform-registry-address v0.4.0 h1:S1yCGomj30Sao4l5BMPjTGZmCNzuv7/GDTDX99E9gTk=
github.com/hashicorp/terraform-registry-address v0.4.0/go.mod h1:LRS1Ay0+mAiRkUyltGT+UHWkIqTFvigGn/LbMshfflE=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down
4 changes: 2 additions & 2 deletions internal/acctest/knownvalue/account_id.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import (
"context"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (v accountID) CheckValue(other any) error {

// String returns the string representation of the value.
func (v accountID) String() string {
return "Who Knows"
return "Account ID"
}

func AccountID() knownvalue.Check {
Expand Down
2 changes: 1 addition & 1 deletion internal/acctest/knownvalue/global_arn_exact.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion internal/acctest/knownvalue/global_arn_regexp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion internal/acctest/knownvalue/regional_arn_exact.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion internal/acctest/knownvalue/regional_arn_regexp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import (
"fmt"
Expand Down
46 changes: 46 additions & 0 deletions internal/acctest/knownvalue/string_ptr_exact.go
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,
}
}
2 changes: 1 addition & 1 deletion internal/acctest/knownvalue/stringable_value.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package statecheck
package knownvalue

import "github.com/hashicorp/terraform-plugin-testing/knownvalue"

Expand Down
106 changes: 106 additions & 0 deletions internal/acctest/statecheck/state_value.go
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())
}
Loading
Loading