Hey - I'm having trouble finding information on ho...
# golang
h
Hey - I'm having trouble finding information on how to conditionally include a setting. I want to read an input variable and only include the configuration if the input variable exists. It's the one I got help on before but I want to only include it conditionally.
Copy code
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
        conf := config.New(ctx, "")
        INIT_SCRIPT := config.Get("init_script_path")

		cluster, err := databricks.NewCluster(ctx, "example", &databricks.ClusterArgs{
			// logic here to only include if INIT_SCRIPT has content //
            InitScripts: databricks.ClusterInitScriptArray{
				databricks.ClusterInitScriptArgs{
					S3: databricks.ClusterInitScriptS3Args{
						Destination: pulumi.String("something"),
					},
				},
			},
            // END INCLUDE AREA //
		})

		if err != nil {
			return fmt.Errorf("error creating cluster: %w", err)
		}

		ctx.Export("clusterName", cluster.ClusterName)

		return nil

	})
}
g
I believe you could use config.Try() which returns (string, error) and assign your databricks.ClusterInitScriptArray to a variable based on that
👍 1
h
For now I am using this and it does the trick. 🙂
Copy code
var = config.Get("var_name")
if var_name == "" {
  var = "default val"
}