Skip to content

gitlab: nested maps in cache, service and default are written as blocks the parser rejects #23

Description

@jccguimaraes

Unparse turns any nested map into an HCL block, but the schema in provider/gitlab/config.go declares several of those keys as attributes. The HCL that comes out does not parse.

writeGenericMap (provider/gitlab/unparse_pipeline.go) does this for every nested map it meets:

if nested, ok := toStringAnyMap(value); ok {
    b := body.AppendNewBlock(key, nil)
    ...
}

Three cases from the GitLab schema, each one a full unparse-then-parse:

cache.key as a map (the documented key: files: form):

build:
  script: [make]
  cache:
    key:
      files: [go.sum]
    paths: [.cache]
cache {
  key {
    files = ["go.sum"]
  }
  paths = [".cache"]
}

Blocks of type "key" are not expected here.hclCacheBlock.Key is hcl.Expression.

services[].variables:

build:
  script: [make]
  services:
    - name: postgres:16
      variables:
        POSTGRES_DB: test

Blocks of type "variables" are not expected here.hclServiceBlock.Variables is hcl.Expression.

default.retry as a map:

default:
  retry:
    max: 2
    when: runner_system_failure
build:
  script: [make]

Blocks of type "retry" are not expected here.hclDefaultBlock.Retry is hcl.Expression.

The job body path does not have this problem: writeJobBlock writes environment, parallel and variables as object attributes, and those roundtrip. Only the generic path inside cache, artifacts, service and default bodies is affected.

artifacts.reports is the one nested map that should stay a block, since hclArtifactsBlock.Reports is declared hcl:"reports,block".

So the writer needs to know which keys the schema declares as blocks rather than guessing from the value shape.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions