繁体   English   中英

terraform su.net不存在报错

[英]The subnet does not exist error in terraform

我想用 tf. 这是main.tf

resource "aws_elastic_beanstalk_application" "elasticapp" {
  name = var.elasticapp
}


resource "aws_elastic_beanstalk_environment" "beanstalkappenv" {
  name                = var.beanstalkappenv
  application         = aws_elastic_beanstalk_application.elasticapp.name
  solution_stack_name = var.solution_stack_name
  tier                = var.tier

  setting {
    namespace = "aws:ec2:vpc"
    name      = "VPCId"
    value     = var.vpc_id
  }
  setting {
    namespace = "aws:ec2:vpc"
    name      = "Subnets"
    value     = var.public_subnets
  }
  setting {
    namespace = "aws:elasticbeanstalk:environment:process:default"
    name      = "MatcherHTTPCode"
    value     = "200"
  }
  setting {
    namespace = "aws:elasticbeanstalk:environment"
    name      = "LoadBalancerType"
    value     = "application"
  }
  setting {
    namespace = "aws:autoscaling:launchconfiguration"
    name      = "InstanceType"
    value     = "t2.micro"
  }
  setting {
    namespace = "aws:ec2:vpc"
    name      = "ELBScheme"
    value     = "internet facing"
  }
  setting {
    namespace = "aws:autoscaling:asg"
    name      = "MinSize"
    value     = 1
  }
  setting {
    namespace = "aws:autoscaling:asg"
    name      = "MaxSize"
    value     = 2
  }
  setting {
    namespace = "aws:elasticbeanstalk:healthreporting:system"
    name      = "SystemType"
    value     = "enhanced"
  }

}

我在vars.tf中定义了变量。 这是provider.tf

provider "aws" {
  region = "eu-west-3"
}

当我尝试申请时,我收到以下消息

Error: ConfigurationValidationException: Configuration validation exception: Invalid option value: 'subnet-xxxxxxxxxxxxxxx' (Namespace: 'aws:ec2:vpc', OptionName: 'ELBSubnets'): The subnet 'subnet-xxxxxxxxxxxxxxx' does not exist.
│   status code: 400, request id: be485042-a653-496b-8510-b310d5796eef
│ 
│   with aws_elastic_beanstalk_environment.beanstalkappenv,
│   on main.tf line 9, in resource "aws_elastic_beanstalk_environment" "beanstalkappenv":
│    9: resource "aws_elastic_beanstalk_environment" "beanstalkappenv" {

我在 main.tf 中提供的 vpc 中创建了 su.net。

编辑:我只有一个 su.net。 编辑:添加 vars.tf

variable "elasticapp" {
  default = "pos-eb"
}
variable "beanstalkappenv" {
  type = string
  default = "pos-eb-env"
}
variable "solution_stack_name" {
  type = string
  default = "64bit Amazon Linux 2 v3.2.0 running Python 3.8"
}
variable "tier" {
  type = string
  default = "WebServer"
}
variable "vpc_id" {
  default = "vpc-xxxxxxxxxxx"
}
variable "public_subnets" {
  type = string
  default = "subnet-xxxxxxxxxxxxxxx"
}

好的,首先,检查错误信息是否正确。

如上所述,您有可能在错误的帐户/区域中工作。 因此,检查 terraform 是否可以使用数据源找到 su.net:

data "aws_subnet" "selected" {
  id = var.public_subnets # based on your code above, this is a single subnet_id
}

output "subnet_detail" {
  value = data.aws_subnet.selected
}

如果上述代码失败,则意味着 terraform 无法使用/查找该 su.net。 因此,如果 su.net 是由 terraform 创建的,则区域/别名/帐户有可能在通往此模块的途中混合在一起。 如果它是手动创建的并且您仅将 ID 用作手动输入的字符串,那么您很可能复制了错误的 su.net_id、vpc_id 或者您在错误的帐户/区域中工作。

如果如上返回数据,terraform确实可以查到那个su.net,检查是否属于你在elastic_beanstalk上使用的VPC。 如果以上所有内容都正确,则问题可能出在“aws_elastic_beanstalk_environment”定义中。

由于您有一个 ELBScheme,但您没有与该 ELB 相关的字段的 rest,因此它可能会引发错误。 由于“aws_elastic_beanstalk_environment”定义中未提供 ELBSu.nets,它可能会尝试使用默认 vpc 中的默认 su.net。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM