-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.go
52 lines (44 loc) · 1.37 KB
/
script.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package command
import (
"path"
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/pulumi/pulumi-command/sdk/go/command/remote"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
const (
baseRemotePath = "/tmp"
)
// If *Param is nil, the create/update/delete command is not run
func NewScript(ctx *pulumi.Context,
conn *remote.ConnectionArgs,
localScriptPath string,
createParam, updateParam, deleteParam *string,
) (*remote.Command, error) {
fileHash, err := utils.FileHash(localScriptPath)
if err != nil {
return nil, err
}
fileName := path.Base(localScriptPath)
remotePath := path.Join(baseRemotePath, "remote-"+fileHash, fileName)
copyFile, err := remote.NewCopyFile(ctx, fileName+"-"+fileHash, &remote.CopyFileArgs{
Connection: conn,
LocalPath: pulumi.String(localScriptPath),
RemotePath: pulumi.String(remotePath),
})
if err != nil {
return nil, err
}
runCommandArgs := &remote.CommandArgs{
Connection: conn,
}
if createParam != nil {
runCommandArgs.Create = pulumi.StringPtr(remotePath + " " + *createParam)
}
if updateParam != nil {
runCommandArgs.Update = pulumi.StringPtr(remotePath + " " + *updateParam)
}
if deleteParam != nil {
runCommandArgs.Delete = pulumi.StringPtr(remotePath + " " + *deleteParam)
}
return remote.NewCommand(ctx, "remote-"+fileHash, runCommandArgs, pulumi.DependsOn([]pulumi.Resource{copyFile}))
}