Wrong field mapping in gitlab api response for data resource gitlab_cluster_agents (agent_id always 0)
Bug Report
gitlab_cluster_agents Data Source always returns 0 value for agent_id field.
Appropriate API call sent directly to gitlab endpoint returns correct values (here and below project_id = 12)
# curl -X GET --header "PRIVATE-TOKEN: glpat-<TOKEN>" https://<SELF_HOSTED_GITLAB>/api/v4/projects/12/cluster_agents | jq
[
{
"config_project": {
"created_at": "2022-05-03T15:56:26.034Z",
"description": "Main project",
"id": 12,
"name": "project",
"name_with_namespace": "group / project",
"path": "project",
"path_with_namespace": "group/project"
},
"created_at": "2022-11-22T16:24:29.998Z",
"created_by_user_id": 69,
"id": 67,
"name": "dev"
},
{
"config_project": {
"created_at": "2022-05-03T15:56:26.034Z",
"description": "Main project",
"id": 12,
"name": "project",
"name_with_namespace": "group / project",
"path": "project",
"path_with_namespace": "group/project"
},
"created_at": "2022-11-22T16:33:38.965Z",
"created_by_user_id": 69,
"id": 68,
"name": "int"
},
{
"config_project": {
"created_at": "2022-05-03T15:56:26.034Z",
"description": "Main project",
"id": 12,
"name": "project",
"name_with_namespace": "group / project",
"path": "project",
"path_with_namespace": "group/project"
},
"created_at": "2022-11-22T16:34:27.576Z",
"created_by_user_id": 69,
"id": 70,
"name": "prd"
},
{
"config_project": {
"created_at": "2022-05-03T15:56:26.034Z",
"description": "Main project",
"id": 12,
"name": "project",
"name_with_namespace": "group / project",
"path": "project",
"path_with_namespace": "group/project"
},
"created_at": "2022-11-22T16:33:58.081Z",
"created_by_user_id": 69,
"id": 69,
"name": "val"
},
]
As far as I can see in the code, you're trying to map agent_id field from the response. It doesn't exist, and since the value is int, 0 is returned as default value.
API docs say that it must be id, not agent_id.
Relevant Terraform Configuration
data "gitlab_cluster_agents" "this" {
project = "12"
}
output "gitlab_cluster_agents" {
value = data.gitlab_cluster_agents.this["the-dock"]
}
Relevant Terraform Command
terraform plan
Relevant Log Output
These are the debug logs of the `terraform` command output:
gitlab_cluster_agents = {
cluster_agents = [
{
agent_id = 0
created_at = "2022-11-22T16:24:29Z"
created_by_user_id = 69
name = "dev"
project = ""
},
{
agent_id = 0
created_at = "2022-11-22T16:33:38Z"
created_by_user_id = 69
name = "int"
project = ""
},
{
agent_id = 0
created_at = "2022-11-22T16:34:27Z"
created_by_user_id = 69
name = "prd"
project = ""
},
{
agent_id = 0
created_at = "2022-11-22T16:33:58Z"
created_by_user_id = 69
name = "val"
project = ""
},
]
id = "12"
project = "12"
}
Additional Details
- GitLab Terraform Provider Version: 1.5.6
- GitLab Version: 16.0.5
- Terraform Version: 16.3.0
Edited by Konstantin Dobroliubov