Hi guys, I am trying to create a Linode instance w...
# getting-started
n
Hi guys, I am trying to create a Linode instance with authorizedKeys (string[]). When I converted it into array, pulumi said it requires it to be ssh_rsa type. When I leave it as raw ssh_rsa type, pulumi said it requires a list type. What should I actually do?
b
can you share your code?
n
import * as pulumi from "@pulumi/pulumi";
import * as linode from "@pulumi/linode";
const fs = require("fs");
const path = require("path");
let pubKey: string = fs.readFileSync(path.join(__dirname,'id_rsa.pub')).toString();
let pubKeys: string[] = pubKey.split("");
const masterInstance = new linode.Instance("nanode-master", {
    
group: "masters",
    
type: "g6-nanode-1",
    
region: "ap-south",
      
image: "linode/alpine3.13",
    
authorizedKeys: pubKeys,
    
rootPass: "rootPass123!",
    
tags: ["master node"],
    
watchdogEnabled: true
});
I'm also having issue that pulumi cannot read files outside its parent folder but within own folder. When I readFileSync from "../../secret/id_rsa.pub", it keeps saying it can't read the file. But when I placed it in the same folder with the index.ts, it is able to read.
b
I don't think this line is correct:
Copy code
let pubKeys: string[] = pubKey.split("");
why wouldn't you do:
Copy code
const masterInstance = new linode.Instance("nanode-master", {
    group: "masters",
    type: "g6-nanode-1",
    region: "ap-south", 
    image: "linode/alpine3.13",
    authorizedKeys: [ pubKey ],
    rootPass: "rootPass123!",
    tags: ["master node"],
    watchdogEnabled: true
});
n
Still having error "error: 1 error occurred: * Error creating a Linode Instance: [400] [authorized_keys] SSH Key 1 must not be multi-lined." But my id_rsa.pub is a single line though.
b
I would double check what the output of
let pubKey: string = fs.readFileSync(path.join(__dirname,'id_rsa.pub')).toString();
is returning
n
is returning the exact content of my public key in the console.log in a single line.
b
is
toString()
adding a newline on the end?
n
my bad, there is indeed a newline on the end. sorry about that.
How about reading id_rsa in another folder outside its parent folder?
b
there's nothing stopping Pulumi reading files outside the parent folder, there's no sandboxing etc. It just uses a standard node interpreter, so I'd double check your path maybe?
n
strange though. I use the exact code inside express. it works. but the exact same code in pulumi, it gives file does not exist error
I will look into it again.
thanks.
b
I'll try do a repro when i get a few minutes
n
let pubKey: string = fs.readFileSync(path.join(__dirname,'/../secret/id_rsa.pub')).toString();
this line works in express, console.log(pubKey) prints the public key in console. the same line in pulumi gives this error "Error: ENOENT: no such file or directory, open '/secret/id_rsa.pub'"
Ok never mind. Is the file permission problem. My bad again.
It still doesn't work even i set the permission to 777