Hi, is there a way to replace strings files in pul...
# general
t
Hi, is there a way to replace strings files in pulumi like in terraform. I want to pass in a kubeconfig into a K8s provider and pass in config variables in to the string of the file:
Copy code
apiVersion: v1
preferences: {}
kind: Config
clusters:
- cluster:
    server: ${server}   
    certificate-authority-data: ${certificate-authority-data}
  name: current-cluster
contexts:
- context:
    cluster: current-cluster
    user: runner-user
  name: runner-context
current-context: runner-context
users:
- name: runner-user
  user:
    token: ${token}
b
Hi What language are you using?
Here is how I do with typescript:
Copy code
import * as fs from 'fs'
import * as _ from "lodash"

const TEMPLATE_SETTINGS = {
    interpolate: /{{([\s\S]+?)}}/g, // Mustache template delimiter: `{{variable}}`
    evaluate: undefined, 
    escape: undefined, 
}

const value = _.template(fs.readFileSync('./assets/file.yaml', 'utf8'), TEMPLATE_SETTINGS)({
                var1: 'value1',                     
                var2: 'value2',
            })
see doc of lodash interpolate for more details
as there is no pulumi way today (I guess), we have to use language capabilities
and it could be great to have these workarounds in doc 😉
note that I use mustache delimiter to prevent conflict with bash variable (
$VAR
)
t
thank you for helping 🙂
I am ysing type script 🙂