variables.tf 和 terraform.tfvars 有什么区别? [英] What is the difference between variables.tf and terraform.tfvars?

查看:30
本文介绍了variables.tf 和 terraform.tfvars 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

variables.tfterraform.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 named variables.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 more variablename=variablevalue pairs. When Terraform loads this file, it looks for any variables in your Terraform with the name variablename and sets their value to be variablevalue. You can't define new variables here, and can only set the values of existing ones defined in variables.tf.

      这篇关于variables.tf 和 terraform.tfvars 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆