简体   繁体   English

terraform su.net不存在报错

[英]The subnet does not exist error in terraform

I want to create elastic beanstalk with tf.我想用 tf. Here is the main.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"
  }

}

I have variables defined in vars.tf .我在vars.tf中定义了变量。 This is the provider.tf这是provider.tf

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

When I try to apply I get the following message当我尝试申请时,我收到以下消息

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" {

I created the su.net inside the vpc that I provided in main.tf.我在 main.tf 中提供的 vpc 中创建了 su.net。

EDIT: I have only one su.net.编辑:我只有一个 su.net。 EDIT: adding vars.tf编辑:添加 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"
}

Ok, so first, check if the error message is correct.好的,首先,检查错误信息是否正确。

As mentioned above, there is a chance you are working in the wrong account/region.如上所述,您有可能在错误的帐户/区域中工作。 So check if terraform can find that su.net by using a datasource:因此,检查 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
}

If the above code fails, that means terraform is not able to use/find that su.net.如果上述代码失败,则意味着 terraform 无法使用/查找该 su.net。 So, if the su.net was created by terraform there is a chance regions/alias/account got mixed on the way to this module.因此,如果 su.net 是由 terraform 创建的,则区域/别名/帐户有可能在通往此模块的途中混合在一起。 If it was manually created and you are only using the ID as manually inputted string, than the chances are that you copied the wrong su.net_id, vpc_id or that you are working in the wrong account/region.如果它是手动创建的并且您仅将 ID 用作手动输入的字符串,那么您很可能复制了错误的 su.net_id、vpc_id 或者您在错误的帐户/区域中工作。

If the above return data, and terraform can indeed find that su.net, check if it belongs to the VPC you are using on elastic_beanstalk.如果如上返回数据,terraform确实可以查到那个su.net,检查是否属于你在elastic_beanstalk上使用的VPC。 If all the above is correct, than the issue may by in the "aws_elastic_beanstalk_environment" definition.如果以上所有内容都正确,则问题可能出在“aws_elastic_beanstalk_environment”定义中。

As you have an ELBScheme but you don't have the rest of the fields related to that ELB it could be throwing an error.由于您有一个 ELBScheme,但您没有与该 ELB 相关的字段的 rest,因此它可能会引发错误。 Since ELBSu.nets was not provided in the "aws_elastic_beanstalk_environment" definition, it may be trying to use a default su.net from the default vpc.由于“aws_elastic_beanstalk_environment”定义中未提供 ELBSu.nets,它可能会尝试使用默认 vpc 中的默认 su.net。

暂无
暂无

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

相关问题 Terraform ENI 映射错误 - 不在 su.net 的地址范围内 - Terraform ENI Mapping error - does not fall within the subnet's address range 使用 terraform 在 aws_vpc 中创建 su.net 时出错 - Error creating subnet in aws_vpc with terraform Terraform 错误:错误:创建 Su.net:原始错误:代码 =“NetcfgInvalidSu.net”消息 =“Su.net'内部'在 virtual.network 中无效 - Terraform error: Error: creating Subnet: Original Error: Code="NetcfgInvalidSubnet" Message="Subnet 'internal' is not valid in virtual network 使用 terraform 创建 aws_db_su.net_group 抛出 Error creating DB Su.net Group: InvalidParameterValue - Create aws_db_subnet_group with terraform throw Error creating DB Subnet Group: InvalidParameterValue Terraform 在 su.net 上更改主机名 - Terraform change Hostname on subnet 如何加入terraform su.net变量 - How to join terraform subnet variable 使用 terraform 创建 Cloud composer 2 时,显示错误,即无法配置工作负载身份:身份池不存在 - While creating Cloud composer 2 using terraform, it is showing error i.e. Could not configure workload identity: Identity Pool does not exist 无法使用 terraform 云上的 terraform 模块更新 AWS 中 su.net 的名称 - Unable to update name of subnet in AWS using terraform module on terraform cloud Terraform 和 GCP - 在现有的共享 VPC 和子网中创建新的计算 VM - Terraform and GCP - Create new Compute VM in existing Shared VPC and Subnet Terraform AWS - 路由表关联 - 添加多个 su.net - Terraform AWS - route table association - add multiple subnet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM