Skip to content

Commit

Permalink
Updates documentation for manually-configured service clients
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Jun 20, 2024
1 parent eccf56d commit 3e4f772
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
46 changes: 35 additions & 11 deletions docs/add-a-new-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,22 @@ If an AWS service must be created in a non-standard way, for example, the servic
func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*costoptimizationhub.Client, error) {
cfg := *(config["aws_sdkv2_config"].(*aws.Config))

return costoptimizationhub.NewFromConfig(cfg, func(o *costoptimizationhub.Options) {
if endpoint := config["endpoint"].(string); endpoint != "" {
o.BaseEndpoint = aws.String(endpoint)
} else if config["partition"].(string) == names.StandardPartitionID {
// Cost Optimization Hub endpoint is available only in us-east-1 Region.
o.Region = names.USEast1RegionID
}
}), nil
return costoptimizationhub.NewFromConfig(cfg,
costoptimizationhub.WithEndpointResolverV2(newEndpointResolverSDKv2()),
withBaseEndpoint(config[names.AttrEndpoint].(string)),
func(o *costoptimizationhub.Options) {
if config["partition"].(string) == names.StandardPartitionID {
// Cost Optimization Hub endpoint is available only in us-east-1 Region.
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
}
```

Expand All @@ -121,11 +129,27 @@ If an AWS service must be created in a non-standard way, for example, the servic
// 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))}

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 p.config["partition"].(string) == endpoints_sdkv1.AwsPartitionID {
config.Region = aws_sdkv1.String(endpoints_sdkv1.UsWest2RegionID)
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
Expand Down
24 changes: 14 additions & 10 deletions docs/retries-and-waiters.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,20 @@ When custom service client configurations are applied, these will be defined in
func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*s3_sdkv2.Client, error) {
cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config))

return s3_sdkv2.NewFromConfig(cfg, func(o *s3_sdkv2.Options) {
// ..other configuration..

o.Retryer = conns.AddIsErrorRetryables(cfg.Retryer().(aws_sdkv2.RetryerV2), retry_sdkv2.IsErrorRetryableFunc(func(err error) aws_sdkv2.Ternary {
if tfawserr_sdkv2.ErrMessageContains(err, errCodeOperationAborted, "A conflicting conditional operation is currently in progress against this resource. Please try again.") {
return aws_sdkv2.TrueTernary
}
return aws_sdkv2.UnknownTernary // Delegate to configured Retryer.
}))
}), nil
return s3_sdkv2.NewFromConfig(cfg,
s3.WithEndpointResolverV2(newEndpointResolverSDKv2()),
withBaseEndpoint(config[names.AttrEndpoint].(string)),
func(o *s3_sdkv2.Options) {
// ..other configuration..
o.Retryer = conns.AddIsErrorRetryables(cfg.Retryer().(aws_sdkv2.RetryerV2), retry_sdkv2.IsErrorRetryableFunc(func(err error) aws_sdkv2.Ternary {
if tfawserr_sdkv2.ErrMessageContains(err, errCodeOperationAborted, "A conflicting conditional operation is currently in progress against this resource. Please try again.") {
return aws_sdkv2.TrueTernary
}
return aws_sdkv2.UnknownTernary // Delegate to configured Retryer.
}))
},
), nil
}
```

Expand Down

0 comments on commit 3e4f772

Please sign in to comment.