ephemeralasnull 함수 레퍼런스

ephemeralasnull 함수 레퍼런스

ephemeralasnull 함수는 일시적(ephemeral) 값을 받아서 null을 돌려줘요. 객체에 중첩된 일시적 값이 있으면 그 값을 모두 null로 바꿔주는 방식으로, 일시적 값을 무효화(nullify)하는 데 사용할 수 있어요. 이 함수는 Terraform v1.10 이상에서 사용할 수 있어요.

출처: 문서

본문

참고: ephemeralasnull 함수는 Terraform v1.10 이상에서 사용할 수 있어요.

이 주제는 ephemeralasnull 함수에 대한 참고 정보를 제공해요. ephemeralasnull 함수는 일시적 값을 받아서 null을 돌려줘요.

Introduction (소개)

ephemeralasnull 함수를 사용해서 일시적 값을 무효화할 수 있어요. 예를 들어 중첩된 일시적 값이 있는 객체를 ephemeralasnull에 넘기면, 그 객체 안의 모든 일시적 값이 null이 돼요.

Syntax (문법)

ephemeralasnull 함수는 다음 문법으로 사용해요:

ephemeralasnull(var.my_ephemeral_value)

다음 예제에서는 ephemeralasnull 함수에 일시적 값을 넘길 수 있고, 함수는 null을 돌려줘요:

variable "example" {
  type      = string
  default   = "test"
  ephemeral = true
}

# This output returns null.
output "example_output" {
  value       = ephemeralasnull(var.example)
}

어떤 Terraform 블록이 일시적 값을 지원하는지에 대한 자세한 내용은 Manage sensitive data를 참고해요.

Example use case (사용 예시)

다음 예제는 ephemeralasnull 함수를 사용해서 일부 일시적 값을 포함한 맵을 받아, 일시적이지 않은 값만 출력하는 방법을 보여줘요.

variable "session_token" {
  type      = string
  default   = "test"
  ephemeral = true
}

variable "configuration" {
  type = map(string)
  default = {
    "env" = "development"
  }
}

# This is a contrived example, but this pattern works with any object that is a mix of ephemeral and non-ephemeral values.
locals {
  configuration_with_token = merge(
    var.configuration,
    { "session_token" = var.session_token }
  )
  ephemeral = true
}

output "configuration_settings" {
# Using ephemeralasnull enables you to output the non-ephemeral values.
  value       = ephemeralasnull(local.things_with_token)
  description = "Environment setting."
}

위 구성을 적용하면 Terraform은 locals.configuration_settings 안의 ephemeral 값을 null로 돌려줘요. 이렇게 하면 일시적이지 않은 값인 env를 출력할 수 있어요.

Outputs:

configuration_settings = {
  "env" = "development"
  "session_token" = tostring(null)
}

더 알아보기 (Learn more)