SSH 在 Windows 中无法使用 Terraform provisioner 连接类型

SSH isnt working in Windows with Terraform provisioner connection type

我尝试使用 Terraform 在 AWS 中创建实例并尝试将一组文件复制到新创建的 AWS 实例中。我使用 "provisioner" 相同但对于连接,它总是说连接超时。

在下面的示例中,我展示了它的 AWS Pem 文件,但我同时尝试了 ppk 和 pem 文件。没有任何效果。

provider "aws" {
    region = "ap-southeast-1"
    access_key = "${var.access_key}"
    secret_key = "${var.secret_key}"
}
resource "aws_instance" "firsttest" {
    ami = "ami-061eb2b23f9f8839c"
    instance_type = "t2.micro"
    key_name = "deepak"
    provisioner "file" {
        source      = "index.html"
        destination = "/home/ubuntu/index.html"
    connection {
        type     = "ssh"
        user     = "ubuntu"
        private_key = file("D:/awskeyterraform/deepak.pem")
        host = "${aws_instance.firsttest.public_ip}"
        }
    }
    user_data = <<-EOF
        #!/bin/bash
        apt-get update -y
        apt-get install -y nginx
        systemctl enable nginx
        service nginx restart
        touch index.html
        EOF
    tags = {
        name = "terraform-firsttest"
    }
}

预期应该复制 index.html 但实际连接超时连接到新创建的实例

在Windows中,SSH模块连接不接受“*.pem”。相反,它在将 PEM 文件重命名为 "id_rsa" 后接受它。

provider "aws" {
    region = "ap-southeast-1"
    access_key = "${var.access_key}"
    secret_key = "${var.secret_key}"
}
resource "aws_instance" "firsttest" {
    ami = "ami-061eb2b23f9f8839c"
    instance_type = "t2.micro"
    key_name = "deepak"
    provisioner "file" {
        source      = "index.html"
        destination = "/home/ubuntu/index.html"
    connection {
        type     = "ssh"
        user     = "ubuntu"
        private_key = "${file("D:/awskeyterraform/id_rsa")}"
        host = "${aws_instance.firsttest.public_ip}"
        }
    }
    user_data = <<-EOF
        #!/bin/bash
        apt-get update -y
        apt-get install -y nginx
        systemctl enable nginx
        service nginx restart
        touch index.html
        EOF
    tags = {
        name = "terraform-firsttest"
    }
}

希望这能解决问题。