Terraform 리소스 참조에 대한 중복 제거 영향 해결하기
Terraform 리소스 참조에 대한 중복 제거 영향 해결하기
identity 중복 제거 중 이름이 변경된 엔티티·그룹에 대한 Terraform 구성 파일의 외부 참조 동작을 수정해요.
전제 조건(Assumptions)
- Vault 1.19 이상을 실행 중이에요.
- 시스템 로그에 중복 제거 이름 변경 대상이 있어요.
- 관련 Vault 서버 또는 클러스터에 대한 관리자 권한이 있어요.
출처: 문서
본문
이름 변경이 외부 참조에 미치는 영향(How renaming affects external references)
엔티티와 그룹 이름을 바꾸면, 그 참조가 엔티티나 그룹을 이름으로 직접 가리킬 때 Terraform(그리고 다른 외부 서비스)의 참조가 깨질 수 있어요. 예를 들어 다음과 같은 명명된 identity 리소스가 있는 Terraform 구성 파일이 있다고 가정해요.
terraform {
required_providers {
vault = {
source = "hashicorp/vault"
}
}
}
provider "vault" {}
resource "vault_identity_entity" "BOB" {
name = "BOB"
policies = ["TEST"]
}
resource "vault_identity_entity" "bob" {
name = "bob"
policies = ["test"]
}
기본적으로 Vault는 identity 매칭 시 대소문자를 무시해 BOB과 bob을 같은 이름으로 취급하고, 두 번째 리소스를 중복으로 거부해요. 하지만 Vault 클러스터가 과거 문제로 두 리소스 이름을 모두 허용하는 모드로 실행 중이라면, 그 리소스가 별도 엔티티로 존재할 수 있어요.
Vault가 중복 제거 중 bob과 BOB을 중복으로 식별하면, identity 중 하나를 <name>-<uuid>로 이름 변경해요. 중복 제거 후 Terraform은 관련 리소스에 이전 이름을 다시 적용하려고 하지만, 기존 리소스가 이제 Vault 쪽의 대소문자 구분 없는 이름 제약을 위반하므로 인플레이스 업데이트가 실패해요.
예를 들어:
➜ tf_dupe_testing terraform apply
vault_identity_entity.bob: Refreshing state... [id=e8c5e633-fe37-5a49-4a29-32e2643d03bd]
vault_identity_entity.BOB: Refreshing state... [id=2577bc3f-67ab-dab7-93dc-e86f78194ff0]
Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# vault_identity_entity.bob will be updated in-place
~ resource "vault_identity_entity" "bob" {
+ external_policies = false
id = "e8c5e633-fe37-5a49-4a29-32e2643d03bd"
~ name = "bob-e8c5e633-fe37-5a49-4a29-32e2643d03bd" -> "bob"
# (3 unchanged attributes hidden)
}
...
vault_identity_entity.bob: Modifying... [id=e8c5e633-fe37-5a49-4a29-32e2643d03bd]
╷
│ Error: error updating IdentityEntity "e8c5e633-fe37-5a49-4a29-32e2643d03bd": Error making API request.
│
│ URL: PUT https://127.0.0.1:8200/v1/identity/entity/id/e8c5e633-fe37-5a49-4a29-32e2643d03bd
│ Code: 400. Errors:
│
│ * entity name is already in use
│
│ with vault_identity_entity.bob,
│ on main.tf line 17, in resource "vault_identity_entity" "bob":
│ 17: resource "vault_identity_entity" "bob" {
해결책(Solution)
이름이 변경된 엔티티와 그룹을 다루는 가장 쉬운 방법은 중복 제거를 강제하기 전에 Terraform 구성의 관련 리소스를 업데이트된 이름으로 수동 업데이트하는 거예요.
팁: 엔티티나 그룹을 이름으로 참조하는 다른 외부 시스템의 대상 이름을 식별하고 업데이트할 때도 같은 프로세스를 사용해요.
예를 들어 시스템 로그에 다음과 같은 줄이 있다면:
2025-01-28T13:15:13.641-0800 [WARN] identity: entity "bob" with namespace ID "admin" duplicates 1 others: id=8ad26e0c-8cf6-5b67-7c77-6571fa374881 force_deduplication="would not rename"
2025-01-28T13:15:13.641-0800 [WARN] identity: entity "BOB" with namespace ID "admin" duplicates 1 others: id=9fe86ea0-f80c-1199-5ad1-1d01ab70237f force_deduplication="would rename to BOB-9fe86ea0-f80c-1199-5ad1-1d01ab70237f"
Terraform 구성 파일에서 BOB과 관련된 어떤 리소스든 업데이트해요. 예를 들어:
terraform {
required_providers {
vault = {
source = "hashicorp/vault"
}
}
}
provider "vault" {}
resource "vault_identity_entity" "BOB-9fe86ea0-f80c-1199-5ad1-1d01ab70237f" {
name = "BOB-9fe86ea0-f80c-1199-5ad1-1d01ab70237f"
policies = ["TEST"]
}
resource "vault_identity_entity" "bob" {
name = "bob"
policies = ["test"]
}
더 알아보기 (Learn more)
- identity 중복 제거 개요와 단계별 절차를 살펴보세요.
- ACL 정책 템플릿에 대한 중복 제거 영향 해결 가이드를 확인해 보세요.
- Vault Terraform 공급자 문서를 확인해 보세요.