Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload failed: scp: /etc/init.d/sample: Permission denied in file provisioning #8238

Closed
alexraju91 opened this issue Aug 16, 2016 · 5 comments

Comments

@alexraju91
Copy link

Terraform Version

Terraform v0.7.0

Affected Resource(s)

  • provisioner "file"

Terraform Configuration Files

resource "null_resource" "sample" {
connection {
host = "${aws_instance.abc.public_ip}"
user = "centos"
agent = true
}
provisioner "file" {
source = "${path.module}/startup-script.sh"
destination = "/etc/init.d/sample"
}

Debug Output

2016/08/16 19:27:25 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:25 connecting to TCP connection for SSH
2016/08/16 19:27:25 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:25 handshaking with SSH
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 [DEBUG] Telling SSH config to forward to agent
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 [DEBUG] Setting up a session to request agent forwarding
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 opening new ssh session
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 [INFO] agent forwarding enabled
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 opening new ssh session
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 Starting remote scp process:  scp -vt /etc/init.d
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 Started SCP session, beginning transfers...
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 Copying input data into temporary file so we can read the length
2016/08/16 19:27:26 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/08/16 19:27:26 Beginning file upload...
Error applying plan:
2016/08/16 19:27:26 [DEBUG] root: eval: *terraform.EvalIf
2016/08/16 19:27:26 [DEBUG] root: eval: *terraform.EvalWriteState
2016/08/16 19:27:26 [DEBUG] root: eval: *terraform.EvalWriteDiff
2016/08/16 19:27:26 [DEBUG] root: eval: *terraform.EvalApplyPost
2016/08/16 19:27:26 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* Upload failed: scp: /etc/init.d/sample: Permission denied
2016/08/16 19:27:26 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* Upload failed: scp: /etc/init.d/sample: Permission denied
2016/08/16 19:27:26 [ERROR] root: eval: *terraform.EvalOpFilter, err: 1 error(s) occurred:

* Upload failed: scp: /etc/init.d/sample: Permission denied
2016/08/16 19:27:26 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* Upload failed: scp: /etc/init.d/sample: Permission denied
2016/08/16 19:27:26 [TRACE] [walkApply] Exiting eval tree: null_resource.abc
2016/08/16 19:27:26 [DEBUG] vertex provider.null (close), got dep: null_resource.abc
2016/08/16 19:27:26 [DEBUG] vertex provisioner.file (close), got dep: null_resource.abc
2016/08/16 19:27:26 [DEBUG] vertex root, got dep: provisioner.file (close)
2016/08/16 19:27:26 [DEBUG] vertex root, got dep: provider.null (close)
2016/08/16 19:27:26 [DEBUG] plugin: waiting for all plugin processes to complete...
2016/08/16 19:27:26 [DEBUG] plugin: /home/centos/terraform/terraform: plugin process exited

1 error(s) occurred:

* Upload failed: scp: /etc/init.d/sample: Permission denied
@kwilczynski
Copy link
Contributor

@alexraju your user ("centos") most likely has no permission to write files under the /etc/init.d directory directly. This is not an issue in Terraform as far as I can tell.

@mitchellh
Copy link
Contributor

Correct.

If your SSH user doesn't have access, what we recommend is using the file provisioner to upload to a place you can, then the remote shell provisioner to sudo (or similar) to move it.

@alexraju91
Copy link
Author

alexraju91 commented Aug 17, 2016

@mitchellh I'm already following the method mentioned in your comment.

@kwilczynski
Copy link
Contributor

@alexraju the "centos" user most likely has a sudo access, but I would be doubtful whether it has UID/GID set to 0 (which would denote a root-alike user).

You need to copy your script into the /tmp or /var/tmp directory and then use remote execution (the name is remote-exec) provisioner to cp or mv it into place (remember to adjust permission, since it is an init script).

@ghost
Copy link

ghost commented Apr 5, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashicorp hashicorp locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants