Skip to content

Commit

Permalink
Fail faster when AWS creds are missing; fix base64 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Jul 30, 2021
1 parent 86415c7 commit 3754f9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aws-py-ec2-provisioners/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pulumi
import pulumi_aws as aws
import provisioners
import base64

# Get the config ready to go.
config = pulumi.Config()
Expand All @@ -12,12 +13,22 @@
key_name = config.get('keyName')
public_key = config.get('publicKey')


# The privateKey associated with the selected key must be provided (either directly or base64 encoded),
# along with an optional passphrase if needed.
def decode_key(key):

try:
key = base64.b64decode(key.encode('ascii')).decode('ascii')
except:
pass

if key.startswith('-----BEGIN RSA PRIVATE KEY-----'):
return key

return key.encode('ascii')


private_key = config.require_secret('privateKey').apply(decode_key)
private_key_passphrase = config.get_secret('privateKeyPassphrase')

Expand Down
3 changes: 3 additions & 0 deletions misc/test/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ func checkAccAwsEc2Provisioners(t *testing.T, dir string) {
KeyName: aws.String(keyName),
})
assert.NoError(t, err)
if err != nil {
return
}
defer func() {
t.Logf("Deleting keypair %s.\n", keyName)
_, err := svc.DeleteKeyPair(&ec2.DeleteKeyPairInput{
Expand Down

0 comments on commit 3754f9d

Please sign in to comment.