-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
[Docs]: Config and example content for content tabs #33022
Merged
+110
−54
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
# Documentation | ||
|
||
- [Using the AWS Provider](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | ||
- [AWS Provider contributing guide](https://hashicorp.github.io/terraform-provider-aws/) | ||
This directory contains documentation for the [Terraform AWS Provider Contributor Guide](https://hashicorp.github.io/terraform-provider-aws/). Resource and data source documentation is located in the [`website`](../website/) directory and available in the [Terraform Registry](https://registry.terraform.io/providers/hashicorp/aws/latest/docs). | ||
|
||
## Local Development | ||
|
||
To serve the contributing guide locally, [`mkdocs`](https://www.mkdocs.org/user-guide/installation/) and the [`mkdocs-material`](https://github.com/squidfunk/mkdocs-material#quick-start) extension must be installed. Both require Python and `pip`. | ||
|
||
```console | ||
% pip3 install mkdocs | ||
``` | ||
|
||
```console | ||
% pip3 install mkdocs-material | ||
``` | ||
|
||
Once installed, the documentation can be served from the root directory: | ||
|
||
```console | ||
% mkdocs serve | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,62 +51,98 @@ If an AWS service must be created in a non-standard way, for example the service | |
|
||
1. Add a file `internal/<service>/service_package.go` that contains an API client factory function, for example: | ||
|
||
```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) | ||
config := &aws_sdkv1.Config{Endpoint: aws_sdkv1.String(p.config["endpoint"].(string))} | ||
|
||
// Force "global" services to correct Regions. | ||
if p.config["partition"].(string) == endpoints_sdkv1.AwsPartitionID { | ||
config.Region = aws_sdkv1.String(endpoints_sdkv1.UsWest2RegionID) | ||
} | ||
|
||
return globalaccelerator_sdkv1.New(sess.Copy(config)), nil | ||
} | ||
``` | ||
<!-- markdownlint-disable code-block-style --> | ||
=== "aws-go-sdk-v2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched this particular example to just AWS SDK Go V1/V2 as this section of code is the same regardless of whether Terraform Plugin SDK or Framework is used. |
||
|
||
```go | ||
package route53domains | ||
|
||
import ( | ||
"context" | ||
|
||
aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" | ||
route53domains_sdkv2 "github.com/aws/aws-sdk-go-v2/service/route53domains" | ||
endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" | ||
) | ||
|
||
// 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) (*route53domains_sdkv2.Client, error) { | ||
cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) | ||
|
||
return route53domains_sdkv2.NewFromConfig(cfg, func(o *route53domains_sdkv2.Options) { | ||
if endpoint := config["endpoint"].(string); endpoint != "" { | ||
o.BaseEndpoint = aws_sdkv2.String(endpoint) | ||
} else if config["partition"].(string) == endpoints_sdkv1.AwsPartitionID { | ||
// Route 53 Domains is only available in AWS Commercial us-east-1 Region. | ||
o.Region = endpoints_sdkv1.UsEast1RegionID | ||
} | ||
}), nil | ||
} | ||
``` | ||
|
||
=== "aws-go-sdk" | ||
|
||
```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) | ||
config := &aws_sdkv1.Config{Endpoint: aws_sdkv1.String(p.config["endpoint"].(string))} | ||
|
||
// Force "global" services to correct Regions. | ||
if p.config["partition"].(string) == endpoints_sdkv1.AwsPartitionID { | ||
config.Region = aws_sdkv1.String(endpoints_sdkv1.UsWest2RegionID) | ||
} | ||
|
||
return globalaccelerator_sdkv1.New(sess.Copy(config)), nil | ||
} | ||
``` | ||
<!-- markdownlint-enable code-block-style --> | ||
|
||
## 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: | ||
|
||
```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 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 | ||
} | ||
``` | ||
<!-- markdownlint-disable code-block-style --> | ||
=== "aws-go-sdk" | ||
|
||
```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 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 | ||
} | ||
``` | ||
<!-- markdownlint-enable code-block-style --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to disable this linter check inline rather than globally for now as the code block checking is valuable for the website docs. If this becomes too burdensome for the contributor documentation we can extend the root markdownlint configuration with a second file stored in the
docs/
subfolder and disable it globally there instead.