본문 바로가기

개발하자

terraformhcl 변수를 맵으로 생성합니다

반응형

terraformhcl 변수를 맵으로 생성합니다

저는 프로바이더를 이용한 테라폼 작업 공간 자동화 작업을 하고 있으며 아래의 데이터 구조를 이용하여 테라폼 HCL 변수를 맵으로 만들고 싶습니다.

workspaces = {
  "PROD" = {
    "custom_tags" = {
      "Application" = "demo"
      "EnvironmentType" = "prod"
      "NamePrefix" = "sof"
      "ProductType" = "terraform"
    }
    "env_variables" = {}
    "id" = "alfsdfksf"
    "name" = "PROD"
    "repo" = "github/something"
    "tf_variables" = {}
  }
  "UAT" = {
    "custom_tags" = {
      "Application" = "demo"
      "EnvironmentType" = "uat"
      "NamePrefix" = "sof"
      "ProductType" = "terraform"
    }
    "env_variables" = {}
    "id" = "ws-k7KWYfsdfsdf"
    "name" = "UAT"
    "repo" = "github/otherthing"
    "tf_variables" = {}
  }
}

여기 내 리소스 블록이 있습니다

resource "tfe_variable" "terraform_hcl_variables" {
  for_each     = { for w in local.workspaces : w.name => w }
  key          = "custom_tags"
  value        = each.value.custom_tags
  category     = "terraform"
  hcl          = true
  sensitive    = false
  workspace_id = tfe_workspace.main[each.key].id
}

그리고, 나는 이 오류를 받고 있다. 이 문제를 해결하기 위해 어떤 도움이라도 주시면 감사하겠습니다.

**each.value.custom_tags is object with 4 attributes
Inappropriate value for attribute "value": string required.**

예상 결과

custom_tags는 HCL 변수로 생성해야 합니다

custom_tags = 
{
   "Application" = "demo"
   "EnvironmentType" = "prod"
   "NamePrefix" = "sof"
   "ProductType" = "terraform"
}



슬프게도 당신은 이것을 할 수 없어요. 속성. 그러나 "4개의 속성을 가진 개체"를 할당하려고 합니다.

를 사용하여 를 문자열로 변환할 수 있지만, 이것은 아마도 당신이 원하는 것이 아닐 것이다.




사용해 보십시오:

workspace_id = tfe_workspace.main[each.key].workspace_id

반응형