Skip to content

Commit

Permalink
d/aws_iam_openid_connect_provider: Embrace Context (hashicorp#15090).
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Feb 17, 2022
1 parent d2405a7 commit f97a83f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/service/iam/openid_connect_provider_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package iam

import (
"context"
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
Expand All @@ -16,7 +16,8 @@ import (

func DataSourceOpenIDConnectProvider() *schema.Resource {
return &schema.Resource{
Read: dataSourceOpenIDConnectProviderRead,
ReadWithoutTimeout: dataSourceOpenIDConnectProviderRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -48,7 +49,7 @@ func DataSourceOpenIDConnectProvider() *schema.Resource {
}
}

func dataSourceOpenIDConnectProviderRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceOpenIDConnectProviderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).IAMConn
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

Expand All @@ -59,21 +60,21 @@ func dataSourceOpenIDConnectProviderRead(d *schema.ResourceData, meta interface{
} else if v, ok := d.GetOk("url"); ok {
url := v.(string)

oidcpEntry, err := dataSourceGetOpenIDConnectProviderByURL(context.Background(), conn, url)
oidcpEntry, err := dataSourceGetOpenIDConnectProviderByURL(ctx, conn, url)
if err != nil {
return fmt.Errorf("error finding IAM OIDC Provider by url (%s): %w", url, err)
return diag.Errorf("error finding IAM OIDC Provider by url (%s): %s", url, err)
}

if oidcpEntry == nil {
return fmt.Errorf("error finding IAM OIDC Provider by url (%s): not found", url)
return diag.Errorf("error finding IAM OIDC Provider by url (%s): not found", url)
}
input.OpenIDConnectProviderArn = oidcpEntry.Arn
}

resp, err := conn.GetOpenIDConnectProvider(input)
resp, err := conn.GetOpenIDConnectProviderWithContext(ctx, input)

if err != nil {
return fmt.Errorf("error reading IAM OIDC Provider: %w", err)
return diag.Errorf("error reading IAM OIDC Provider: %s", err)
}

d.SetId(aws.StringValue(input.OpenIDConnectProviderArn))
Expand All @@ -83,7 +84,7 @@ func dataSourceOpenIDConnectProviderRead(d *schema.ResourceData, meta interface{
d.Set("thumbprint_list", flex.FlattenStringList(resp.ThumbprintList))

if err := d.Set("tags", KeyValueTags(resp.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
return diag.Errorf("error setting tags: %s", err)
}

return nil
Expand Down

0 comments on commit f97a83f

Please sign in to comment.