Skip to content

Commit

Permalink
resource/tls_private_key: Use now available x/crypto/ssh.MarshalPriva…
Browse files Browse the repository at this point in the history
…teKey (#425)

Reference: #154
  • Loading branch information
bflad authored Oct 12, 2023
1 parent a986913 commit bcd3d43
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 312 deletions.
206 changes: 0 additions & 206 deletions internal/openssh/lib.go

This file was deleted.

102 changes: 0 additions & 102 deletions internal/openssh/lib_test.go

This file was deleted.

7 changes: 3 additions & 4 deletions internal/provider/resource_private_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/hashicorp/terraform-provider-tls/internal/openssh"
"golang.org/x/crypto/ssh"
)

type privateKeyResource struct{}
Expand Down Expand Up @@ -318,7 +317,7 @@ func (r *privateKeyResource) Create(ctx context.Context, req resource.CreateRequ
tflog.Debug(ctx, "Marshalling private key to OpenSSH PEM (if supported)")
newState.PrivateKeyOpenSSH = types.StringValue("")
if prvKeySupportsOpenSSHMarshalling(prvKey) {
openSSHKeyPemBlock, err := openssh.MarshalPrivateKey(prvKey, "")
openSSHKeyPemBlock, err := ssh.MarshalPrivateKey(prvKey, "")
if err != nil {
res.Diagnostics.AddError("Unable to marshal private key into OpenSSH format", err.Error())
return
Expand Down Expand Up @@ -392,7 +391,7 @@ func (r *privateKeyResource) UpgradeState(ctx context.Context) map[int64]resourc
// Marshal the Key in OpenSSH PEM, if necessary and supported
tflog.Debug(ctx, "Marshalling private key to OpenSSH PEM (if supported)")
if (upState.PrivateKeyOpenSSH.IsNull() || upState.PrivateKeyOpenSSH.ValueString() == "") && prvKeySupportsOpenSSHMarshalling(prvKey) {
openSSHKeyPemBlock, err := openssh.MarshalPrivateKey(prvKey, "")
openSSHKeyPemBlock, err := ssh.MarshalPrivateKey(prvKey, "")
if err != nil {
res.Diagnostics.AddError("Unable to marshal private key into OpenSSH format", err.Error())
return
Expand Down

0 comments on commit bcd3d43

Please sign in to comment.