본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

호스트와 호스트 관리용 Terraform 패턴

원문 보기 위키 갱신

호스트와 호스트 관리용 Terraform 패턴 (Terraform patterns for hosts and host management)

Terraform 패턴으로 Boundary 호스트와 호스트 카탈로그를 만들고, 타깃이 연결하는 호스트 세트에 연결할 수 있어요.

이 페이지는 호스트와 호스트 카탈로그 생성을 다룹니다. 타깃에 연결하는 방법은 타깃 페이지를 참고하세요.

타깃 주소를 직접 정의해서 접근을 단순화할 수도 있지만, HashiCorp는 규모가 커졌을 때 그 패턴을 권장하지 않아요. 대신 호스트를 호스트 세트에 추가하고, 그 호스트 세트를 타깃에 연결할 것을 권장합니다.

호스트 카탈로그 유형 가장 적합한 경우
Static 작고 고정된, 수동으로 관리하는 호스트 목록
AWS 플러그인 태그/지역으로 EC2 호스트 자동 검색
Azure 플러그인 태그/지역으로 Azure 호스트 자동 검색

출처: HashiCorp Boundary docs

본문

사전 요구 사항

이 문서는 독자가 다음을 갖추고 있다고 가정합니다:

  • Terraform 기초에 대한 이해
  • 기존 Boundary 설치
  • Terraform Boundary 프로바이더 구성

정적(static) 호스트 카탈로그 구성

다음 예시는 Boundary 정적 호스트 카탈로그를 만들고 알려진 호스트를 그 카탈로그에 추가하는 방법을 보여줍니다.

# Create the host catalog
resource "boundary_host_catalog_static" "example" {
  name        = "My static catalog"
  description = "My static host catalog"
  scope_id    = boundary_scope.project.id
}

# Create the static host
resource "boundary_host" "example" {
  type            = "static"
  name            = "example_host"
  description     = "My first host"
  address         = "10.0.0.1"

  # Associate the host with the static host catalog
  host_catalog_id = boundary_host_catalog.static.id
}

정적 호스트 카탈로그는 관리 부담을 늘릴 수 있으므로 필요할 때만 사용해야 해요.

동적(dynamic) 호스트 카탈로그 구성

Amazon Web Services(AWS)나 Microsoft Azure 같은 클라우드 프로바이더를 사용하면, 플러그인 기반 호스트 카탈로그를 사용하는 것이 더 나은 패턴이에요. 이 카탈로그는 특정 클라우드의 필터 기준에 따라 호스트를 자동으로 검색합니다.

이 예시는 us-east-1의 AWS 호스트를 자동 검색하는 동적 호스트 카탈로그를 만듭니다.

resource "boundary_host_catalog_plugin" "aws_example" {
  name            = "My AWS catalog"
  description     = "My AWS dynamic host catalog"
  scope_id        = boundary_scope.project.id

  # Delare the cloud plugin to use and the region to search for hosts
  plugin_name     = "aws"
  attributes_json = jsonencode({ "region" = "us-east-1" })

  # Define the cloud credentials to use for searching
  secrets_json = jsonencode({
    "access_key_id"     = "aws_access_key_id_value",
    "secret_access_key" = "aws_secret_access_key_value"
  })
}

Azure 호스트 카탈로그 구성

이 호스트 카탈로그 예시는 Azure의 호스트를 검색합니다. AWS 예시와 매우 비슷하다는 점을 주목하세요.

resource "boundary_host_catalog_plugin" "azure_example" {
  name        = "My Azure catalog"
  description = "My Azure dynamic host catalog"
  scope_id    = boundary_scope.project.id
  plugin_name = "azure"

  # HashiCorp recommends providing Azure secrets using a file() or environment variables

  # The attributes below must be generated in Azure by creating an Entra ID application
  attributes_json = jsonencode({
    "disable_credential_rotation" = "true",
    "tenant_id"                   = "ARM_TENANT_ID",
    "subscription_id"             = "ARM_SUBSCRIPTION_ID",
    "client_id"                   = "ARM_CLIENT_ID"
  })

  # The secrets below must be generated in Azure by creating an Entra ID application
  secrets_json = jsonencode({
    "secret_value" = "ARM_CLIENT_SECRET"
  })
}

정적 호스트를 호스트 세트에 추가하는 구성

이 예시는 정적 호스트를 정적 호스트 세트에 추가합니다.

resource "boundary_host_set_static" "web" {
  host_catalog_id = boundary_host_catalog_static.example.id
  host_ids = [
    # This is the static Boundary host created in the example above.
    boundary_host_static.example.id
  ]
}

플러그인 기반 호스트를 호스트 세트에 추가하는 구성

플러그인 기반 호스트 카탈로그로 검색된 호스트는 boundary_host_set_plugin 호스트 세트에 추가해야 해요.

이 예시는 필터 기준으로 태그를 사용해서 AWS 호스트 카탈로그의 호스트를 호스트 세트에 추가하는 방법을 보여줍니다. 예시에서 필터는 service-type이라는 이름의 태그에서 값이 web인 것을 찾아요.

resource "boundary_host_set_plugin" "web" {
  name            = "My web host set plugin"

  # This is the AWS host catalog that was created above
  host_catalog_id = boundary_host_catalog_plugin.aws_example.id

  # This is the filter that looks for specific tags using AWS filtering syntax
  attributes_json = jsonencode({ "filters" = ["tag:service-type=web"] })
}

관련 호스트, 호스트 세트, 호스트 카탈로그 문서

이 주제에서 언급한 Boundary 리소스에 대한 자세한 내용은 도메인 모델 문서를 참고하세요:

Terraform으로 다음 리소스를 관리하는 방법에 대한 자세한 내용은 Boundary 프로바이더 문서를 참고하세요:

Boundary의 필터 구문과 모범 사례에 대한 자세한 내용은 필터링 및 리소스 나열을 참고하세요.

더 알아보기 (Learn more)

호스트를 구성했다면, 호스트와 사용자를 위한 자격 증명과 자격 증명 저장소를 구성하고 싶을 거예요.