terraform state show 커맨드

terraform state show 커맨드

terraform state show 커맨드는 Terraform 상태 안의 단일 리소스 속성을 보여줘요. 상태 파일에서 주어진 주소와 일치하는 단일 리소스의 속성을 표시해요.

출처: 문서

본문

사용법 (Usage)

사용법: terraform state show [options] ADDRESS

이 커맨드는 상태 파일에서 주어진 주소와 일치하는 단일 리소스의 속성을 보여줘요.

이 커맨드는 상태의 단일 리소스를 가리키는 주소가 필요해요. 주소는 리소스 주소 지정 형식을 사용해요.

명령줄 플래그는 모두 선택사항이에요. 사용 가능한 플래그는 다음과 같아요:

-json 옵션을 통한 JSON 출력은 Terraform v1.16 이상이 필요해요.

JSON 출력 (JSON Output)

-json 명령줄 플래그를 추가하면 기계가 읽을 수 있는 출력을 생성해요. Terraform 상태 파일의 경우, 경로를 제공하지 않을 때를 포함해서 terraform state show -json은 요청한 리소스의 JSON 표현을 보여줘요.

상태가 작성된 이후 새 스키마 버전을 포함하는 프로바이더를 업데이트했다면, Terraform이 show -json으로 표시할 수 있도록 상태를 먼저 업그레이드하세요. 상태 파일을 보고 있다면 먼저 terraform refresh를 실행하세요.

이 커맨드의 일반적 출력 형식은 다음과 같아요:

{
  "format_version": "1.0", // the json format version
  "resource": { },         // the resource requested
  "diagnostics": []        // any diagnostics
}

리소스 출력 형식에 대한 자세한 내용은 JSON 출력 형식에서 다룹니다.

예제: 리소스 표시 (Example: Show a Resource)

아래 예제는 worker라는 packet_device 리소스를 보여줘요:

$ terraform state show 'packet_device.worker'
# packet_device.worker:
resource "packet_device" "worker" {
    billing_cycle = "hourly"
    created       = "2015-12-17T00:06:56Z"
    facility      = "ewr1"
    hostname      = "prod-xyz01"
    id            = "6015bg2b-b8c4-4925-aad2-f0671d5d3b13"
    locked        = false
}

예제: JSON 출력으로 리소스 표시 (Example: Show a Resource with JSON output)

아래 예제는 worker라는 packet_device 리소스를 json 출력 형식으로 보여줘요:

$ terraform state show 'packet_device.worker' -json
{
  "format_version": "1.0",
  "resource": {
    "address": "packet_device.worker",
    "mode": "managed",
    "type": "device",
    "name": "worker",
    "provider_name": "registry.terraform.io/hashicorp/packet",
    "schema_version": 0,
    "values": {
      "billing_cycle": "hourly",
      "created": "2015-12-17T00:06:56Z",
      "facility": "ewr1",
      "hostname":  "prod-xyz01",
      "id": "6015bg2b-b8c4-4925-aad2-f0671d5d3b13",
      "locked": "false"
    },
    "sensitive_values": {}
  },
  "diagnostics": []
}

예제: 모듈 리소스 표시 (Example: Show a Module Resource)

아래 예제는 foo라는 모듈 안의 worker라는 packet_device 리소스를 보여줘요:

$ terraform state show 'module.foo.packet_device.worker'

예제: count로 구성된 리소스 표시 (Example: Show a Resource configured with count)

아래 예제는 count로 구성된 worker라는 packet_device 리소스의 첫 번째 인스턴스를 보여줘요:

$ terraform state show 'packet_device.worker[0]'

예제: for_each로 구성된 리소스 표시 (Example: Show a Resource configured with for_each)

다음 예제는 for_each 메타-인자로 구성된 worker라는 packet_device 리소스의 "example" 인스턴스를 보여줘요. 리소스 이름에 큰따옴표 같은 특수 문자가 포함되면 리소스 이름을 작은따옴표로 묶어야 해요.

Linux, Mac OS, UNIX:

$ terraform state show 'packet_device.worker["example"]'

PowerShell:

$ terraform state show 'packet_device.worker[\"example\"]'

Windows cmd.exe:

$ terraform state show packet_device.worker[\"example\"]

더 알아보기 (Learn more)