https://pulumi.com logo
#general
Title
# general
h

hallowed-printer-89159

11/10/2022, 4:43 PM
Hey everyone, I was wondering, if you have a few example for SshPublicKey I need to create a SSH public key to connect with de VM on GCP but I have an error when I am creating the resource
Copy code
const sshKey = new SshPublicKey('test', {
    expirationTimeUsec: '250000',
    key: '',
    project: 'example',
    user: '<mailto:----@univision.net|----@univision.net>',
});
The types for SshPublicKey is but the Args are not enough clear and I got Error creating SSHPublicKey: googleapi: Error 400: SSH key is expired.
Copy code
/**
 * Create a SshPublicKey resource with the given unique name, arguments, and options.
 *
 * @param name The _unique_ name of the resource.
 * @param args The arguments to use to populate this resource's properties.
 * @param opts A bag of options that control this resource's behavior.
 */
constructor(name: string, args: SshPublicKeyArgs, opts?: pulumi.CustomResourceOptions);
b

billowy-army-68599

11/10/2022, 4:51 PM
do you have an existing key you want to use, or generate a new key?
h

hallowed-printer-89159

11/10/2022, 4:51 PM
I want to generate a new one
Copy code
const sshKey = new tls.PrivateKey("bastion", {
  algorithm: "RSA",
})

const sshKey = new SshPublicKey('test', {
    expirationTimeUsec: '250000',
    key: sshKey.publicKeyOpenssh,
    project: 'example',
    user: '<mailto:----@univision.net|----@univision.net>',
});
h

hallowed-printer-89159

11/10/2022, 4:59 PM
Thanks I am going to try
I got same error
b

billowy-army-68599

11/10/2022, 5:22 PM
this worked for me
Copy code
// Create a GCP resource (Storage Bucket)
const sshKey = new tls.PrivateKey("example",{
    algorithm: "RSA",
})

const gcloudKey = new gcp.oslogin.SshPublicKey("example",{
    key: sshKey.publicKeyOpenssh,
    user: "<mailto:lbriggs@pulumi.com|lbriggs@pulumi.com>",
})
h

hallowed-printer-89159

11/10/2022, 5:29 PM
now, It works, do you know how to see the key created to connect after the vm creation?
b

billowy-army-68599

11/10/2022, 5:32 PM
add this to your code
Copy code
export const privateKey = sshKey.privateKeyOpenssh
Then run
pulumi up
Then run
pulumi stack outputs --show-secrets
h

hallowed-printer-89159

11/10/2022, 5:33 PM
Thanks for your help
Sorry for asking so much, do you know how to associate the public key to a compute instance, I am trying to pass on the metadata but it doesn't works
Copy code
metadata: {
    'enable-oslogin': "true",
    'ssh-keys': '<mailto:----@univision.net|----@univision.net>' +":"+ sshKey.key
},
Got the following error: Calling [toString] on an [Output<T>] is not supported.
b

billowy-army-68599

11/10/2022, 6:45 PM
you will need to use an
apply
h

hallowed-printer-89159

11/10/2022, 6:49 PM
I tried
Copy code
metadata: {
    'enable-oslogin': "true",
    'ssh-keys': '<mailto:----@univision.net|----@univision.net>' +":"+ sshKey.key.apply(v => v.toString())
},
b

billowy-army-68599

11/10/2022, 6:52 PM
try
Copy code
'ssh-keys': pulumi.interpolate`--- +":" ssh.key
h

hallowed-printer-89159

11/10/2022, 6:58 PM
now it works! thanks
5 Views