4

terraform.tfvars 与 variables.tf 区别

 2 years ago
source link: https://mednoter.com/terraform-variable-files.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

terraform.tfvars 与 variables.tf 区别

Terraform 项目中会定义两个与变量相关的文件:variables.tf 和 terraform.tfvars。

他们之间有什么区别?

variables.tf

variables.tf 用来定义变量,比如变量名,类型,有点像写代码时函数的参数定义。

在以下范例文件中我定义了两个变量 project 和 environment,他们的类型是 string。

# variables.tf
# Input variable definitions

variable "project" {
  description = "project name"
  type = string
}

variable "environment" {
  description = "the environment of project, e.g. production, sandbox, staging"
  type = string
}

terraform.tfvars

terraform.tfvars 类似于一个 .env 文件,保存了一些 key-value,用来批量给变量赋值。

project = "paylocity"
environment = "sandbox"
  1. Stack Overflow: terraform.tfvars vs variables.tf difference [duplicate]
  2. Stack Overflow: What is the difference between variables.tf and terraform.tfvars?
  3. [Stack Overflow: Terraform: how to declare a variable as required (or optional) in variables.tf?)(https://stackoverflow.com/questions/68187296/terraform-how-to-declare-a-variable-as-required-or-optional-in-variables-tf/68187417#68187417)
吕小荣
30 June 2021

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK