Hey everyone, I was wondering, if you have a few e...
# general
h
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
do you have an existing key you want to use, or generate a new key?
h
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
Thanks I am going to try
I got same error
b
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
now, It works, do you know how to see the key created to connect after the vm creation?
b
add this to your code
Copy code
export const privateKey = sshKey.privateKeyOpenssh
Then run
pulumi up
Then run
pulumi stack outputs --show-secrets
h
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
you will need to use an
apply
h
I tried
Copy code
metadata: {
    'enable-oslogin': "true",
    'ssh-keys': '<mailto:----@univision.net|----@univision.net>' +":"+ sshKey.key.apply(v => v.toString())
},
b
try
Copy code
'ssh-keys': pulumi.interpolate`--- +":" ssh.key
h
now it works! thanks