问题描述
variables.tf
和 terraform.tfvars
有什么区别?两者都可以为变量定义(赋值)对吗?这两者中定义的变量的范围或行为有什么不同吗?至于给变量赋值,可以用一个代替另一个吗?
What is the difference between variables.tf
and terraform.tfvars
? Both can define (assign values) to variables right? Is there any difference in scope or behavior of variables defined in these two? As far as assigning values to variables, can one be used in place of the other?
推荐答案
variables.tf
- 在这里,您定义必须具有值的变量,以便 Terraform 代码验证和运行.您还可以在此文件中定义变量的默认值.请注意,您不需要在名为variables.tf
的文件中定义所有变量 - 它们可以在任何地方定义,但出于组织目的,鼓励这种做法.variables.tf
- here, you define the variables that must have values in order for your Terraform code to validate and run. You can also define default values for your variables in this file. Note that you don't need to define all of your variables in a file namedvariables.tf
- they can be defined anywhere, but this practice is encouraged for organizational purposes.terraform.tfvars
- 此文件包含一个或多个variablename
=variablevalue
对.当 Terraform 加载此文件时,它会在 Terraform 中查找名称为variablename
的任何变量,并将其值设置为variablevalue
.此处不能定义新变量,只能设置variables.tf
中定义的已有变量的值.terraform.tfvars
- this file contains one or morevariablename
=variablevalue
pairs. When Terraform loads this file, it looks for any variables in your Terraform with the namevariablename
and sets their value to bevariablevalue
. You can't define new variables here, and can only set the values of existing ones defined invariables.tf
.这篇关于variables.tf 和 terraform.tfvars 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!