Skip to content

Commit

Permalink
Merge pull request #36773 from mattburgess/ce-awssdkv2-migration
Browse files Browse the repository at this point in the history
costexplorer: Migrate to AWS SDK v2
  • Loading branch information
ewbankkit committed Apr 12, 2024
2 parents e8774a0 + c532936 commit 70a5bc9
Show file tree
Hide file tree
Showing 35 changed files with 1,081 additions and 1,231 deletions.
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

0 comments on commit 70a5bc9

Please sign in to comment.