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

KMS: migrate to AWS SDK v2 #37092

Merged
merged 40 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
076b89b
`kms`: migrate to AWS SDK v2
aristosvo Apr 25, 2024
0cbae59
Revert "`kms`: migrate to AWS SDK v2"
ewbankkit May 1, 2024
53d15b7
Merge branch 'main' into HEAD
ewbankkit May 1, 2024
8a2d87d
kms: Use AWS SDK for Go v2.
ewbankkit May 1, 2024
d472dc7
kms: Generate AWS SDK for Go v2 tagging code.
ewbankkit May 1, 2024
e7c5cf2
Run 'make gen'.
ewbankkit May 1, 2024
91f8de1
run 'go get github.com/aws/aws-sdk-go-v2/service/[email protected] && go mo…
ewbankkit May 1, 2024
2011fb4
r/aws_kms_alias: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
db9d519
d/aws_kms_alias: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
4d15fcf
r/aws_kms_ciphertext: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
1f61787
d/aws_kms_ciphertext: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
e4ee69e
r/aws_kms_custom_key_store: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
52303fc
d/aws_kms_custom_key_store: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
2f4cfe0
r/aws_kms_key: Start to migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
c1dd31f
Merge branch 'main' into HEAD
ewbankkit May 2, 2024
9f1664e
r/aws_kms_key: Migrate to AWS SDK for Go v2.
ewbankkit May 2, 2024
726e903
'findDefaultKey' -> 'findDefaultKeyARNForService'.
ewbankkit May 3, 2024
9fbe469
kms: Reduce visibility of some timeouts.
ewbankkit May 3, 2024
84a435b
'findKey' -> 'findKeyInfo'.
ewbankkit May 3, 2024
a50b9ea
d/aws_kms_key: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
d4992a9
kms: Reduce visibility of diff suppress.
ewbankkit May 3, 2024
f4f41b0
Fix d/aws_kms_alias.
ewbankkit May 3, 2024
2844555
kms: Reduce visibility of validators.
ewbankkit May 3, 2024
1897d4f
r/aws_kms_external_key: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
c837f55
r/aws_kms_grant: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
b5a6926
r/aws_kms_policy: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
6ee058c
d/aws_kms_public_key: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
6939249
r/aws_kms_replica_key: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
05a1e29
r/aws_kms_replica_external_key: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
80b77a8
d/aws_kms_secrets: Migrate to AWS SDK for Go v2.
ewbankkit May 3, 2024
3a4a255
kms: Migrate sweepers to AWS SDK for Go v2.
ewbankkit May 3, 2024
4e3317c
kms: Migrate cross service package calls to AWS SDK for Go v2.
ewbankkit May 3, 2024
4995bf5
kms: More visibility reduction.
ewbankkit May 3, 2024
0e15fe9
kms: Even more visibility reduction.
ewbankkit May 3, 2024
8706873
Fix semgrep 'ci.kms-in-var-name'.
ewbankkit May 3, 2024
92653bc
Merge branch 'main' into HEAD
ewbankkit May 3, 2024
21aebcb
r/aws_kms_key_policy: Fix "NotFoundException: Invalid keyId 'KMS Key …
ewbankkit May 3, 2024
0299e64
Fix 'TestAccKMSKeyPolicy_iamRole' and 'TestAccKMSKeyPolicy_iamService…
ewbankkit May 3, 2024
7af39dd
Fix golangci-lint 'unparam'.
ewbankkit May 3, 2024
1e07b5e
Fix golangci-lint 'gomnd'.
ewbankkit May 3, 2024
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
3 changes: 3 additions & 0 deletions .changelog/37092.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_kms_custom_key_store: Change `trust_anchor_certificate` to [ForceNew](https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#forcenew)
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/kendra v1.50.1
github.com/aws/aws-sdk-go-v2/service/keyspaces v1.10.4
github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4
github.com/aws/aws-sdk-go-v2/service/kms v1.31.0
github.com/aws/aws-sdk-go-v2/service/lakeformation v1.32.0
github.com/aws/aws-sdk-go-v2/service/lambda v1.54.0
github.com/aws/aws-sdk-go-v2/service/launchwizard v1.3.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ github.com/aws/aws-sdk-go-v2/service/keyspaces v1.10.4 h1:b8U8xht0BhuuzDlKUq/QzB
github.com/aws/aws-sdk-go-v2/service/keyspaces v1.10.4/go.mod h1:K0uQVx8xnUBI3CudcERApORx5cJrVUDew1K3deRDjLU=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4 h1:Oe8awBiS/iitcsRJB5+DHa3iCxoA0KwJJf0JNrYMINY=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4/go.mod h1:RCZCSFbieSgNG1RKegO26opXV4EXyef/vNBVJsUyHuw=
github.com/aws/aws-sdk-go-v2/service/kms v1.31.0 h1:yl7wcqbisxPzknJVfWTLnK83McUvXba+pz2+tPbIUmQ=
github.com/aws/aws-sdk-go-v2/service/kms v1.31.0/go.mod h1:2snWQJQUKsbN66vAawJuOGX7dr37pfOq9hb0tZDGIqQ=
github.com/aws/aws-sdk-go-v2/service/lakeformation v1.32.0 h1:X7ydA78B8lmKVgGS3XEVUsgMKMHoYhmIwoxl3U2S2wg=
github.com/aws/aws-sdk-go-v2/service/lakeformation v1.32.0/go.mod h1:0xTSto0XwDuPvY7P3XoEwOLH7sr5EzehNvxCoBaeuPU=
github.com/aws/aws-sdk-go-v2/service/lambda v1.54.0 h1:gazALVrZ7RIG6gJXut3c7NKtPgs9eQ8BFCA9uoliayk=
Expand Down
13 changes: 1 addition & 12 deletions internal/conns/awsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
directoryservice_sdkv1 "github.com/aws/aws-sdk-go/service/directoryservice"
dynamodb_sdkv1 "github.com/aws/aws-sdk-go/service/dynamodb"
efs_sdkv1 "github.com/aws/aws-sdk-go/service/efs"
kms_sdkv1 "github.com/aws/aws-sdk-go/service/kms"
opsworks_sdkv1 "github.com/aws/aws-sdk-go/service/opsworks"
rds_sdkv1 "github.com/aws/aws-sdk-go/service/rds"
baselogging "github.com/hashicorp/aws-sdk-go-base/v2/logging"
Expand Down Expand Up @@ -95,17 +94,7 @@ func (c *AWSClient) EFSConnForRegion(ctx context.Context, region string) *efs_sd
return efs_sdkv1.New(c.session, aws_sdkv1.NewConfig().WithRegion(region))
}

// KMSConnForRegion returns an AWS SDK For Go v1 KMS API client for the specified AWS Region.
// If the specified region is not the default a new "simple" client is created.
// This new client does not use any configured endpoint override.
func (c *AWSClient) KMSConnForRegion(ctx context.Context, region string) *kms_sdkv1.KMS {
if region == c.Region {
return c.KMSConn(ctx)
}
return kms_sdkv1.New(c.session, aws_sdkv1.NewConfig().WithRegion(region))
}

// KMSConnForRegion returns an AWS SDK For Go v1 OpsWorks API client for the specified AWS Region.
// OpsWorksConnForRegion returns an AWS SDK For Go v1 OpsWorks API client for the specified AWS Region.
// If the specified region is not the default a new "simple" client is created.
// This new client does not use any configured endpoint override.
func (c *AWSClient) OpsWorksConnForRegion(ctx context.Context, region string) *opsworks_sdkv1.OpsWorks {
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func FlattenStringMap(m map[string]*string) map[string]interface{} {
})
}

func FlattenStringValueMap(m map[string]string) map[string]interface{} {
return tfmaps.ApplyToAllValues(m, func(v string) any {
return v
})
}

// Takes the result of schema.Set of strings and returns a []*int64
func ExpandInt64Set(configured *schema.Set) []*int64 {
return ExpandInt64List(configured.List())
Expand Down
2 changes: 1 addition & 1 deletion internal/service/cloudfront/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ func resourceDistributionDelete(ctx context.Context, d *schema.ResourceData, met
const (
timeout = 1 * time.Minute
)
_, err = tfresource.RetryWhenIsOneOf[*awstypes.PreconditionFailed, *awstypes.InvalidIfMatchVersion](ctx, timeout, func() (interface{}, error) {
_, err = tfresource.RetryWhenIsOneOf2[*awstypes.PreconditionFailed, *awstypes.InvalidIfMatchVersion](ctx, timeout, func() (interface{}, error) {
return nil, deleteDistribution(ctx, conn, d.Id())
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/dynamodb/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ func clearSSEDefaultKey(ctx context.Context, client *conns.AWSClient, sseList []

sse := sseList[0].(map[string]interface{})

dk, err := kms.FindDefaultKey(ctx, client, "dynamodb", client.Region)
dk, err := kms.FindDefaultKeyARNForService(ctx, client.KMSClient(ctx), "dynamodb", client.Region)
if err != nil {
return sseList
}
Expand Down Expand Up @@ -1906,7 +1906,7 @@ func clearReplicaDefaultKeys(ctx context.Context, client *conns.AWSClient, repli
continue
}

dk, err := kms.FindDefaultKey(ctx, client, "dynamodb", replica["region_name"].(string))
dk, err := kms.FindDefaultKeyARNForService(ctx, client.KMSClient(ctx), "dynamodb", replica["region_name"].(string))
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/dynamodb/table_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func resourceTableReplicaRead(ctx context.Context, d *schema.ResourceData, meta
return create.AppendDiagError(diags, names.DynamoDB, create.ErrActionReading, ResNameTableReplica, d.Id(), err)
}

dk, err := kms.FindDefaultKey(ctx, meta.(*conns.AWSClient), "dynamodb", replicaRegion)
dk, err := kms.FindDefaultKeyARNForService(ctx, meta.(*conns.AWSClient).KMSClient(ctx), "dynamodb", replicaRegion)
if err != nil {
return create.AppendDiagError(diags, names.DynamoDB, create.ErrActionReading, ResNameTableReplica, d.Id(), err)
}
Expand Down Expand Up @@ -363,7 +363,7 @@ func resourceTableReplicaUpdate(ctx context.Context, d *schema.ResourceData, met
}

if d.HasChange(names.AttrKMSKeyARN) && !d.IsNewResource() { // create ends with update and sets kms_key_arn causing change that is not
dk, err := kms.FindDefaultKey(ctx, meta.(*conns.AWSClient), "dynamodb", replicaRegion)
dk, err := kms.FindDefaultKeyARNForService(ctx, meta.(*conns.AWSClient).KMSClient(ctx), "dynamodb", replicaRegion)
if err != nil {
return create.AppendDiagError(diags, names.DynamoDB, create.ErrActionUpdating, ResNameTableReplica, d.Id(), fmt.Errorf("region %s: %w", replicaRegion, err))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ec2/ebs_default_kms_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func testAccCheckEBSDefaultKMSKey(ctx context.Context, name string) resource.Tes

// testAccEBSManagedDefaultKey returns' the account's AWS-managed default CMK.
func testAccEBSManagedDefaultKey(ctx context.Context) (*arn.ARN, error) {
conn := acctest.Provider.Meta().(*conns.AWSClient).KMSConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).KMSClient(ctx)

alias, err := tfkms.FindAliasByName(ctx, conn, "alias/aws/ebs")
if err != nil {
Expand Down
100 changes: 66 additions & 34 deletions internal/service/kms/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import (
"context"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/kms"
awstypes "github.com/aws/aws-sdk-go-v2/service/kms/types"
"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/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

// @SDKResource("aws_kms_alias")
func ResourceAlias() *schema.Resource {
// @SDKResource("aws_kms_alias", name="Alias")
func resourceAlias() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAliasCreate,
ReadWithoutTimeout: resourceAliasRead,
Expand All @@ -35,7 +37,6 @@ func ResourceAlias() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"name": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -44,7 +45,6 @@ func ResourceAlias() *schema.Resource {
ConflictsWith: []string{"name_prefix"},
ValidateFunc: validNameForResource,
},

"name_prefix": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -53,12 +53,10 @@ func ResourceAlias() *schema.Resource {
ConflictsWith: []string{"name"},
ValidateFunc: validNameForResource,
},

"target_key_arn": {
Type: schema.TypeString,
Computed: true,
},

"target_key_id": {
Type: schema.TypeString,
Required: true,
Expand All @@ -70,25 +68,21 @@ func ResourceAlias() *schema.Resource {

func resourceAliasCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).KMSConn(ctx)
conn := meta.(*conns.AWSClient).KMSClient(ctx)

namePrefix := d.Get("name_prefix").(string)
if namePrefix == "" {
namePrefix = AliasNamePrefix
namePrefix = aliasNamePrefix
}
name := create.Name(d.Get("name").(string), namePrefix)

input := &kms.CreateAliasInput{
AliasName: aws.String(name),
TargetKeyId: aws.String(d.Get("target_key_id").(string)),
}

// KMS is eventually consistent.
log.Printf("[DEBUG] Creating KMS Alias: %s", input)

_, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, KeyRotationUpdatedTimeout, func() (interface{}, error) {
return conn.CreateAliasWithContext(ctx, input)
}, kms.ErrCodeNotFoundException)
_, err := tfresource.RetryWhenIsA[*awstypes.NotFoundException](ctx, keyRotationUpdatedTimeout, func() (interface{}, error) {
return conn.CreateAlias(ctx, input)
})

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating KMS Alias (%s): %s", name, err)
Expand All @@ -101,10 +95,10 @@ func resourceAliasCreate(ctx context.Context, d *schema.ResourceData, meta inter

func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).KMSConn(ctx)
conn := meta.(*conns.AWSClient).KMSClient(ctx)

outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, PropagationTimeout, func() (interface{}, error) {
return FindAliasByName(ctx, conn, d.Id())
outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, kmsPropagationTimeout, func() (interface{}, error) {
return findAliasByName(ctx, conn, d.Id())
}, d.IsNewResource())

if !d.IsNewResource() && tfresource.NotFound(err) {
Expand All @@ -117,17 +111,17 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interfa
return sdkdiag.AppendErrorf(diags, "reading KMS Alias (%s): %s", d.Id(), err)
}

alias := outputRaw.(*kms.AliasListEntry)
aliasARN := aws.StringValue(alias.AliasArn)
targetKeyID := aws.StringValue(alias.TargetKeyId)
targetKeyARN, err := AliasARNToKeyARN(aliasARN, targetKeyID)
alias := outputRaw.(*awstypes.AliasListEntry)
aliasARN := aws.ToString(alias.AliasArn)
targetKeyID := aws.ToString(alias.TargetKeyId)
targetKeyARN, err := aliasARNToKeyARN(aliasARN, targetKeyID)
if err != nil {
return sdkdiag.AppendErrorf(diags, "reading KMS Alias (%s): %s", d.Id(), err)
}

d.Set("arn", aliasARN)
d.Set("name", alias.AliasName)
d.Set("name_prefix", create.NamePrefixFromName(aws.StringValue(alias.AliasName)))
d.Set("name_prefix", create.NamePrefixFromName(aws.ToString(alias.AliasName)))
d.Set("target_key_arn", targetKeyARN)
d.Set("target_key_id", targetKeyID)

Expand All @@ -136,16 +130,15 @@ func resourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interfa

func resourceAliasUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).KMSConn(ctx)
conn := meta.(*conns.AWSClient).KMSClient(ctx)

if d.HasChange("target_key_id") {
input := &kms.UpdateAliasInput{
AliasName: aws.String(d.Id()),
TargetKeyId: aws.String(d.Get("target_key_id").(string)),
}

log.Printf("[DEBUG] Updating KMS Alias: %s", input)
_, err := conn.UpdateAliasWithContext(ctx, input)
_, err := conn.UpdateAlias(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating KMS Alias (%s): %s", d.Id(), err)
Expand All @@ -157,14 +150,14 @@ func resourceAliasUpdate(ctx context.Context, d *schema.ResourceData, meta inter

func resourceAliasDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).KMSConn(ctx)
conn := meta.(*conns.AWSClient).KMSClient(ctx)

log.Printf("[DEBUG] Deleting KMS Alias: (%s)", d.Id())
_, err := conn.DeleteAliasWithContext(ctx, &kms.DeleteAliasInput{
log.Printf("[DEBUG] Deleting KMS Alias: %s", d.Id())
_, err := conn.DeleteAlias(ctx, &kms.DeleteAliasInput{
AliasName: aws.String(d.Id()),
})

if tfawserr.ErrCodeEquals(err, kms.ErrCodeNotFoundException) {
if errs.IsA[*awstypes.NotFoundException](err) {
return diags
}

Expand All @@ -175,6 +168,45 @@ func resourceAliasDelete(ctx context.Context, d *schema.ResourceData, meta inter
return diags
}

func findAliasByName(ctx context.Context, conn *kms.Client, name string) (*awstypes.AliasListEntry, error) {
input := &kms.ListAliasesInput{}

return findAlias(ctx, conn, input, func(v *awstypes.AliasListEntry) bool {
return aws.ToString(v.AliasName) == name
})
}

func findAlias(ctx context.Context, conn *kms.Client, input *kms.ListAliasesInput, filter tfslices.Predicate[*awstypes.AliasListEntry]) (*awstypes.AliasListEntry, error) {
output, err := findAliases(ctx, conn, input, filter)

if err != nil {
return nil, err
}

return tfresource.AssertSingleValueResult(output)
}

func findAliases(ctx context.Context, conn *kms.Client, input *kms.ListAliasesInput, filter tfslices.Predicate[*awstypes.AliasListEntry]) ([]awstypes.AliasListEntry, error) {
var output []awstypes.AliasListEntry

pages := kms.NewListAliasesPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return output, err
}

for _, v := range page.Aliases {
if filter(&v) {
output = append(output, v)
}
}
}

return output, nil
}

func suppressEquivalentKeyARNOrID(k, old, new string, d *schema.ResourceData) bool {
return KeyARNOrIDEqual(old, new)
return keyARNOrIDEqual(old, new)
}
12 changes: 6 additions & 6 deletions internal/service/kms/alias_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
)

// @SDKDataSource("aws_kms_alias")
func DataSourceAlias() *schema.Resource {
// @SDKDataSource("aws_kms_alias", name="Alias")
func dataSourceAlias() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceAliasRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand All @@ -41,11 +42,10 @@ func DataSourceAlias() *schema.Resource {

func dataSourceAliasRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).KMSConn(ctx)
conn := meta.(*conns.AWSClient).KMSClient(ctx)

target := d.Get("name").(string)

alias, err := FindAliasByName(ctx, conn, target)
alias, err := findAliasByName(ctx, conn, target)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading KMS Alias (%s): %s", target, err)
Expand All @@ -65,7 +65,7 @@ func dataSourceAliasRead(ctx context.Context, d *schema.ResourceData, meta inter
//
// https://docs.aws.amazon.com/kms/latest/APIReference/API_ListAliases.html

keyMetadata, err := FindKeyByID(ctx, conn, target)
keyMetadata, err := findKeyByID(ctx, conn, target)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading KMS Key (%s): %s", target, err)
Expand Down
Loading
Loading