https://pulumi.com logo
Title
n

nutritious-church-27230

06/09/2021, 4:56 PM
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

billowy-army-68599

06/09/2021, 4:58 PM
can you share your code?
n

nutritious-church-27230

06/09/2021, 5:01 PM
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

billowy-army-68599

06/09/2021, 5:12 PM
I don't think this line is correct:
let pubKeys: string[] = pubKey.split("");
why wouldn't you do:
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

nutritious-church-27230

06/09/2021, 5:16 PM
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

billowy-army-68599

06/09/2021, 5:16 PM
I would double check what the output of
let pubKey: string = fs.readFileSync(path.join(__dirname,'id_rsa.pub')).toString();
is returning
n

nutritious-church-27230

06/09/2021, 5:19 PM
is returning the exact content of my public key in the console.log in a single line.
b

billowy-army-68599

06/09/2021, 5:19 PM
is
toString()
adding a newline on the end?
n

nutritious-church-27230

06/09/2021, 5:23 PM
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

billowy-army-68599

06/09/2021, 5:26 PM
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

nutritious-church-27230

06/09/2021, 5:27 PM
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

billowy-army-68599

06/09/2021, 5:32 PM
I'll try do a repro when i get a few minutes
n

nutritious-church-27230

06/09/2021, 5:45 PM
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