wardviaene / terraform-course

Course files for my Udemy course about Terraform

Home Page:https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/?couponCode=TERRAFORM_GIT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provision files via ssh connection : no such file or directory

mungaij83 opened this issue · comments

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