我有这个文件结构它包含两个根模块,我分别从它们中应用。我想在一个模块中访问从不同根目录输出的模块
module "lambda" {
source = "../../modules/lambda"
environment = var.environment
clean-bucket-name = "../flow-components/module.s3.clean-bucket-name"
infected-bucket-name = "../flow-components/module.s3.infected-bucket-name"
after-classification-bucket-name = module.s3.after-classification-bucket-name
}
这是尝试访问模块的两个示例。
第一个只要给这个字符串第二个给我这个错误
│ Error: Reference to undeclared module
│
│ on lambda.tf line 8, in module "lambda":
│ 8: after-classification-bucket-name = module.s3.after-classification-bucket-name
│
│ No module call named "s3" is declared in the root module.
这是的第二个模块
module "s3" {
source = "../../modules/s3"
environment = var.environment
}
以及该模块的输出文件
output "before-av-bucket-name" {
value = aws_s3_bucket.before-av-bucket.bucket
}
output "clean-bucket-name" {
value = aws_s3_bucket.clean-bucket.bucket
}
output "infected-bucket-name" {
value = aws_s3_bucket.infected-bucket.bucket
}
output "after-classification-bucket-name" {
value = aws_s3_bucket.after-classification-bucket.bucket
}
文件结构
├───environment
│ ├───flow-components
│ │ ├───provider
│ │ ├───s3
│ ├───lambdas
│ │ ├───provider
│ │ ├─── lambda
└───modules
├───lambda
└───s3
如何访问此模块的输出?
您没有使用有效的Terraform语法。要引用模块的输出,您不需要将其指定为文件路径。after-classification-bucket-name
属性中有正确的语法,所以我不确定您要对其他两个属性做什么。
正确的语法是:
module "lambda" {
source = "../../modules/lambda"
environment = var.environment
clean-bucket-name = module.s3.clean-bucket-name
infected-bucket-name = module.s3.infected-bucket-name
after-classification-bucket-name = module.s3.after-classification-bucket-name
}