使用Terraform在AWS上创建实例时出错

时间:2019-01-21 06:28:36

标签: terraform

我正在尝试使用现有资源使用Terraform在AWS上创建实例

下面是我的varibale.tf文件

variable "aws_vpc" {
  description = "VPC ID"
  default = "vpc-1234567b"
}

variable "subnet_prv1" {
  description = "Subnet ID"
  default = "subnet-1234567"
}

下面是我的ec2.tf文件

provider "aws" {
  access_key = "SDSFFDGRTYUYIJKH"
  secret_key = "sfdfKSFE3546/34sfsfSFDFSF89dv"
  region     = "ap-south-1"
}

resource "aws_instance" "terra-jd" {
  ami           = "ami-1234567"
  instance_type = "t2.micro"
  vpc_id        = "${var.aws_vpc}"
  subnet_id     = "${var.subnet_prv1}"
  key_name      = "AWS-IntIGRATION-APAC"
  security_groups = "MYORG-INT-Ser-Cluster-SG"
  tags {
  Name = "terra-jd-nirvana"
  }
}

当我尝试运行terraform apply时出现错误

Error: aws_instance.terra-jd: : invalid or unknown key: vpc_id

VPC,SUBNET,安全组,密钥名称它们已经存在,当尝试使用现有资源旋转实例时,它给出错误,如何纠正?

1 个答案:

答案 0 :(得分:1)

aws_instance resource根本没有使用vpc_id参数,因此错误很容易解释。

设置subnet_id会推断出VPC ID,因为子网只能存在于单个VPC中。