我正在尝试使用现有资源使用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,安全组,密钥名称它们已经存在,当尝试使用现有资源旋转实例时,它给出错误,如何纠正?
答案 0 :(得分:1)
aws_instance
resource根本没有使用vpc_id
参数,因此错误很容易解释。
设置subnet_id
会推断出VPC ID,因为子网只能存在于单个VPC中。