modules 명령

modules 명령

terraform modules 명령은 현재 작업 디렉터리의 Terraform 구성에서 선언된 모든 Terraform 모듈을 전체적으로 보여 주는 명령이에요. 모듈 사용 현황을 감사(audit)하거나 모듈 소비에 대한 정책을 설정할 때 유용해요. terraform modules의 출력에는 각 선언된 모듈의 키(key), 소스(source), 버전이 포함돼요.

출처: 문서

본문

참고: terraform modules 명령은 Terraform v1.10.0 이상이 필요해요.

사용법 (Usage)

terraform modules [options]

다음 선택적 플래그를 사용할 수 있어요.

  • -json: 모듈 선언을 기계가 읽을 수 있는 JSON 형식으로 표시함.
  • -var 'NAME=VALUE': 구성의 루트 모듈에 선언된 단일 입력 변수에 값을 설정함. 여러 변수를 설정하려면 이 옵션을 여러 번 사용해요. 자세한 내용은 Input Variables on the Command Line 문서를 참고해 주세요.
  • -var-file=FILENAME: .tfvars 파일의 정의를 사용해서 구성의 루트 모듈에 선언된 여러 입력 변수에 값을 설정함. 여러 파일의 값을 포함하려면 이 옵션을 여러 번 사용해요. -var-var-file 옵션 외에도 루트 모듈의 입력 변수에 값을 설정하는 여러 방법이 있어요. 자세한 내용은 Assign values to input variables 문서를 참고해 주세요.

terraform modules -json의 출력에는 format_version 키가 포함되며, Terraform 1.10.0에서는 이 값이 "1.0"으로 설정돼요. 이 버전의 의미는 다음과 같아요.

  • "1.1" 같은 마이너 버전의 경우 변경이나 추가는 하위 호환이 유지돼요. 앞으로 나올 마이너 버전과의 호환성을 유지하려면 인식하지 못하는 객체 속성은 무시해요.
  • "2.0" 같은 메이저 버전의 경우 변경은 하위 호환이 되지 않아요. 지원하지 않는 메이저 버전을 보고하는 입력은 거부해요.

새 메이저 버전은 Terraform 1.0 Compatibility Promises 범위 안에서만 도입할 거예요.

출력 형식 (Output Format)

terraform modules 명령은 구성 안의 모듈 구성과 계층을 나타내는 중첩 구조를 반환해요.

다음 예시는 추가 플래그 없이 terraform modules 명령이 반환하는 내용을 보여 줘요.

Modules declared by configuration:

.
├── "my_private_registry_module"[app.terraform.io/hashicorp/label/null] 1.0.0 (>=1.0.0, < 2.0.1)
├── "my_public_registry_module"[terraform-aws-modules/iam/aws] 5.47.1 (>5.0.1)
└── "my_local_module_a"[./path/to/local/module_a]
    └── "my_local_module_b"[./path/to/local/module_a/module_b]
        └── "my_local_module_c"[./path/to/local/module/module_a/module_b/module_c]

다음 예시는 terraform modules -json이 반환하는 JSON 출력 형식의 표현이에요.

{
    "format_version": "1.0",
    "modules": [
        {
            "key": "my_private_registry_module",
            "source": "app.terraform.io/hashicorp/label/null",
            "version": "1.0.0"
        },
        {
            "key": "my_public_registry_module",
            "source": "terraform-aws-modules/iam/aws",
            "version": "5.47.1"
        },
        {
            "key": "my_local_module_a",
            "source": "./path/to/local/module_a",
            "version": ""
        },
        {
            "key": "my_local_module_b",
            "source": "./path/to/local/module_a/module_b",
            "version": ""
        },
        {
            "key": "my_local_module_c",
            "source": "./path/to/local/module/module_a/module_b/module_c",
            "version": ""
        },
    ]
}

더 알아보기 (Learn more)

  • terraform init 명령
  • Terraform 모듈 개요 문서
  • Input Variables on the Command Line 문서
  • Terraform CLI 명령 목록