如何在Terraform云搜索资源中多次调用配置块
嗨,我正在尝试在云搜索index_field配置块中添加一个动态块,但是没有使用大量错误
resource "aws_cloudsearch_domain" "this" {
name = "${var.name}"
scaling_parameters {
desired_instance_type = "${var.instance_type}"
}
dynamic "index_field" {
for_each = var.index_field
content {
name = index_field.value["name"]
type = index_field.value["type"]
search = index_field.value["search"]
return = index_field.value["return"]
sort = index_field.value["sort"]
highlight = index_field.value["highlight"]
analysis_scheme = index_field.value["analysis_scheme"]
}
}
}
main.tf文件
module "cloudsearch" {
source = "./modules"
name = "demo"
instance_type = "search.2xlarge"
index_field = {
name = "hello"
type = "text"
index_name = "hello"
search = "true"
return = false
sort = false
highlight = true
analysis_scheme = "_en_default_"
}
}
var.tf文件 -
variable "name" {
type = string
description = "value"
}
variable "instance_type" {
type = string
description = "value"
}
variable "index_field" {
description = ""
type = any
default = null
}
我要低于错误
:错误:无效索引 │ │在模块/main.tf第18行上,在资源“ aws_cloudsearch_domain”中 │18:Analysis_scheme = index_field.Value [“ Analysis__scheme”] │├│├├届─-─-─-─-─-─-─..-─..- - ─- ││index_field.value是“文本” │ │此值没有任何索引。
感谢您会很感激,谢谢
Hi I'm trying to add a dynamic block in the cloud search index_field config block but no use getting a lot of errors
resource "aws_cloudsearch_domain" "this" {
name = "${var.name}"
scaling_parameters {
desired_instance_type = "${var.instance_type}"
}
dynamic "index_field" {
for_each = var.index_field
content {
name = index_field.value["name"]
type = index_field.value["type"]
search = index_field.value["search"]
return = index_field.value["return"]
sort = index_field.value["sort"]
highlight = index_field.value["highlight"]
analysis_scheme = index_field.value["analysis_scheme"]
}
}
}
main.tf file
module "cloudsearch" {
source = "./modules"
name = "demo"
instance_type = "search.2xlarge"
index_field = {
name = "hello"
type = "text"
index_name = "hello"
search = "true"
return = false
sort = false
highlight = true
analysis_scheme = "_en_default_"
}
}
var.tf file -
variable "name" {
type = string
description = "value"
}
variable "instance_type" {
type = string
description = "value"
}
variable "index_field" {
description = ""
type = any
default = null
}
I'm getting below error
│ Error: Invalid index
│
│ on modules/main.tf line 18, in resource "aws_cloudsearch_domain" "this":
│ 18: analysis_scheme = index_field.value["analysis_scheme"]
│ ├────────────────
│ │ index_field.value is "text"
│
│ This value does not have any indices.
help would be appreciated, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题是您使用的是
index_field
变量的键,但值是整个块。因此,您需要另一个将充当占位符密钥的密钥,因此可以通过其键的名称访问与该密钥相关的值。换句话说,当前变量的解释方式是:为了按照您设想的方式工作,需要对将变量传递给儿童模块的方式进行一些修改:
请注意,您可以可以从变量中获取值时也使用不同的语法:
该计划显示:
The issue here is that you are using the key of
index_field
variable but the value is the whole block. So you need another key which will act as a placeholder key so the values related to that key can be accessed by the names of their keys. In other words, the way the variable is currently interpreted is:In order for this to work the way you have envisioned it, there needs to be a slight modification to the way you are passing the variable to the child module:
Note that you can also use a different syntax when getting the values from the variable:
The plan shows this: