我需要根据调用资源时最终使用哪个变量(来自一组始终存在的预定义变量)来呈现模板。
例子:
变量.tf
possible_choice = "this"
another_choice = "that"
yet_another_choice = "then"
主文件
resource "instance" "this_name" {
image_id = var.possible_choice
user_data = templatefile( "my_template_file.tpl", {choice = image_id})
}
模板文件:
%{ if choice == ....) %{endif}
我无法完成的是传递选择在资源中实现的变量的值。
我无法检查变量是否为空(因为它们都在 variables.tf 中定义并且将返回一个字符串)。
我不能通过
instance.this_name
,因为命名不统一(可能是 ofthis_name.possible_choice
等等)。
如果可以提取其中包含的任何默认值instance.this_name.image_id
,那么我应该很高兴,我想。我尝试了多种方法,但大多数都得到了cannot refer to itself
,这是有道理的。
谢谢你。