3 months ago
    Hello everyone, trying to port some changes from Terraform to Pulumi and run into an issue: This is EC2 instance spec in terraform. I have a templated bash script into which I inject loadbalancer DNS name.
    user_data                   = base64encode(
        templatefile("../templates/", {
            internal_lb_dns_name =
    How to achieve similar results with pulumi? If it was not a templated file it would be easy, namely:
    UserData:            pulumi.StringPtr(base64.StdEncoding.EncodeToString(bashScriptContent))
    However, I need to inject some variables into that script that will be known once some resources got created. Any help would be appreciated, this is a part of my Master's Degree thesis and it would be a shame that this cannot be solved in Pulumi 😄 //EDIT, I'm writing in Golang


    3 months ago
    This example may help: You may need to augment that with
    to resolve those values to build the string as per:


    3 months ago
    Thanks @witty-candle-66007 , I came out with a solution
    userDataTpl, err := template.New("").
    		if err != nil {
    			return err
    		userData := internalLoadBalancer.DnsName.ApplyT(
    			func(lbDNSName string) (*string, error) {
    				buf := new(bytes.Buffer)
    				err := userDataFrontendTpl.Execute(buf, map[string]string{"internal_lb_dns_name": lbDNSName})
    				userData := base64.StdEncoding.EncodeToString(buf.Bytes())
    				return &userData, err
    worked like a charm with native go templating engine