gpt4 book ai didi

amazon-web-services - 地形资源 : Connection Error while executing apply?

转载 作者:行者123 更新时间:2023-12-04 17:25:39 26 4
gpt4 key购买 nike

我正在尝试登录到 terraform 将使用以下代码创建的 ec2 实例:

resource "aws_instance" "sess1" {
ami = "ami-c58c1dd3"
instance_type = "t2.micro"
key_name = "logon"

connection {
host= self.public_ip
user = "ec2-user"
private_key = file("/logon.pem")
}

provisioner "remote-exec" {
inline = [
"sudo yum install nginx -y",
"sudo service nginx start"
]
}
}
但这给了我一个错误:
PS C:\Users\Amritvir Singh\Documents\GitHub\AWS-Scribble\Terraform> terraform apply
provider.aws.region
The region where AWS operations will take place. Examples
are us-east-1, us-west-2, etc.

Enter a value: us-east-1


Error: Invalid function argument

on Session1.tf line 13, in resource "aws_instance" "sess1":
13: private_key = file("/logon.pem")

Invalid value for "path" parameter: no file exists at logon.pem; this function
works only with files that are distributed as part of the configuration source
code, so if this file will be created by a resource in this configuration you
must instead obtain this result from an attribute of that resource.
如何在不登录控制台的情况下在运行时将 key 从资源保存到供应商?

最佳答案

您是否尝试过使用完整路径?如果您使用模块,则特别有用。
IE:

private_key = file("${path.module}/logon.pem")
或者我认为即使这样也会奏效
private_key = file("./logon.pem")
我相信您现有的代码正在寻找文件系统根目录下的文件。

关于amazon-web-services - 地形资源 : Connection Error while executing apply?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63613944/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com