【发布时间】:2023-01-29 23:30:19
【问题描述】:
我有以下简单的 EC2 创建地形脚本:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = "default"
region = "us-east-1" # virginia
}
resource "aws_network_interface" "network" {
subnet_id = "subnet-0*******"
security_groups = ["sg-******"]
attachment {
instance = aws_instance.general_instance.id
device_index = 0
}
}
resource "aws_instance" "general_instance" {
ami = "ami-00874d747dde814fa" # unbutu server
instance_type = "m5.2xlarge"
key_name = "my-key"
root_block_device {
delete_on_termination = true
volume_size = 500
tags = { Name = "Root Volume" }
}
# user_data = file("startup.sh") # file directive can install stuff
tags = {
Name = "General"
}
}
我得到以下信息:
Error: Error launching source instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
我觉得这很奇怪,因为经典的流程是创建一个 VPC,创建一个子网,然后创建一个网络接口。但是,我有一个我想使用的 VPC,它与我正在使用的子网相关联。所以我想知道如果我将它与我请求的子网相关联,它会要求一个 VPC id。
提前致谢
【问题讨论】:
标签: terraform terraform-provider-aws