Merging multiple user-data

Bug #1990169 reported by blt
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Undecided
Unassigned

Bug Description

Provider : Terraform / LXD

ci-user-global.tf
locals {
  cloud-init-user-data-global = <<EOF
#cloud-config
packages:
  - nginx
write_files:
- encoding: b64
  content: |
    ${filebase64("conf/fichierdeconf")}
  path: /etc/fichierdeconf
  owner: root:root
  permissions: '755'
merge_how:
 - name: list
   settings: [append, recurse_list]
 - name: dict
   settings: [no_replace, recurse_dict]
 - name: str
   settings: [append, recurse_str]
EOF
}

ci-user-specific.tf
locals {
  cloud-init-user-data-specific = <<EOF
#cloud-config
write_files:
- encoding: b64
  content: |
    ${filebase64("conf/fichierdeconf2")}
  path: /etc/fichierdeconf2
  owner: root:root
  permissions: '755'
merge_how:
 - name: list
   settings: [append, recurse_list]
 - name: dict
   settings: [no_replace, recurse_dict]
 - name: str
   settings: [append, recurse_str]
EOF
}

The first is specified on profile file, the last is specified on container file.
Only the last is applied even if merge_how is used.

Already seen a couple of similar issues and documentation but never saw how to fix, apply it correctly for cloud-init to merge theses two user-data files ?

information type: Public → Public Security
information type: Public Security → Public
Revision history for this message
James Falcon (falcojr) wrote :

Cloud-init has no knowledge of terraform; rather terraform incorporates cloud-init. In that sense, it doesn't make sense to expect cloud-init understand the abstractions you're using within terraform.

You mentioned a profile and a container specification. Does the profile file specify how to setup the instance, whereas the container file sets up the container? If so, then the profile config is being passed to the cloud-init running on the instance, and the container config will be passed to cloud-init on the container. If that's not how things are setup, can you help me understand what exactly these two configs are being applied to? Where is the first being defined such that parts need to be overridden by the second?

The sort of merging you're asking about is really only applicable in cases where you're sending userdata as a list of include files or as a multipart MIME file.
https://cloudinit.readthedocs.io/en/latest/topics/format.html#include-file
and
https://cloudinit.readthedocs.io/en/latest/topics/format.html#helper-subcommand-to-generate-mime-messages

E.g., you can have userdata that pulls in multiple cloud-configs and merges them accordingly:
"""
#include
https://raw.githubusercontent.com/canonical/cloud-init/403f70b930e3ce0f05b9b6f0e1a38d383d058b53/doc/examples/cloud-config-run-cmds.txt
https://raw.githubusercontent.com/canonical/cloud-init/403f70b930e3ce0f05b9b6f0e1a38d383d058b53/doc/examples/cloud-config-boot-cmds.txt
"""

Changed in cloud-init:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for cloud-init because there has been no activity for 60 days.]

Changed in cloud-init:
status: Incomplete → Expired
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.