由于Terraform 自身的一些设计问题,导致在设计 Module 的 Variable 类型时可能没有一个可以遵循的统一的标准。假如多个独立的variable那么descritpion的可读性最好,但如果涉及到作为是否创建某个资源的判断条件时,就要考虑使用object或是map进行封装;object可以包含不同类型的成员,但很难在不破坏向前兼容的情况下进行扩展;...
variable "instance_config" { type = object({ name = string ami = string type = string subnet = string }) default = { name = "instance-1" ami = "ami-0c55b159cbfafe1f0" type = "t2.micro" subnet = "subnet-0c55b159cbfafe1f0" }...
Terraform 默认读取terraform.tfvars variable 可选参数 variable"region"{ type=string description="region name" default="cn-beijing" sensitive=true } 1. 2. 3. 4. 5. 6. default 变量的默认值 type 变量的类型 describtion 变量的描述信息 ...
文件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"} ...
I am trying to write a clear documentation/description of my terraform modules. According to Hashicorp's doc, the description attribute will permit that, but I cannot find a way to describe an object type variable in details.Here's more or less I want to do :...
变量的使用都是使用variable关键字,后面跟上变量的名称,块里面有变量的类型。 只需要将模块当中经常变化的部分声明为变量,类似于shell。 这些变量也可以跨不同的模块去共享,比如像region信息,当我们有多个模块的时候,既然在同一个region下面,我们就不需要声明很多这种变量了,这样可以实现组合和重用。
环境变量(TF_VAR_<variable_name>) exportTF_VAR_server_port = 8080 type# 允许对用户输入的变量类型进行强制约束; 包含string、number、bool、list、map、set、object、tuple、any(默认约束类型为any) string# 字符串 variable"map_example"{ description ="an example of a map in terrform"type=map(string...
variable"docker_ports"{ type=list(object({ internal=number external=number protocol=string })) default=[ { internal=8300 external=8300 protocol="tcp" } ] } variable关键字后为变量名。在一个 Terraform 模块(同一个文件夹中的所有 Terraform 代码文件,不包含子文件夹)中变量名必须唯一。在代码中可以通...
variable"ami"{type=object({# 仅使用模块所需的属性子集声明对象。 # Terraform 将允许任何至少具有这些属性的对象。 id=string architecture=string})} 该模块的调用者现在可以自己直接表示这是要内联创建的 AMI 还是要从其他地方检索的 AMI: 代码语言:javascript ...
Terraform 数据类型分为 原始类型(string、number、bool) 与 复杂类型(list()、map()、set()、object、tuple),支持自定义输入变量variable、本地变量locals、输出变量output,以块的型式组织成.tf文件。 HCL是一个用于创建结构化配置语言的工具包,主要针对DevOps工具、服务器等。