Skip to content

Commit

Permalink
config and example for content tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
breathingdust committed Aug 15, 2023
1 parent a4393f9 commit ac68d78
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 25 deletions.
135 changes: 110 additions & 25 deletions docs/add-a-new-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,116 @@ 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
}
```
=== "framework / aws-go-sdk-v2"

```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
}
```

=== "framework / aws-go-sdk"

```go
package accessanalyzer

import (
"context"

aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws"
accessanalyzer_sdkv2 "github.com/aws/aws-sdk-go-v2/service/accessanalyzer"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/types"
"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) (*accessanalyzer_sdkv2.Client, error) {
cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config))

return accessanalyzer_sdkv2.NewFromConfig(cfg, func(o *accessanalyzer_sdkv2.Options) {
if endpoint := config["endpoint"].(string); endpoint != "" {
o.EndpointResolver = accessanalyzer_sdkv2.EndpointResolverFromURL(endpoint)
}
}), nil
}
```

=== "sdk / aws-go-sdk-v2"

```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
}
```

=== "sdk / 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
}
```

## Customizing a new Service Client

Expand Down
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ theme:
features:
- navigation.instant
- content.tabs.link
- content.code.copy

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

0 comments on commit ac68d78

Please sign in to comment.