HCL (HashiCorp Configuration Language)
- Hashicorp 사에서 개발한 툴을 이용하기 위한 언어 (ex: Terraform, Packer, Vault, 기타 등등...)
- JSON 형식을 지원
- Variables를 통해 resource 선언에 필요한 값을 입력 (like functions arguments)
- Outputs를 통해 resource 생성 후 필요한 정보를 출력 (like function return values)
- Local을 통해 변수로 활용 (like a function's temporary local variables)
- string interpolation 지원 ( ${...} )
- string directive ( %{...} )
"Hello, %{ if var.name != "" }${var.name}%{ else }unnamed%{ endif }!"
Meta-Arguments
- terraform에서 resource 선언 시에 사용할 수 있는 argument들
- providers : provider 설정
module "example" {
source = "./example"
providers = {
aws = aws.usw2
}
}
- depends_on : 의존성 설정
resource "aws_instance" "example" {
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
iam_instance_profile = aws_iam_instance_profile.example
depends_on = [
aws_iam_role_policy.example,
]
}
- count : 같은 작업이 필요한 경우
resource "aws_instance" "server" {
count = 4 # create four similar EC2 instances
ami = "ami-a1b2c3d4"
instance_type = "t2.micro"
tags = {
Name = "Server ${count.index}"
}
}
- for_each : 반복 탐색이 필요한 경우
resource "aws_iam_user" "the-accounts" {
for_each = toset( ["Todd", "James", "Alice", "Dottie"] )
name = each.key
}
기본 문법
<BLOCK TYPE> "<BLOCK LABEL>" "<BLOCK LABEL>" {
# Block body
<IDENTIFIER> = <EXPRESSION> # Argument
}
resource "aws_vpc" "main" {
cidr_block = var.base_cidr_block
}
출처
https://www.terraform.io/language
https://octopus.com/blog/introduction-to-hcl-and-hcl-tooling
https://www.terraform.io/language/values
'IT > Devops' 카테고리의 다른 글
[Terraform] Block type (0) | 2022.04.06 |
---|---|
[Terraform] Module 기본 구조 (0) | 2022.03.16 |
[Terraform] State, Terraform Cloud (0) | 2022.03.14 |
[Terraform] windows에서 Terraform Cloud 사용 순서 (0) | 2022.03.14 |
Devops Roadmap (0) | 2022.02.27 |
댓글