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

fix aws_kms_public_key.public_key format - must be base64 #19944

Merged
merged 3 commits into from
Aug 25, 2021
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
3 changes: 3 additions & 0 deletions .changelog/19944.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_kms_public_key: Correctly base64 encode `public_key` value
```
3 changes: 2 additions & 1 deletion aws/data_source_aws_kms_public_key.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"encoding/base64"
"fmt"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -75,7 +76,7 @@ func dataSourceAwsKmsPublicKeyRead(d *schema.ResourceData, meta interface{}) err
d.Set("arn", output.KeyId)
d.Set("customer_master_key_spec", output.CustomerMasterKeySpec)
d.Set("key_usage", output.KeyUsage)
d.Set("public_key", string(output.PublicKey))
d.Set("public_key", base64.StdEncoding.EncodeToString(output.PublicKey))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? If my understanding is correct output.PublicKey is already base64 encoded, so should it be returned as is?

Copy link
Contributor

@anGie44 anGie44 Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the AWS Go SDK Documentation https://docs.aws.amazon.com/sdk-for-go/api/service/kms/#GetPublicKeyOutput

PublicKey is automatically base64 encoded/decoded by the SDK

@chrisclayson in this case I think we'd have to encode this API response value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ... OK, fair enough, I was reading the AWS API docs, didn't realise the Go SDK automatically decoded it. Thanks for clarifying! 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ! That's why we need to encode again in base64, so that it can be handled through terraform


if err := d.Set("encryption_algorithms", flattenStringList(output.EncryptionAlgorithms)); err != nil {
return fmt.Errorf("error setting encryption_algorithms: %w", err)
Expand Down