```const userData = fs.readFileSync('bs.sh','utf8'...
# typescript
b
Copy code
const userData = fs.readFileSync('bs.sh','utf8'); 

userData: fs.readFileSync('./basenode.sh'),
Is above right way to call shell script @stocky-restaurant-98004 ?
s
This works for me:
Copy code
import { readFileSync } from "fs";

const userData = readFileSync("my_script.sh", {
  encoding: "utf-8",
});

export { userData };
my_script.sh:
Copy code
#!/bin/sh
ls
b
@stocky-restaurant-98004 it was able to read while file or commands inside bs.sh ..but didn’t ran any shell command
Copy code
#!/bin/sh

sudo apt-get install -y ansible

sudo apt install python3.8

wget -qO - terraform.gpg <https://apt.releases.hashicorp.com/gpg> | sudo gpg --dearmor -o /usr/share/keyrings/terraform-archive-keyring.gpg

sudo echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/terraform-archive-keyring.gpg] <https://apt.releases.hashicorp.com> $(lsb_release -cs) main" > /etc/apt/sources.list.d/terraform.list

sudo apt install terraform
I want it to read and run above commands on server
s
Ah, so the issue is that userData isn't working. Got it.
b
Copy code
Resources:
    3 unchanged

Do you want to perform this update? yes
Updating (stage):
     Type                 Name              Status     
     pulumi:pulumi:Stack  metal-auto-stage             
 
Outputs:
    dsbasenodeIP: "139.178.70.225"
    userData    : "#!/bin/sh\n\nsudo apt-get install -y ansible\n\nsudo apt install python3.8\n\nwget -qO - terraform.gpg <https://apt.releases.hashicorp.com/gpg> | sudo gpg --dearmor -o /usr/share/keyrings/terraform-archive-keyring.gpg\n\nsudo echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/terraform-archive-keyring.gpg] <https://apt.releases.hashicorp.com> $(lsb_release -cs) main\" > /etc/apt/sources.list.d/terraform.list\n\nsudo apt install terraform\n\n\n"
s
And this is on a freshly provisioned Device, right? Userdata only runs when you create the device.
b
Yes it on server which I created with code..Ideally it should ran right ?
s
If you run
pulumi destroy
and then
pulumi up
, the userdata code does not run, correct?
There's also an update for that provider that's missing. Not sure if that would fix the userdata issue or not.
b
Copy code
#!/bin/env node
Calling out .sh should be like above ?