【问题标题】:VPCIdNotSpecified: No default VPC for this user error when doing terraform applyVPCIdNotSpecified:在执行 terraform 应用时,此用户错误没有默认 VPC
【发布时间】:2021-12-02 21:21:13
【问题描述】:

Terraform 新手在这里。

我正在使用Terraform in Action 书籍here。当我运行terraform apply 时,我收到VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC 错误。我已经安装了 AWS CLI 并使用 aws configure 配置了我的 AWS 凭证。我的 AWS 凭证存在于 %UserProfile%\.aws\credentials 文件中。

我错过了什么?

ma​​in.tf

provider "aws" {
    region = "us-west-2"
}
resource "aws_instance" "helloworld" {
    ami = "ami-09dd2e08d601bff67"
    instance_type = "t2.micro"
    tags = {
        Name = "HelloWorld"
    }
}

错误堆栈跟踪:

aws_instance.helloworld: Creating...
╷
│ Error: Error launching source instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
│       status code: 400, request id: 1e0911db-300b-4c00-aea1-dad588bbe40e
│
│   with aws_instance.helloworld,
│   on main.tf line 4, in resource "aws_instance" "helloworld":
│    4: resource "aws_instance" "helloworld" {
│

【问题讨论】:

    标签: amazon-web-services terraform terraform-provider-aws


    【解决方案1】:

    您在us-west-2 区域中似乎没有默认 VPC。

    既然你提到你刚刚开始使用 Terraform;当您想使用特定的资源/模块/提供者时,我强烈建议您参考official Terraform documentation

    在这种情况下,对于Resource: aws_instance,您可以查看所有属性都支持的内容。

    如果我是你,我会首先检查上述区域中是否有默认 VPC。很有可能没有。如果我知道 VPC 子网 ID,那么我只需将该值传递给 subnet_id 属性,Terraform 将确保我的实例将出现在正确的网络中。

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 2015-12-14
      • 2018-09-01
      • 2021-01-18
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      相关资源
      最近更新 更多