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

[Docs]: Config and example content for content tabs #33022

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 19 additions & 2 deletions docs/README.md
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
```
140 changes: 88 additions & 52 deletions docs/add-a-new-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Copy link
Member

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.

=== "aws-go-sdk-v2"
Copy link
Member

Choose a reason for hiding this comment

The 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 -->
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ theme:
features:
- navigation.instant
- content.tabs.link
- content.code.copy

plugins:
- search:
Expand All @@ -67,6 +68,8 @@ plugins:
markdown_extensions:
- pymdownx.highlight
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.inlinehilite
- toc:
permalink: "#"
Expand Down