flaky-beach-82888
02/08/2022, 10:09 PMresource_config = cloudinit.Config("resource", base64_encode=False,
gzip=False,
parts=[cloudinit.GetConfigPartArgs(
content="baz",
content_type="text/cloud-config",
filename="cloudinit/test.yaml",
)])
node0 = hcloud.Server(
get_name('node'),
image=image,
location=location,
server_type=server_type,
ssh_keys=[default_ssh.id],
user_data=resource_config
)
cloudinit file - taken from cloudinit docu
#cloud-config
# run commands
# default: none
# runcmd contains a list of either lists or a string
# each item will be executed in order at rc.local like level with
# output to the console
# - runcmd only runs during the first boot
# - if the item is a list, the items will be properly executed as if
# passed to execve(3) (with the first arg as the command).
# - if the item is a string, it will be simply written to the file and
# will be interpreted by 'sh'
#
# Note, that the list has to be proper yaml, so you have to quote
# any characters yaml would eat (':' can be problematic)
runcmd:
- [ ls, -l, / ]
- [ sh, -xc, "echo $(date) ': hello world!'" ]
- [ sh, -c, echo "=========hello world'=========" ]
- ls -l /root
# Note: Don't write files to /tmp from cloud-init use /run/somedir instead.
# Early boot environments can race systemd-tmpfiles-clean LP: #1707222.
- mkdir /run/mydir
- [ wget, "<http://slashdot.org>", -O, /run/mydir/index.html ]
pulumi up runs through without errors, but cloud init is not applied. -> directory /run/mydir does not exists.
edit:
I use hetzner cloud, user_data should be supported according to pulumi doc.little-cartoon-10569
02/08/2022, 10:25 PMcontent
has to be the actual content. filename
is just a string that is put into the MIME part header.rendered
on the object returned from get_config, in order to get the rendered JSON object of the MIME parts.flaky-beach-82888
02/08/2022, 11:23 PM# read cloud-init config payload from file
with open(cloud_init_path) as f:
init_payload = f.read()
# create cloud-init config
foo = cloudinit.get_config(base64_encode=False,
gzip=False,
parts=[cloudinit.GetConfigPartArgs(
content=init_payload,
content_type="text/cloud-config",
filename="init.cfg",
)])
node0 = hcloud.Server(
get_name('node'),
image=image,
location=location,
server_type=server_type,
ssh_keys=[default_ssh.id],
user_data=foo.rendered # set cloudinit config
)