无法使用 Terraform AWS VPC 模块派生 VPC ID

unable to derive VPC ID with Terraform AWS VPC module

我正在尝试在同一个模块中构建 aws vpc 和安全组。 我的项目中有这个结构:

.
├── README.md
├── commit.sh
├── main.tf
├── modules
│   └── networking
│       ├── README.md
│       ├── main.tf
│       ├── outputs.tf
│       └── variables.tf
├── plans
├── terraform.sh
├── variables.tf
├── vars
└── versions.tf

我在项目根目录中使用非常简单的 main.tf 调用模块:

## Networking
module "networking" {
  source = "./modules/networking/"
}

我需要安全组的 VPC ID,SG 被定义为与 VPC 模块相同的文件中的不同模块:

module "web_ingress_sg" {
  source = "terraform-aws-modules/security-group/aws//modules/http-80"

  name        = "wordpress-ingress"
  description = "Security group for web-server with HTTP ports open within VPC"
  vpc_id      = module.vpc.vpc_id

  ingress_cidr_blocks = ["50.82.222.12/32"]
  computed_egress_with_source_security_group_id = [
    {
      rule                     = "http-80-tcpp"
      source_security_group_id = module.wordpress_instance_sg.security_group_id
    },
  ]
}

VPC ID 在模块的 outputs.tf 文件中定义,但我不断收到错误消息“需要参数“vpc_id”,但未找到定义。”。 =13=]

模块不能引用它自己的输出。您必须直接获取 vpc id。假设您在此网络模块中定义了 vpc,那么以下内容就足够了:

vpc_id      = aws_vpc.vpc.vpc_id