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

costexplorer: Migrate to AWS SDK v2 #36773

Merged
merged 22 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3f5e993
costexplorer: Migrate to AWS SDK v2
mattburgess Apr 7, 2024
8e62dae
Merge branch 'main' into HEAD
ewbankkit Apr 11, 2024
a10a946
r/aws_ce_anomaly_monitor: Reduce visibility.
ewbankkit Apr 11, 2024
188fea4
r/aws_ce_anomaly_subscription: Reduce visibility.
ewbankkit Apr 11, 2024
ea7c8ae
r/aws_ce_cost_allocation_tag: Reduce visibility.
ewbankkit Apr 11, 2024
b03e532
r/aws_ce_cost_category: Reduce visibility.
ewbankkit Apr 11, 2024
1b73069
d/aws_ce_cost_category: Reduce visibility.
ewbankkit Apr 11, 2024
fead1d0
r/aws_ce_tags: Reduce visibility.
ewbankkit Apr 11, 2024
6a3a7a1
Add 'sdkv2.DataSourcePropertyFromResourceProperty'.
ewbankkit Apr 11, 2024
6670382
appmesh: Use 'sdkv2.DataSourcePropertyFromResourceProperty'.
ewbankkit Apr 11, 2024
db2aa75
Add 'sdkv2.DataSourceElemFromResourceElem'.
ewbankkit Apr 11, 2024
f521362
ce: Better schema sharing.
ewbankkit Apr 11, 2024
718f7e8
r/aws_ce_anomaly_monitor: Fix acceptance tests.
ewbankkit Apr 12, 2024
0d33f33
Acceptance test output:
ewbankkit Apr 12, 2024
dd6db4a
Fix semgrep 'ci.ce-in-var-name'.
ewbankkit Apr 12, 2024
b9241a9
r/aws_ce_anomaly_subscription: Fix acceptance tests.
ewbankkit Apr 12, 2024
2df7cf8
Acceptance test output:
ewbankkit Apr 12, 2024
71d159a
Acceptance test output:
ewbankkit Apr 12, 2024
e7512c7
Acceptance test output:
ewbankkit Apr 12, 2024
e1dfd41
Fix 'TestAccCECostCategory_effectiveStart'.
ewbankkit Apr 12, 2024
90eccfa
Acceptance test output:
ewbankkit Apr 12, 2024
c532936
Call 'testAccCheckCostAllocationTagDestroy'.
ewbankkit Apr 12, 2024
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
7 changes: 7 additions & 0 deletions .changelog/36773.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_ce_anomaly_monitor: Change `monitor_dimension` to [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew)
```

```release-note:bug
resource/aws_ce_anomaly_subscription: Change `account_id` to [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew)
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/connectcases v1.15.4
github.com/aws/aws-sdk-go-v2/service/controltower v1.13.4
github.com/aws/aws-sdk-go-v2/service/costandusagereportservice v1.23.4
github.com/aws/aws-sdk-go-v2/service/costexplorer v1.37.1
github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.4
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.4
github.com/aws/aws-sdk-go-v2/service/datasync v1.36.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ github.com/aws/aws-sdk-go-v2/service/controltower v1.13.4 h1:vUHPzud4ZEbPNCBxRsr
github.com/aws/aws-sdk-go-v2/service/controltower v1.13.4/go.mod h1:qwJIgEG0ASp7utTqwiagEW0LOE6AFsNzQL1oOWRsydU=
github.com/aws/aws-sdk-go-v2/service/costandusagereportservice v1.23.4 h1:MDEvMVWZZetTacemmH+Z7ScvQkOKxqkEQfFROo//G18=
github.com/aws/aws-sdk-go-v2/service/costandusagereportservice v1.23.4/go.mod h1:DSbQUgLN9rHicCWE2Wuu7yRNHT3oQvnOiPk3LAGZe9I=
github.com/aws/aws-sdk-go-v2/service/costexplorer v1.37.1 h1:xjhk+io+kPtDOG5RizvHlkGKET3dxRBzorLdPPkpZQc=
github.com/aws/aws-sdk-go-v2/service/costexplorer v1.37.1/go.mod h1:uLOg0o57AyQQhZGtUKIlcBJOKE53mO9bXKyrM9dFhy4=
github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.4 h1:gSO6kMlH4cXxBmZwTA1qngTVxt8Och7irFtNGrxIUEg=
github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.4/go.mod h1:UkyRWEyu3iT7oPmPri8xwPnKXqJQzSUDK9MOKq7xyZE=
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.4 h1:UBo3t3uliQIP3f8duZhmJ1Z62bz/j5o7LH8f/BTt1mU=
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.

63 changes: 63 additions & 0 deletions internal/sdkv2/schema.go
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 sdkv2

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// Adapted from https://github.com/hashicorp/terraform-provider-google/google/datasource_helpers.go. Thanks!

// DataSourcePropertyFromResourceProperty is a recursive func that
// converts an existing Resource property schema to a Datasource property schema.
// All schema elements are copied, but certain attributes are ignored or changed:
// - all attributes have Computed = true
// - all attributes have ForceNew, Required = false
// - Validation funcs and attributes (e.g. MaxItems) are not copied
func DataSourcePropertyFromResourceProperty(rs *schema.Schema) *schema.Schema {
ds := &schema.Schema{
Computed: true,
Description: rs.Description,
Type: rs.Type,
}

switch rs.Type {
case schema.TypeSet:
ds.Set = rs.Set
fallthrough
case schema.TypeList, schema.TypeMap:
// List & Set types are generally used for 2 cases:
// - a list/set of simple primitive values (e.g. list of strings)
// - a sub resource
// Maps are usually used for maps of simple primitives
switch elem := rs.Elem.(type) {
case *schema.Resource:
// handle the case where the Element is a sub-resource
ds.Elem = DataSourceElemFromResourceElem(elem)
case *schema.Schema:
// handle simple primitive case
ds.Elem = &schema.Schema{Type: elem.Type}
}
}

return ds
}

func DataSourceElemFromResourceElem(rs *schema.Resource) *schema.Resource {
ds := &schema.Resource{
Schema: DataSourceSchemaFromResourceSchema(rs.Schema),
}

return ds
}

func DataSourceSchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.Schema {
ds := make(map[string]*schema.Schema, len(rs))

for k, v := range rs {
ds[k] = DataSourcePropertyFromResourceProperty(v)
}

return ds
}
3 changes: 2 additions & 1 deletion internal/service/appmesh/gateway_route_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func DataSourceGatewayRoute() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceGatewayRouteSpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceGatewayRouteSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
"virtual_gateway_name": {
Type: schema.TypeString,
Expand Down
50 changes: 0 additions & 50 deletions internal/service/appmesh/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,53 +241,3 @@ func findMesh(ctx context.Context, conn *appmesh.AppMesh, input *appmesh.Describ

return output.Mesh, nil
}

// Adapted from https://github.com/hashicorp/terraform-provider-google/google/datasource_helpers.go. Thanks!
// TODO Move to a shared package.

// dataSourceSchemaFromResourceSchema is a recursive func that
// converts an existing Resource schema to a Datasource schema.
// All schema elements are copied, but certain attributes are ignored or changed:
// - all attributes have Computed = true
// - all attributes have ForceNew, Required = false
// - Validation funcs and attributes (e.g. MaxItems) are not copied
func dataSourceSchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.Schema {
ds := make(map[string]*schema.Schema, len(rs))

for k, v := range rs {
ds[k] = dataSourcePropertyFromResourceProperty(v)
}

return ds
}

func dataSourcePropertyFromResourceProperty(rs *schema.Schema) *schema.Schema {
ds := &schema.Schema{
Computed: true,
Description: rs.Description,
Type: rs.Type,
}

switch rs.Type {
case schema.TypeSet:
ds.Set = rs.Set
fallthrough
case schema.TypeList, schema.TypeMap:
// List & Set types are generally used for 2 cases:
// - a list/set of simple primitive values (e.g. list of strings)
// - a sub resource
// Maps are usually used for maps of simple primitives
switch elem := rs.Elem.(type) {
case *schema.Resource:
// handle the case where the Element is a sub-resource
ds.Elem = &schema.Resource{
Schema: dataSourceSchemaFromResourceSchema(elem.Schema),
}
case *schema.Schema:
// handle simple primitive case
ds.Elem = &schema.Schema{Type: elem.Type}
}
}

return ds
}
3 changes: 2 additions & 1 deletion internal/service/appmesh/mesh_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -47,7 +48,7 @@ func DataSourceMesh() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceMeshSpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceMeshSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/appmesh/route_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func DataSourceRoute() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceRouteSpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceRouteSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
"virtual_router_name": {
Type: schema.TypeString,
Expand Down
3 changes: 2 additions & 1 deletion internal/service/appmesh/virtual_gateway_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -50,7 +51,7 @@ func DataSourceVirtualGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceVirtualGatewaySpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceVirtualGatewaySpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/appmesh/virtual_node_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func DataSourceVirtualNode() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceVirtualNodeSpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceVirtualNodeSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/appmesh/virtual_router_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func DataSourceVirtualRouter() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceVirtualRouterSpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceVirtualRouterSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/service/appmesh/virtual_service_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func DataSourceVirtualService() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"spec": dataSourcePropertyFromResourceProperty(resourceVirtualServiceSpecSchema()),
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceVirtualServiceSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
},
}
Expand Down
Loading
Loading