我有一个创建子模块的模块,每个子模块都有一个 custom_error_response ,它指向不同的 response_page_path。
在我添加的主模块中;
custom_error_response = [
{
error_code = "403"
error_caching_min_ttl = "30"
response_code = "200"
response_page_path = "/${var.default_root_object}"
},
]
并且变量 default_root_object 是:
variable "default_root_object" {
description = "Default root object at origin for CloudFront distribution"
}
在子模块中,我在 variables.tf 中添加了以下内容:
variable "custom_error_response" {
description = "(Optional) - List of one or more custom error response element maps"
type = "list"
default = []
}
在每个子模块的 main.tf 中,我还定义了 custom_error_response,如下所示:
dynamic "custom_error_response" {
for_each = var.custom_error_response
content {
error_caching_min_ttl = lookup(custom_error_response.value, "error_caching_min_ttl", null)
error_code = custom_error_response.value.error_code
response_code = lookup(custom_error_response.value, "response_code", null)
response_page_path = lookup(custom_error_response.value, "response_page_path", null)
}
}
当我运行 terraform init 时没问题,但是当我运行 terraform plan 时,对于我制作的 8 个子模块,它给了我 8 次相同的错误。
Error: Invalid value for module argument
on portal_distribution/main.tf line 32, in module "**mainmodule**":
32: custom_error_response = [
33: {
34: error_code = "403"
35: error_caching_min_ttl = "30"
36: response_code = "200"
37: response_page_path = "/${var.default_root_object}"
38: },
39: ]
The given value is not suitable for child module variable
"custom_error_response" defined at
.terraform/modules/**submodule**_portal.**mainmodule**/modules/aws-terraform-cloudfront_s3_origin/variables.tf:302,1-33:
element 0: string required.
如何修复错误?