Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SSH在具有Terraform provisioner连接类型的Windows中不工作_Terraform_Terraform Provider Aws - Fatal编程技术网

SSH在具有Terraform provisioner连接类型的Windows中不工作

SSH在具有Terraform provisioner连接类型的Windows中不工作,terraform,terraform-provider-aws,Terraform,Terraform Provider Aws,我尝试使用Terraform在AWS中创建实例,并尝试将一组文件复制到新创建的AWS实例中。我使用“provisioner”来表示相同的连接,但对于连接,它总是说连接超时 在下面的示例中,我展示了它的AWS Pem文件,但我尝试了ppk和Pem文件。什么都不管用 provider "aws" { region = "ap-southeast-1" access_key = "${var.access_key}" secret_key = "${var.secret_key

我尝试使用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"
    }
}
提供程序“aws”{
region=“ap-东南-1”
access_key=“${var.access_key}”
secret\u key=“${var.secret\u key}”
}
资源“aws_实例”“firsttest”{
ami=“ami-061EB23F9F8839C”
实例_type=“t2.micro”
key_name=“deepak”
供应器“文件”{
source=“index.html”
destination=“/home/ubuntu/index.html”
联系{
type=“ssh”
user=“ubuntu”
私钥=文件(“D:/awskeyterraform/deepak.pem”)
host=“${aws_instance.firsttest.public_ip}”
}
}

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

提供程序“aws”{
region=“ap-东南-1”
access_key=“${var.access_key}”
secret\u key=“${var.secret\u key}”
}
资源“aws_实例”“firsttest”{
ami=“ami-061EB23F9F8839C”
实例_type=“t2.micro”
key_name=“deepak”
供应器“文件”{
source=“index.html”
destination=“/home/ubuntu/index.html”
联系{
type=“ssh”
user=“ubuntu”
private_key=“${file(“D:/awskeyterraform/id_rsa”)}”
host=“${aws_instance.firsttest.public_ip}”
}
}

user_data=您没有定义任何安全组(AWS采用有状态防火墙),因此任何东西都不能进入或离开实例(包括SSH)。由于这是AWS的一个非常重要的方面,我现在会放弃terraform,并尝试使用控制台创建实例以了解EC2的基础知识,然后跳到terraform上。否则,您将要打两场大战。我已将默认安全组修改为any:any,当我在Linux b上执行相同操作时,它工作正常ut仅在windows中出现问题。我可以理解Linux默认有SSH代理,但在windows中没有!!!只是想知道如何在不在windows中安装任何SSH代理的情况下处理这种情况。@DeenaDeepak您应该能够使用WinRMprovisioner@ScottHeath,谢谢您的建议。WinRM Provisioner适用于Windows VM,但我可以管理d通过将“deepak.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"
    }
}