salmon-winter-68864
11/30/2023, 4:07 AMpulumi up
, the time sleep always runs first before the instance create in the following example and I don't understand why (even with the dependsOn)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
linodeConfig := LinodeConfig{}.New()
roxyConfig := config.New(ctx, "roxy")
roxyConfig.RequireObject("linode", linodeConfig)
if linodeConfig.SSH.Key.Private == "" {
return fmt.Errorf("No SSH Private key found")
}
if linodeConfig.SSH.Key.Public == "" {
return fmt.Errorf("No SSH Public key found")
}
// Create a linode resource (Linode Instance)
instance, err := linode.NewInstance(ctx, "roxy", &linode.InstanceArgs{
Type: pulumi.String(linodeConfig.Instance.Type),
Region: pulumi.String(linodeConfig.Instance.Region),
Image: pulumi.String(linodeConfig.Instance.Image),
AuthorizedKeys: pulumi.StringArray{
pulumi.String(linodeConfig.SSH.Key.Public),
},
})
if err != nil {
return err
}
fmt.Println("sleeping for a min")
time.Sleep(time.Minute)
_, err = remote.NewCommand(ctx, "echoCmd", &remote.CommandArgs{
Create: pulumi.String("echo 'Hello, World!' > boo.txt"),
Connection: remote.ConnectionArgs{
Host: instance.IpAddress,
User: pulumi.String("root"),
PrivateKey: pulumi.StringPtr(linodeConfig.SSH.Key.Private),
},
}, pulumi.DependsOn([]pulumi.Resource{instance}))
if err != nil {
return err
}
return nil
})
}
For brevity I added a plain time.Sleep - but I originally had a for loop to check the status of the linode instance, and based on this, I wanted to break and then run the remote command. But the for loop always ran first before the instance when calling pulumi up
so of course it always failed. As does this example with the sleep.
I have a feeling I will need to use "Component resources" to build my platform, but I'm currently trying to get a taste of Pulumi and this is driving me a little mental. Any help/advice welcome. I didn't imagine my Go code would be run in a different order than I wrote it?salmon-winter-68864
11/30/2023, 5:43 AMsleeping for a min
occurs 1st which means every up
fails to process the new command because the sleep happens first? I don't understand how the execution order is altered?salmon-winter-68864
11/30/2023, 8:35 PMsalmon-winter-68864
12/01/2023, 12:29 AMsalmon-winter-68864
12/01/2023, 1:49 AM