terraform - Terraform 变量中引用了未知资源

标签 terraform

我是 Terraform 的初学者。 我正在尝试执行 Terraform 入门指南中的以下代码。

provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region     = "${var.region}"
}

resource "aws_instance" "example" {
  ami           = "${lookup(var.amis, var.region)}"
  instance_type = "t2.micro"

  tags {
    Name = "newprovisionerstest"
  }

  provisioner "local-exec" {
    command = "echo ${aws_instance.example.public_ip} > ip_address.txt"
  }
}

output "ip" {
  value = "${aws_eip.ip.public_ip}"
}

当我运行时

terraform apply

terraform refresh

它给出以下错误:

Error: output 'ip': unknown resource 'aws_eip.ip' referenced in variable aws_eip.ip.public_ip

为什么会这样呢?是因为“aws_eip”资源没有在任何地方声明吗?

最佳答案

就像您自己所说,没有名为 ip 的 aws_eip 资源。 如果您使用

aws_instance.example.public_ip

它应该工作得很好

关于terraform - Terraform 变量中引用了未知资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47710135/

相关文章:

google-app-engine - Terraform:创建 App Engine 应用程序时出错:googleapi:错误 403:调用方没有权限,禁止

azure - Terraform Azure 后端问题

terraform - 错误 terraform init, plan , apply

amazon-web-services - AWS Lambda 不等待代码上传到 Terraform 脚本中的 S3 存储桶

Terraform API Gateway HTTP API - 获取错误 Insufficient permissions to enable logging

amazon-web-services - 带有资源策略的aws api网关的terraform循环依赖

emr - 我们可以将安全组添加\附加到 Terraform aws_cloudformation_stack 资源吗

google-cloud-platform - 获取 Terraform google_monitoring_notification_channel 资源的 Slack auth_token

amazon-web-services - Terraform 不更新 AWS 金丝雀代码

amazon-web-services - 为什么我收到 aws ExpiredToken : The security token included in the request is expired?