현재 config.yml에 하드코딩된 설정을 사용하고 있는 Terraform 기반의 Fabric 배포 프로세스를 개선하고 있습니다.
아래의 설정 파일을 설명드리면, variable.tf에서 정의된 변수를 활용하지 않고, variable.tf에는 ADO 파이프라인에서 전달되는 dev, prod 등의 환경 정보(var.env)만 정의되어 있습니다. 그리고 현재 구성은 config.yml을 yamldecode()를 통해 locals 블록(config.tf)에서 파싱하는 방식입니다.
workspace_role_assignment = yamldecode(file("${path.root}/config/workspace_role_assignment.yml"))
환경별로 다른 설정 파일을 적용하기 위해 var.env 값을 해당 경로에 동적으로 넣으려고, 예를 들어 아래와 같이 시도했는데, 실행 중 에러가 발생합니다:
workspace_role_assignment = yamldecode(file("${path.root}/config/${var.env}/workspace_role_assignment.yml"))
추가적으로 아래와 같이 시도도 해봤습니다.
workspace_role_assignment = yamldecode(file("${path.root}/config/var.env/workspace_role_assignment.yml"))
하지만 런타임에서 다음과 같은 오류가 발생했습니다:
Invalid value for path parameter: no file exists at "./config/var.env/workspace_role_assignment.yml"; this function works only with files that are distributed as part of configuration source code, so if this file will be created by a resource in this configuration you must obtain the result from an attribute of that resource.
즉, yamldecode()는 런타임에 동적으로 생성되거나 위치가 불확실한 파일을 사용할 수 없다는데 의견 부탁드려요.