It is not secure and you should use something like vault but if you still want to migrate certificate file to data bag you can use the following:
- Replace new lines with /n
cat fullchain.pem | tr '\n' '#' | sed 's/#/\\n/g'
- Do the same thing for your key file
cat key.pem | tr '\n' '#' | sed 's/#/\\n/g'
- Copy the data to the data bag