Repeated "Duplicate oci_credentials block" logs when using the image in a CI user script

Summary

Parasite Error: Duplicate oci_credentials block for logs when using the gitlab-tofu command in a user script.

This is does not cause any wreck because I'm either not using the gitlab terraform registry or I'm already using the job token to log in, but the script forcing the credentials repeatedly would be an issue if I had to use a different user for any reason

I think this started to appear after b40c7aef was made available in the latest image, and had me wondering if something was about to break

Steps to reproduce

  1. Create a CI job using the image registry.gitlab.com/components/opentofu/gitlab-opentofu:latest-alpine
  2. In the script section, invoke gitlab-tofu several times in the same context

Example Project

What is the current bug behavior?

TF_CLI_CONFIG_FILE gets appended again and again with oci_credentials nodes

What is the expected correct behavior?

Only append credentials for an OCI registry if there are no defined credentials for this registry (there are many possible sources), or default to not having the login behaviour by default in the image + enable it in the CI component

Relevant logs and/or screenshots

$ gitlab-tofu workspace show
There are some problems with the CLI configuration:

│ Error: Duplicate oci_credentials block for "gitlab.example:4567"



│ Error: Duplicate oci_credentials block for "gitlab.example:4567"


As a result of the above problems, OpenTofu may not behave as intended.
toto
$ gitlab-tofu -- fmt -diff -recursive
There are some problems with the CLI configuration:

│ Error: Duplicate oci_credentials block for "gitlab.example:4567"



│ Error: Duplicate oci_credentials block for "gitlab.example:4567"



│ Error: Duplicate oci_credentials block for "gitlab.example:4567"


As a result of the above problems, OpenTofu may not behave as intended.
$ gitlab-tofu validate
There are some problems with the CLI configuration:

│ Error: Duplicate oci_credentials block for "gitlab.example:4567"



│ Error: Duplicate oci_credentials block for "gitlab.example:4567"



│ Error: Duplicate oci_credentials block for "gitlab.example:4567"



│ Error: Duplicate oci_credentials block for "gitlab.example:4567"


As a result of the above problems, OpenTofu may not behave as intended.

Possible fixes

append heredoc in gitlab-tofu.sh