Terraform 모듈 문제 해결 가이드
I’m happy to translate the article for you, but I need the full text you’d like translated. Could you please paste the content (or the portion you want translated) here? I’ll keep the source line and all formatting exactly as you requested.
증상
- 오류:
"variable_name"이라는 인수가 여기서는 예상되지 않습니다 - 오류: 이 객체에는
"output_name"이라는 속성이 없습니다 - 변수/출력이 올바르게 정의된 것처럼 보여도 이러한 오류가 발생합니다.
Source: …
Root Causes & Solutions
1. Stale Terraform Module Cache (Most Common)
모듈 변수나 출력값을 수정하면 Terraform이 캐시된 정보를 사용할 수 있습니다.
When to use: 모든 다음 변경 후:
- 모듈 변수 (
variables.tf) - 모듈 출력 (
outputs.tf) - 모듈 소스 경로
Solution: 캐시를 지우고 다시 초기화합니다.

2. Empty or Corrupted Files (Critical Issue)
파일이 존재하지만 0 바이트 데이터만 포함하고 있을 수 있습니다.
How to check: Length: 0 또는 0 bytes인 파일을 찾습니다.

Solution: 명령줄(또는 편집기)에서 파일을 다시 생성하여 올바르게 저장되었는지 확인합니다.


3. Missing Variable Definitions
Terraform이 모듈의 variables.tf에 존재하지 않는 변수를 보고합니다.
Solution: 누락된 변수를 modules//variables.tf에 추가합니다.

추가 후 캐시를 지우고 다시 초기화합니다(솔루션 #1 참고).
4. Missing Output Definitions
모듈이 참조되는 출력을 노출하고 있지 않습니다.
Solution: modules//outputs.tf에 출력을 추가합니다:
output "output_name" {
description = "Description"
value = azurerm_resource.resource_name.id
}
그런 다음 캐시를 지우고 다시 초기화합니다.
Source: …
진단 워크플로우
Step 1: 파일 구조 확인

확인 항목:
- 모든 필수 파일이 존재하는지
- 0 바이트 파일이 없는지
- 올바른 디렉터리 계층 구조인지
Step 2: 파일 내용 확인

Step 3: 캐시 정리 및 재초기화

Step 4: Terraform 버전 확인

예시 variables.tf:
variable "rg_name" {
description = "Resource group name"
type = string
}
variable "location" {
description = "Azure region"
type = string
}
예시 outputs.tf
output "resource_id" {
description = "ID of the created resource"
value = azurerm_resource.name.id
}
root/main.tf에서 예제 모듈 호출
module "example" {
source = "./modules/module_name"
rg_name = "my-rg"
location = "eastus"
}
# Reference module output
resource "other_resource" "example" {
dependency_id = module.example.resource_id
}
피해야 할 일반적인 실수
❌ 하지 말아야 할 것
- 파일을 저장하지 않고 편집하기 (VSCode에서 Ctrl + S)
- 모듈 변경 후
terraform init실행을 잊기 outputs.tf에 정의되지 않은 모듈 출력 사용variables.tf에 정의되지 않은 변수 전달
✅ 해야 할 것
- 항상 파일이 올바르게 저장되었는지 확인하기 (파일 크기 확인)
- 모듈 수정 후
.terraform캐시 정리하기 terraform fmt실행하여 코드 포맷팅하기terraform validate실행하여 오류를 조기에 잡기- 모듈 인터페이스(변수 / 출력)를 안정적으로 유지하기
빠른 참조 명령
모든 것이 실패할 때
1. 새로 시작하기

2. 각 모듈을 개별적으로 검증하기

