.tfvars 파일은 시크릿 값들을 로컬에 저장해놓고 env파일처럼 사용하는 파일로 커밋하면 안된다.
aws_access_key_id = "sensitive value"
aws_secret_access_key = "sensitive value"
terraform.tfvars파일에 변수를 정의해놓는다고 바로 사용할 수 있는 게 아니라 따로 variables.tf에 정의해주어야 한다.
variable "aws_access_key_id" {
type = string
description = "The AWS access key ID"
sensitive = true
}
variable "aws_secret_access_key" {
type = string
description = "The AWS secret access key"
sensitive = true
}
Terraform에서는 변수를 주입시키는 방법이 다양하다. 만약 겹칠 경우, 아래와 같은 순서로 변수를 가져온다.
terraform.tfvars file, if present.terraform.tfvars.json file, if present..auto.tfvars or .auto.tfvars.json files, processed in lexical order of their filenames.var and var-file options on the command line, in the order they are provided. (This includes variables set by a Terraform Cloud workspace.)Input Variables - Configuration Language | Terraform | HashiCorp Developer