wardviaene / terraform-course

Course files for my Udemy course about Terraform
https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/?couponCode=TERRAFORM_GIT
1.59k stars 4.02k forks source link

Provision files via ssh connection : no such file or directory #48

Closed mungaij83 closed 3 years ago

mungaij83 commented 3 years ago

I have this on my connection. The goal is to copy a file to this server on ec2.

connection {
    type     = "ssh"
    host     = aws_instance.example[0].public_ip
    user     = "ec2-user"
    private_key ="${file(var.ssh_key_file_path)}"
  }

However terraform does not accept the content of the file as in the documentation. It tries to read the file content as if it were a file itself. Passing the file name also results in invalid key.

connection {
    type     = "ssh"
    host     = aws_instance.example[0].public_ip
    user     = "ec2-user"
    private_key =var.ssh_key_file_path
  }

The documentation says

private_key - The contents of an SSH key to use for the connection. These can be loaded from a file on disk using the file function. This takes preference over the password if provided.

Output: Error: stat -----BEGIN PRIVATE KEY----- . . . -----END PRIVATE KEY----- : no such file or directory

Question Has this behavior been modified? Or Am I missing something