Skip to content

Commit f93038b

Browse files
committed
Add another method to use CopyToRemote, because it breaks with input that are not resolved at plan time
1 parent dafcc85 commit f93038b

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

components/command/filemanager.go

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func (fm *FileManager) CopyFile(name string, localPath, remotePath pulumi.String
6868
return fm.runner.newCopyFile(name, localPath, remotePath, opts...)
6969
}
7070

71+
func (fm *FileManager) CopyToRemoteFile(name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
72+
return fm.command.NewCopyToRemoteFile(fm.runner, name, localPath, remotePath, opts...)
73+
}
74+
7175
func (fm *FileManager) CopyInlineFile(fileContent pulumi.StringInput, remotePath string, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
7276
// Write the content into a temporary file and get the path
7377
tempFile, err := os.CreateTemp("", filepath.Base(remotePath))

components/command/osCommand.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ type OSCommand interface {
3131
PathJoin(parts ...string) string
3232

3333
NewCopyFile(runner Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
34+
NewCopyToRemoteFile(runner Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
3435
copyLocalFile(runner *LocalRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
3536
copyRemoteFile(runner *RemoteRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
37+
copyRemoteFileV2(runner *RemoteRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
3638
}
3739

3840
// ------------------------------

components/command/runner.go

+9
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ type Runner interface {
141141
Command(name string, args RunnerCommandArgs, opts ...pulumi.ResourceOption) (Command, error)
142142

143143
newCopyFile(name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
144+
newCopyToRemoteFile(name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error)
144145
}
145146

146147
var _ Runner = &RemoteRunner{}
@@ -233,6 +234,10 @@ func (r *RemoteRunner) newCopyFile(name string, localPath, remotePath pulumi.Str
233234
return r.osCommand.copyRemoteFile(r, name, localPath, remotePath, opts...)
234235
}
235236

237+
func (r *RemoteRunner) newCopyToRemoteFile(name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
238+
return r.osCommand.copyRemoteFileV2(r, name, localPath, remotePath, opts...)
239+
}
240+
236241
func (r *RemoteRunner) PulumiOptions() []pulumi.ResourceOption {
237242
return r.options
238243
}
@@ -298,6 +303,10 @@ func (r *LocalRunner) newCopyFile(name string, localPath, remotePath pulumi.Stri
298303
return r.osCommand.copyLocalFile(r, name, localPath, remotePath, opts...)
299304
}
300305

306+
func (r *LocalRunner) newCopyToRemoteFile(name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
307+
return r.newCopyFile(name, localPath, remotePath, opts...)
308+
}
309+
301310
func (r *LocalRunner) PulumiOptions() []pulumi.ResourceOption {
302311
return []pulumi.ResourceOption{}
303312
}

components/command/unixOSCommand.go

+17
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func (fs unixOSCommand) NewCopyFile(runner Runner, name string, localPath, remot
8080
return runner.newCopyFile(name, localPath, remotePath, opts...)
8181
}
8282

83+
func (fs unixOSCommand) NewCopyToRemoteFile(runner Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
84+
return runner.newCopyToRemoteFile(name, localPath, remotePath, opts...)
85+
}
86+
8387
func formatCommandIfNeeded(command pulumi.StringInput, sudo bool, password bool, user string) pulumi.StringInput {
8488
if command == nil {
8589
return nil
@@ -146,3 +150,16 @@ func (fs unixOSCommand) copyRemoteFile(runner *RemoteRunner, name string, src, d
146150

147151
return moveCommand, err
148152
}
153+
154+
func (fs unixOSCommand) copyRemoteFileV2(runner *RemoteRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
155+
srcAsset := src.ToStringOutput().ApplyT(func(path string) pulumi.AssetOrArchive {
156+
return pulumi.NewFileAsset(path)
157+
}).(pulumi.AssetOrArchiveOutput)
158+
159+
return remote.NewCopyToRemote(runner.Environment().Ctx(), runner.Namer().ResourceName("copy", name), &remote.CopyToRemoteArgs{
160+
Connection: runner.Config().connection,
161+
Source: srcAsset,
162+
RemotePath: dst,
163+
Triggers: pulumi.Array{src, dst},
164+
}, utils.MergeOptions(runner.PulumiOptions(), opts...)...)
165+
}

components/command/windowsOSCommand.go

+17
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func (fs windowsOSCommand) NewCopyFile(runner Runner, name string, localPath, re
8686
return runner.newCopyFile(name, localPath, remotePath, opts...)
8787
}
8888

89+
func (fs windowsOSCommand) NewCopyToRemoteFile(runner Runner, name string, localPath, remotePath pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
90+
return runner.newCopyToRemoteFile(name, localPath, remotePath, opts...)
91+
}
92+
8993
func (fs windowsOSCommand) MoveFile(runner Runner, name string, source, destination pulumi.StringInput, sudo bool, opts ...pulumi.ResourceOption) (Command, error) {
9094
backupPath := pulumi.Sprintf("%v.%s", destination, backupExtension)
9195
copyCommand := pulumi.Sprintf(`Copy-Item -Path '%v' -Destination '%v'`, source, destination)
@@ -116,3 +120,16 @@ func (fs windowsOSCommand) copyRemoteFile(runner *RemoteRunner, name string, src
116120
Triggers: pulumi.Array{src, dst},
117121
}, utils.MergeOptions(runner.PulumiOptions(), opts...)...)
118122
}
123+
124+
func (fs windowsOSCommand) copyRemoteFileV2(runner *RemoteRunner, name string, src, dst pulumi.StringInput, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
125+
srcAsset := src.ToStringOutput().ApplyT(func(path string) pulumi.AssetOrArchive {
126+
return pulumi.NewFileAsset(path)
127+
}).(pulumi.AssetOrArchiveOutput)
128+
129+
return remote.NewCopyToRemote(runner.Environment().Ctx(), runner.Namer().ResourceName("copy", name), &remote.CopyToRemoteArgs{
130+
Connection: runner.Config().connection,
131+
Source: srcAsset,
132+
RemotePath: dst,
133+
Triggers: pulumi.Array{src, dst},
134+
}, utils.MergeOptions(runner.PulumiOptions(), opts...)...)
135+
}

components/datadog/agent/host.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (h *HostAgent) directInstallInstallation(env config.Env, params *agentparam
132132
}
133133
packageToInstall := matches[0]
134134
env.Ctx().Log.Info(fmt.Sprintf("Found local package to install %s", packageToInstall), nil)
135-
uploadCmd, err := h.Host.OS.FileManager().CopyFile("copy-agent-package", pulumi.String(packagePath), pulumi.String("./"), baseOpts...)
135+
uploadCmd, err := h.Host.OS.FileManager().CopyToRemoteFile("copy-agent-package", pulumi.String(packagePath), pulumi.String("./"), baseOpts...)
136136
if err != nil {
137137
return nil, err
138138
}

0 commit comments

Comments
 (0)