[英]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.