Skip to content

Commit

Permalink
Merge pull request #39932 from hashicorp/d-purge-aws-sdk-go
Browse files Browse the repository at this point in the history
Remove AWS SDK for Go v1 references from contributor documentation
  • Loading branch information
ewbankkit authored Oct 29, 2024
2 parents 63ff69b + 412f8a9 commit a97254c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 344 deletions.
6 changes: 2 additions & 4 deletions docs/add-a-new-datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Each data source should be submitted for review in isolation, pull requests cont

If this is the first addition of a data source for a new service, please ensure the Service Client for the new service has been added and merged. See [Adding a new Service](add-a-new-service.md) for details.

Determine which version of the AWS SDK for Go the resource will be built upon. For more information and instructions on how to determine this choice, please read [AWS SDK for Go Versions](aws-go-sdk-versions.md)

## Steps to Add a Data Source

### Fork the Provider and Create a Feature Branch
Expand All @@ -19,9 +17,9 @@ For a new data source use a branch named `f-{datasource name}` for example: `f-e

### Create and Name the Data Source

See the [Naming Guide](naming.md#resources-and-data-sources) for details on how to name the new resource and the resource file. Not following the naming standards will cause extra delay as maintainers request that you make changes.
See the [Naming Guide](naming.md#resources-and-data-sources) for details on how to name the new data source and the data source file. Not following the naming standards will cause extra delay as maintainers request that you make changes.

Use the [skaff](skaff.md) provider scaffolding tool to generate new resource and test templates using your chosen name ensuring you provide the `v1` flag if you are targeting version 1 of the `aws-go-sdk`. Doing so will ensure that any boilerplate code, structural best practices and repetitive naming are done for you and always represent our most current standards.
Use the [skaff](skaff.md) provider scaffolding tool to generate new data source and test templates using your chosen name. Doing so will ensure that any boilerplate code, structural best practices and repetitive naming are done for you and always represent our most current standards.

### Fill out the Data Source Schema

Expand Down
10 changes: 1 addition & 9 deletions docs/add-a-new-region.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,28 @@ provider "aws" {

## Enabling Region Validation

Support for region validation requires that the provider has an updated AWS Go SDK dependency that includes the new region. These are added to the AWS Go SDK `aws/endpoints/defaults.go` file and generally noted in the AWS Go SDK `CHANGELOG` as `aws/endpoints: Updated Regions`. This also needs to be done in the core Terraform binary itself to enable it for the S3 backend. The provider currently takes a dependency on both v1 AND v2 of the AWS Go SDK, as we start to base new (and migrate) resources on v2. Many of the authentication and provider-level configuration interactions are also located in the aws-go-sdk-base library. As all of these things take direct dependencies and as a result there end up being quite a few places where these dependency updates need to be made.
Support for region validation requires that the provider has an updated [AWS SDK Go Base](aws-sdk-go-base.md) dependency that includes the new region. This also needs to be done in the core Terraform binary itself to enable it for the S3 backend. Many of the authentication and provider-level configuration interactions are also located in the `aws-go-sdk-base` library. As all of these things take direct dependencies and as a result there end up being quite a few places where these dependency updates need to be made.

### Update aws-go-sdk-base

[aws-go-sdk-base](https://github.com/hashicorp/aws-sdk-go-base)

- Update [aws-go-sdk](https://github.com/aws/aws-sdk-go)
- Update [aws-go-sdk-v2](https://github.com/aws/aws-sdk-go-v2)

### Update Terraform AWS Provider

[provider](https://github.com/hashicorp/terraform-provider-aws)

- Update [aws-go-sdk](https://github.com/aws/aws-sdk-go)
- Update [aws-go-sdk-v2](https://github.com/aws/aws-sdk-go-v2)
- Update [aws-go-sdk-base](https://github.com/hashicorp/aws-sdk-go-base)

### Update Terraform Core (S3 Backend)

[core](https://github.com/hashicorp/terraform)

- Update [aws-go-sdk](https://github.com/aws/aws-sdk-go)
- Update [aws-go-sdk-v2](https://github.com/aws/aws-sdk-go-v2)
- Update [aws-go-sdk-base](https://github.com/hashicorp/aws-sdk-go-base)

```shell
go get github.com/aws/aws-sdk-go@v#.#.#
go mod tidy
```

See the [Changelog Process](changelog-process.md) document for example changelog format.

## Update Region Specific values in static Data Sources
Expand Down
4 changes: 1 addition & 3 deletions docs/add-a-new-resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Each resource should be submitted for review in isolation. Pull requests contain

If this is the first resource for a new service, please ensure the Service Client for the new service has been added and merged. See [Adding a new Service](add-a-new-service.md) for details.

Determine which version of the AWS SDK for Go the resource will be built upon. For more information and instructions on how to determine this choice, please read [AWS SDK for Go Versions](aws-go-sdk-versions.md)

## Steps to Add a Resource

### Fork the provider and create a feature branch
Expand All @@ -21,7 +19,7 @@ For new resources use a branch named `f-{resource name}` for example: `f-ec2-vpc

See the [Naming Guide](naming.md#resources-and-data-sources) for details on how to name the new resource and the resource file. Not following the naming standards will cause extra delay as maintainers request that you make changes.

Use the [skaff](skaff.md) provider scaffolding tool to generate new resource and test templates using your chosen name ensuring you provide the `v1` flag if you are targeting version 1 of the `aws-go-sdk`. Doing so will ensure that any boilerplate code, structural best practices and repetitive naming are done for you and always represent our most current standards.
Use the [skaff](skaff.md) provider scaffolding tool to generate new resource and test templates using your chosen name. Doing so will ensure that any boilerplate code, structural best practices and repetitive naming are done for you and always represent our most current standards.

### Fill out the Resource Schema

Expand Down
110 changes: 35 additions & 75 deletions docs/add-a-new-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ If an AWS service must be created in a non-standard way, for example, the servic

1. Add a file `internal/<service>/service_package.go` that contains an API client factory function, for example:

=== "AWS Go SDK V2 (Preferred)"

```go
package costoptimizationhub

Expand Down Expand Up @@ -112,82 +110,44 @@ If an AWS service must be created in a non-standard way, for example, the servic
}
```

=== "AWS Go SDK V1"

```go
package globalaccelerator

import (
"context"

aws_sdkv1 "github.com/aws/aws-sdk-go/aws"
endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints"
session_sdkv1 "github.com/aws/aws-sdk-go/aws/session"
globalaccelerator_sdkv1 "github.com/aws/aws-sdk-go/service/globalaccelerator"
)

// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API.
func (p *servicePackage) NewConn(ctx context.Context) (*globalaccelerator_sdkv1.GlobalAccelerator, error) {
sess := p.config["session"].(*session_sdkv1.Session)

cfg := aws.Config{}

if endpoint := config[names.AttrEndpoint].(string); endpoint != "" {
tflog.Debug(ctx, "setting endpoint", map[string]any{
"tf_aws.endpoint": endpoint,
})
cfg.Endpoint = aws.String(endpoint)
} else {
cfg.EndpointResolver = newEndpointResolverSDKv1(ctx)
}

// Force "global" services to correct Regions.
if config["partition"].(string) == endpoints.AwsPartitionID {
if aws.StringValue(cfg.Region) != endpoints.UsWest2RegionID {
tflog.Info(ctx, "overriding region", map[string]any{
"original_region": aws.StringValue(cfg.Region),
"override_region": endpoints.UsWest2RegionID,
})
cfg.Region = aws.String(endpoints.UsWest2RegionID)
}
}

return globalaccelerator_sdkv1.New(sess.Copy(config)), nil
}
```

## Customizing a new Service Client

If an AWS service must be customized after creation, for example, retry handling must be changed, then:

1. Add a file `internal/<service>/service_package.go` that contains an API client customization function, for example:

=== "AWS Go SDK V1"

```go
package chime

import (
"context"

aws_sdkv1 "github.com/aws/aws-sdk-go/aws"
request_sdkv1 "github.com/aws/aws-sdk-go/aws/request"
chime_sdkv1 "github.com/aws/aws-sdk-go/service/chime"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
)

// CustomizeConn customizes a new AWS SDK for Go v1 client for this service package's AWS API.
func (p *servicePackage) CustomizeConn(ctx context.Context, conn *chime_sdkv1.Chime) (*chime_sdkv1.Chime, error) {
conn.Handlers.Retry.PushBack(func(r *request_sdkv1.Request) {
// When calling CreateVoiceConnector across multiple resources,
// the API can randomly return a BadRequestException without an explanation
if r.Operation.Name == "CreateVoiceConnector" {
if tfawserr.ErrMessageContains(r.Error, chime_sdkv1.ErrCodeBadRequestException, "Service received a bad request") {
r.Retryable = aws_sdkv1.Bool(true)
}
}
})

return conn, nil
}
```
```go
package shield
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/shield"
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-provider-aws/names"
)
// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API.
func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*shield.Client, error) {
cfg := *(config["aws_sdkv2_config"].(*aws.Config))
return shield.NewFromConfig(cfg,
shield.WithEndpointResolverV2(newEndpointResolverV2()),
withBaseEndpoint(config[names.AttrEndpoint].(string)),
func(o *shield.Options) {
// Force "global" services to correct Regions.
if config["partition"].(string) == endpoints.AwsPartitionID {
if cfg.Region != names.USEast1RegionID {
tflog.Info(ctx, "overriding region", map[string]any{
"original_region": cfg.Region,
"override_region": names.USEast1RegionID,
})
o.Region = names.USEast1RegionID
}
}
},
), nil
}
```
9 changes: 4 additions & 5 deletions docs/adding-a-tag-resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ Adding a tag resource, similar to the `aws_ecs_tag` resource, has its own implem
- Create `internal/service/{service}/tag_gen_test.go` with initial acceptance testing similar to the following (where the parent resource is simple to provision):

```go

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/{Service}"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAcc{Service}Tag_basic(t *testing.T) {
Expand All @@ -26,7 +25,7 @@ func TestAcc{Service}Tag_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, {Service}.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.{Service}ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheck{Service}TagDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestAcc{Service}Tag_disappears(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, {Service}.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.{Service}ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheck{Service}TagDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -77,7 +76,7 @@ func TestAcc{Service}Tag_Value(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, {Service}.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.{Service}ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheck{Service}TagDestroy(ctx),
Steps: []resource.TestStep{
Expand Down
46 changes: 0 additions & 46 deletions docs/aws-go-sdk-versions.md

This file was deleted.

12 changes: 6 additions & 6 deletions docs/data-handling-and-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ Define FLatten and EXpand (i.e., flex) functions at the _most local level_ possi
// ...

if v := apiObject.NestedAttributeName; v != nil {
tfMap["nested_attribute_name"] = aws.BoolValue(v)
tfMap["nested_attribute_name"] = aws.ToBool(v)
}

// ...
Expand Down Expand Up @@ -1238,7 +1238,7 @@ Define FLatten and EXpand (i.e., flex) functions at the _most local level_ possi
// ...

if v := apiObject.NestedAttributeName; v != nil {
tfMap["nested_attribute_name"] = aws.Float64Value(v)
tfMap["nested_attribute_name"] = aws.ToFloat64(v)
}

// ...
Expand Down Expand Up @@ -1297,7 +1297,7 @@ Define FLatten and EXpand (i.e., flex) functions at the _most local level_ possi
// ...

if v := apiObject.NestedAttributeName; v != nil {
tfMap["nested_attribute_name"] = aws.Int64Value(v)
tfMap["nested_attribute_name"] = aws.ToInt64(v)
}

// ...
Expand Down Expand Up @@ -1712,7 +1712,7 @@ Define FLatten and EXpand (i.e., flex) functions at the _most local level_ possi
// ...

if v := apiObject.NestedAttributeName; v != nil {
tfMap["nested_attribute_name"] = aws.StringValue(v)
tfMap["nested_attribute_name"] = aws.ToString(v)
}

// ...
Expand Down Expand Up @@ -1788,7 +1788,7 @@ Define FLatten and EXpand (i.e., flex) functions at the _most local level_ possi
// ...

if v := apiObject.NestedAttributeName; v != nil {
tfMap["nested_attribute_name"] = aws.TimeValue(v).Format(time.RFC3339)
tfMap["nested_attribute_name"] = aws.ToTime(v).Format(time.RFC3339)
}

// ...
Expand Down Expand Up @@ -1873,7 +1873,7 @@ This helps prevent an immediate plan difference after resource import unless the
Below is a listing of relevant terms and descriptions for data handling and conversion in the Terraform AWS Provider to establish common conventions throughout this documentation.
This list is not exhaustive of all concepts of Terraform Plugins, the Terraform AWS Provider, or the data handling that occurs during Terraform runs, but these should generally provide enough context about the topics discussed here.

- **AWS Go SDK**: Library that converts Go code into AWS Service API compatible operations and data types. See [AWS SDK For Go Versions](aws-go-sdk-versions.md) for information on which version to use.
- **AWS Go SDK**: Library that converts Go code into AWS Service API compatible operations and data types.
- **AWS Go SDK Model**: AWS Go SDK compatible format of AWS Service API Model.
- **AWS Go SDK Service**: AWS Service API Go code generated from the AWS Go SDK Model. Generated by the AWS Go SDK code.
- **AWS Service API**: Logical boundary of an AWS service by API endpoint. Some large AWS services may be marketed with many different product names under the same service API (e.g., VPC functionality is part of the EC2 API) and vice-versa where some services may be marketed with one product name but are split into multiple service APIs (e.g., Single Sign-On functionality is split into the Identity Store and SSO Admin APIs).
Expand Down
Loading

0 comments on commit a97254c

Please sign in to comment.