使用 variable 块定义变量:hcl复制variable "instance_type" { type = string default = "t2...使用模块(Modules)模块是 Terraform 中的可复用代码单元,可以将资源定义封装到模块中,并通过模块的输入变量动态传递参数。...使用数据源(Data Sources)数据源允许你在 Terraform 中动态获取外部数据,并将其作为参数传递...
variable "map_variable" { type = map default = { key1 = "value1,value2,value3" key2 = "value4,value5" } } locals { list_variable = [ for values in values(var.map_variable) : split(",", values) ] } output "list_output" { value = local.list_variable } 在上面的示例...
文件variables.tf variable"env_list"{type= list(string) description ="define environment name"default= ["dev"] } variable"dns_record"{type=map(string) description ="define dns name"} variable"ecs_info"{type= object({ ecs_image =string, ecs_name =string}) description ="define ecs info"} ...
name的类型是string而service_delegation的类型是另一个object,像这样的结构就不是map可以描述的了。 小结 由于Terraform 自身的一些设计问题,导致在设计 Module 的 Variable 类型时可能没有一个可以遵循的统一的标准。假如多个独立的variable那么descritpion的可读性最好,但如果涉及到作为是否创建某个资源的判断条件时,...
这一章笔记总结一下变量在Terraform里面的定义和使用。 变量在Terraform里面可以通过多种方式来定义: 系统的环境变量 命令行里面指定 从文件里面指定 从variable default的值指定 下面来看几个例子 例1 我创建一个EC2, 把一个自定义的变量传给我的 instance_type ...
variable "instance_names" { type = list(string) default = ["instance-1", "instance-2", "instance-3"]} 映射用于表示键值对的集合。映射可以使用大括号定义{},键值对用逗号分隔:variable "instance_amis" { type = map(string) default = { us-west-2 = "ami-0c55b159cbfafe1f0" ...
variable_map = { "actiontrail_enabled" = "true", "actiontrail_ttl" = "180" } } 多账号采集 您可以通过自定义鉴权管理模式(中心账号为普通账号)或资源目录管理模式(中心账号必须为管理账号或者委派管理员账号)配置多账号采集。更多信息,请参见配置多账号采集。
terraform的hcl语言包含一些元参数,在resource、output、variable等资源块下可使用。这些经常被用到的元参数是count,for_each,for。 count 用于同时创建多个相同资源,count_index作为索引。 variable "name_list" { type = list(string) default = ["vpc_demo1", "vpc_demo2"] ...
variable"region"{type = stringdescription ="region name"default ="cn-beijing"sensitive = true} Variable参数类型 any string number bool list() set() map() object([ATTR_NAME = ATTR_TYPE, ...) tuple([, ...]) VariableMap 示例:使用map类型的变量来定义DNS域名 ...
variable 参数类型 any string number bool list set map object tuple map DNS # variable"dns_record"{ type=map(string) description="custom dns record" } 1. 2. 3. 4. 5. # terraform.tfvars dns_record={ "dev"="dev.", "stag"="stag.", ...