Hi all, I have the following code that downloads a...
# general
n
Hi all, I have the following code that downloads a kubeconfg file after I have installed Kubernetes. How do I extract the content of that file into a variable and then export it. Just not sure how I run some manual nodejs code to extract the file contents after pulumi has downloaded the file.
Copy code
const kubeConfigFile = pulumi.getStack() === "prod" ? "./kube/config" : "./kube/config-dev"
const kubeconfg = new local.Command("copy-kubeconfig", {
  create: pulumi.interpolate`
  mkdir -p ./kube
  scp -o StrictHostKeyChecking=no -i "${tlsKey.privateKeyOpenssh}" root@${k3sMaster1.ipv4Address}:/etc/rancher/k3s/k3s.yaml ${kubeConfigFile}
  sed -i 's/127.0.0.1/${k3sMaster1.ipv4Address}/' ${kubeConfigFile}
  `
}, {
  dependsOn: [k3sMaster1Install]
})
I worked out how to do it. I just cated the file out as the last command. So my local.Command looked like this.
Copy code
const kubeConfigFile = pulumi.getStack() === "prod" ? "./kube/config" : "./kube/config-dev"
const kubeconfg = new local.Command("copy-kubeconfig", {
  create: pulumi.interpolate`
  mkdir -p ./kube
  scp -o StrictHostKeyChecking=no -i "${tlsKey.privateKeyOpenssh}" root@${k3sMaster1.ipv4Address}:/etc/rancher/k3s/k3s.yaml ${kubeConfigFile}
  sed -i 's/127.0.0.1/${k3sMaster1.ipv4Address}/' ${kubeConfigFile}
  cat ${kubeConfigFile}
  `
}, {
  dependsOn: [k3sMaster1Install]
})
Then I used the stdout as export for my output.
Copy code
module.exports = {
  kubeconfig: kubeconfg.stdout.apply(x => x.toString()),
}
Not sure if the
apply
is required, but it works.