terraform.tfvars 생성

.tfvars 파일은 시크릿 값들을 로컬에 저장해놓고 env파일처럼 사용하는 파일로 커밋하면 안된다.

aws_access_key_id = "sensitive value"
aws_secret_access_key = "sensitive value"

variables.tf 생성

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
}

Value 가져오는 순서

Terraform에서는 변수를 주입시키는 방법이 다양하다. 만약 겹칠 경우, 아래와 같은 순서로 변수를 가져온다.

참고

Input Variables - Configuration Language | Terraform | HashiCorp Developer