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.
Unparse turns any nested map into an HCL block, but the schema in
provider/gitlab/config.godeclares 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:Three cases from the GitLab schema, each one a full unparse-then-parse:
cache.keyas a map (the documentedkey: files:form):Blocks of type "key" are not expected here.—hclCacheBlock.Keyishcl.Expression.services[].variables:Blocks of type "variables" are not expected here.—hclServiceBlock.Variablesishcl.Expression.default.retryas a map:Blocks of type "retry" are not expected here.—hclDefaultBlock.Retryishcl.Expression.The job body path does not have this problem:
writeJobBlockwritesenvironment,parallelandvariablesas object attributes, and those roundtrip. Only the generic path insidecache,artifacts,serviceanddefaultbodies is affected.artifacts.reportsis the one nested map that should stay a block, sincehclArtifactsBlock.Reportsis declaredhcl:"reports,block".So the writer needs to know which keys the schema declares as blocks rather than guessing from the value shape.