【问题标题】:Terraform simple script says "Error: Error launching source instance: VPCIdNotSpecified: No default VPC for this user"Terraform 简单脚本显示“错误:启动源实例时出错:VPCIdNotSpecified:此用户没有默认 VPC”
【发布时间】:2021-08-30 13:15:50
【问题描述】:

开始使用 Terraform。我正在尝试使用以下 .tf 文件配置 EC2 实例。我在尝试预置 EC2 实例的 AZ 中的账户中已有默认 VPC。

# Terraform Settings Block
 terraform {
      required_providers {
         aws = {
             source  = "hashicorp/aws"
             #version = "~> 3.21" # Optional but recommended in production
        }
     }
 }

  # Provider Block
  provider "aws" {
        profile = "default"
        region  = "us-east-1"
  }

  # Resource Block
  resource "aws_instance" "ec2demo" {
           ami           = "ami-c998b6b2" 
           instance_type = "t2.micro"
  }

我执行以下 Terraform 命令。

  1. 地形初始化
  2. 地形规划
  3. terraform 应用

aws_instance.ec2demo:正在创建...

错误:启动源实例时出错:VPCIdNotSpecified:没有此用户的默认 VPC。只有 EC2-Classic 和默认 VPC 支持 GroupName。 状态码:400,请求ID:04274b8c-9fc2-47c0-8d51-5b627e6cf7cc

在 ec2-instance.tf 第 18 行,资源“aws_instance”“ec2demo”中: 18:资源“aws_instance”“ec2demo”{

【问题讨论】:

    标签: terraform terraform-provider-aws


    【解决方案1】:

    正如错误提示的那样,它在 us-east-1 区域中找不到默认 VPC。 您可以在您的 VPC 中提供subnet_id 来创建您的实例,如下所示。

     resource "aws_instance" "ec2demo" {
               ami           = "ami-c998b6b2" 
               instance_type = "t2.micro"
               subnet_id = "subnet-0b1250d733767bafe"
      }
    

    【讨论】:

      猜你喜欢
      • 2021-12-02
      • 2020-12-17
      • 2015-12-14
      • 2018-09-01
      • 2021-01-18
      • 2023-04-02
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多