Skip to content
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

Migrate wafv2 service to AWS Go SDKv2 #37264

Merged
merged 12 commits into from
May 9, 2024
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/transfer v1.47.3
github.com/aws/aws-sdk-go-v2/service/verifiedpermissions v1.13.2
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.6
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.48.4
github.com/aws/aws-sdk-go-v2/service/wellarchitected v1.30.1
github.com/aws/aws-sdk-go-v2/service/workspaces v1.39.1
github.com/aws/aws-sdk-go-v2/service/workspacesweb v1.18.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ github.com/aws/aws-sdk-go-v2/service/verifiedpermissions v1.13.2 h1:H4Z5fqtcfa9g
github.com/aws/aws-sdk-go-v2/service/verifiedpermissions v1.13.2/go.mod h1:DKtR1LdOqG21jCPD/b7zMxAFxpelWoGb65rNVTpBaXs=
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.6 h1:ZJzyuwG/oxo8Usglni0OzP9hCCiFqg5EDAwAWFZIy4Y=
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.7.6/go.mod h1:lwuOe4SF+wdRnUrcPt1tukhJCj4gklxBV6xlD03Uo/8=
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.48.4 h1:2UwmqMxMqrh/PeC9rlz622TcUMa4mhIJ9YjoZHSPEvQ=
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.48.4/go.mod h1:0NVabz9uKCHY8Y0NtuK4P79USdbbr4GiPA0Lmu1NCyc=
github.com/aws/aws-sdk-go-v2/service/wellarchitected v1.30.1 h1:wIDRr8lKqz+82N2Rimasu7CuqPLu+PdoVBZ/et1jOuo=
github.com/aws/aws-sdk-go-v2/service/wellarchitected v1.30.1/go.mod h1:MRT/P9Cwn+7xCCVpD1sTvUESiWMAc9hA+FooRsW5fe8=
github.com/aws/aws-sdk-go-v2/service/workspaces v1.39.1 h1:JF+4iTmn/qTQLZydN8ZFdnD7kp6pbV7noSgpla1HAyU=
Expand Down
9 changes: 5 additions & 4 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ import (
inspector2types "github.com/aws/aws-sdk-go-v2/service/inspector2/types"
"github.com/aws/aws-sdk-go-v2/service/ssoadmin"
ssoadmintypes "github.com/aws/aws-sdk-go-v2/service/ssoadmin/types"
"github.com/aws/aws-sdk-go-v2/service/wafv2"
wafv2types "github.com/aws/aws-sdk-go-v2/service/wafv2/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/directoryservice"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/outposts"
"github.com/aws/aws-sdk-go/service/wafv2"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -1262,12 +1263,12 @@ func PreCheckWAFV2CloudFrontScope(ctx context.Context, t *testing.T) {
PreCheckRegion(t, endpoints.CnNorthwest1RegionID)
}

conn := Provider.Meta().(*conns.AWSClient).WAFV2Conn(ctx)
conn := Provider.Meta().(*conns.AWSClient).WAFV2Client(ctx)
input := &wafv2.ListWebACLsInput{
Scope: aws.String(wafv2.ScopeCloudfront),
Scope: wafv2types.ScopeCloudfront,
}

_, err := conn.ListWebACLsWithContext(ctx, input)
_, err := conn.ListWebACLs(ctx, input)

if PreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ func ExpandInt32ValueList(configured []interface{}) []int32 {
})
}

// Takes the result of schema.Set of strings and returns a []int32
func ExpandInt32ValueSet(configured *schema.Set) []int32 {
return ExpandInt32ValueList(configured.List())
}

func FlattenInt32Set(set []*int32) *schema.Set {
return schema.NewSet(schema.HashInt, FlattenInt32List(set))
}

func FlattenInt32ValueSet(set []int32) *schema.Set {
return schema.NewSet(schema.HashInt, FlattenInt32ValueList(set))
}

// Takes the result of flatmap.Expand for an array of int64
// and returns a []*int64
func ExpandInt64List(configured []interface{}) []*int64 {
Expand Down Expand Up @@ -301,6 +314,15 @@ func FlattenFloat64List(list []*float64) []interface{} {
})
}

// Takes list of pointers to int32s. Expand to an array
// of raw ints and returns a []interface{}
// to keep compatibility w/ schema.NewSet
func FlattenInt32List(list []*int32) []interface{} {
return tfslices.ApplyToAll(list, func(v *int32) any {
return int(aws.Int32Value(v))
})
}

// Takes a string of resource attributes separated by the ResourceIdSeparator constant, an expected number of Id Parts, and a boolean specifying if empty parts are to be allowed
// Returns a list of the resource attributes strings used to construct the unique Id or an error message if the resource id does not parse properly
func ExpandResourceId(id string, partCount int, allowEmptyPart bool) ([]string, error) {
Expand Down
17 changes: 15 additions & 2 deletions internal/service/wafv2/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ package wafv2

// Exports for use in tests only.
var (
ListRuleGroupsPages = listRuleGroupsPages
ListWebACLsPages = listWebACLsPages
ResourceIPSet = resourceIPSet
ResourceRegexPatternSet = resourceRegexPatternSet
ResourceRuleGroup = resourceRuleGroup
ResourceWebACL = resourceWebACL
ResourceWebACLAssociation = resourceWebACLAssociation
ResourceWebACLLoggingConfiguration = resourceWebACLLoggingConfiguration

FindIPSetByThreePartKey = findIPSetByThreePartKey
FindLoggingConfigurationByARN = findLoggingConfigurationByARN
FindRegexPatternSetByThreePartKey = findRegexPatternSetByThreePartKey
FindRuleGroupByThreePartKey = findRuleGroupByThreePartKey
FindWebACLByResourceARN = findWebACLByResourceARN
FindWebACLByThreePartKey = findWebACLByThreePartKey
ListRuleGroupsPages = listRuleGroupsPages
ListWebACLsPages = listWebACLsPages
)