Terraform 资源:执行应用时出现连接错误? [英] Terraform Resource: Connection Error while executing apply?

查看:36
本文介绍了Terraform 资源:执行应用时出现连接错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to login to ec2 instance that terraform will create with the following code:

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.

如何在不登录控制台的情况下在运行时将密钥从资源保存到供应商?

How do I save pass the key from resource to provisioner at runtime without logging into the console?

推荐答案

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

Have you tried using the full path? Especially beneficial if you are using modules. I.E:

private_key = file("${path.module}/logon.pem")

或者我认为即使这样也行

Or I think even this will work

private_key = file("./logon.pem")

我相信您现有的代码正在寻找文件系统根目录下的文件.

I believe your existing code is looking for the file at the root of your filesystem.

这篇关于Terraform 资源:执行应用时出现连接错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆