#cloud-config
merge_how: dict(recurse_array)+list(append)
write_files:
  - path: /etc/systemd/system/add-ext-ca-certs.service
    owner: "root:root"
    permissions: "0644"
    content: |
      [Unit]
      Description=Install custom CA certificates

      [Service]
      Type=oneshot
      ExecStart=/etc/sysconfig/add-ext-ca-certs.sh

      [Install]
      WantedBy=multi-user.target

  - path: /etc/sysconfig/add-ext-ca-certs.sh
    owner: "root:root"
    permissions: "0755"
    content: |
      #!/bin/sh

      CERT_FILE=/etc/ssl/certs/openstack-ca.pem
      if [ -n "$OPENSTACK_CA" ]
      then
          echo -ne "$OPENSTACK_CA" | tee -a ${CERT_FILE}

          chmod 0644 ${CERT_FILE}
          chown root:root ${CERT_FILE}
          update-ca-certificates
      fi
