Hello. I'm trying to use cloud-init templating wit...
# general
s
Hello. I'm trying to use cloud-init templating with pulumi (for proxmox) and I've come across this: https://www.pulumi.com/registry/packages/cloudinit/api-docs/config/ But it says it's deprecated:
This resource is deprecated Please use the cloudinit.Config data source instead.
I've no idea what is meant by 'data source' here. Maybe someone can point me to the right resource. It would be great if the documentation contained an actual reference/link to it.
My guess is that I have to use something to the effect of:
Copy code
import pulumi_cloudinit as cloudinit

# Generate a cloud-init config
config = cloudinit.Config("example",
    gzip=False,
    base64_encode=False,
    parts=[cloudinit.ConfigPartArgs(
        content_type="text/x-shellscript",
        content="""
#cloud-config
users:
  - name: pulumi
    ssh_authorized_keys:
      - your_public_ssh_key_here
""",
    )])
But this is just something I've found on the internet, it's not something I've inferred in anyway. Eh...
q
looks like the pulumi package for cloud-init just tracks the terraform provider. the same deprecation message is here on the config resource page in the provider docs https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs/resources/config
definitely confusing without adding context on the pulumi docs
i think you'd want to use the getConfig function in the pulumi package, it seems to match up to the terraform data source. this github issue comment has some example code that might be useful https://github.com/pulumi/pulumi-cloudinit/issues/33#issuecomment-1039064729
s
for me
getConfig
is just misleading or I don't understand it. It leads me to believe that there's an existing config that I'm retrieving somehow and I'm not creating it there.
But from the link you're offering, yeah, that's not the case. It works more or less like with terraform, where you define it in parts.
I'm slowing trying to understand how I can go from terraform (which is exceedingly and frustratingly limiting) to pulumi, which is much more powerful, but it also means taking more responsibility, as it were, and being more creative/capable.
Anyway, there's also https://www.pulumi.com/registry/packages/cloudinit/ (which is consistent to my solution, as far as I understand). I don't understand the difference.
q
its frustrating that the example is using the deprecated resource. functionally, there doesn't appear to be any difference between the deprecated resource and the data source apart from how they would both be maintained in state by the provider. they both return a config object rendered from the config parts you provide
s
I've just realised that this is part of the same package, all that. So there's the overview (the link above), there's
Config
(deprecated) and there
getConfig
, what you've suggested. So the overview uses
config
, which is deprecated then, as you've mentioned, they just haven't updated the documentation, right? I'm mislead by that because in the overview
Config
is used differently than in the "Config" section. So
getConfig
is the only non-deprecated version, if I understand correctly.
q
yep, thats my understanding as well. they just need to update example wherever its being generated from
s
Do you happen to know how I could generate an actual cloud-init file from this? I need this as a proxmox snippet and there's no other way than having the file as such. You can't do it through the Proxmox API.
q
sorry, i haven't used proxmox before and i don't have a definite answer for you. but, can you talk a little more about your use-case? You could create a file and write the rendered config output from getConfig to it. though that might be too oversimplified depending on where you're running pulumi and where you need the file to go
s
Thanks, I have it, it took a while to understand how I could test it as such. I tried testing it python cli, but it doesn't work that way (because of async, await, future and all sorts of stuff 😄 ). Testing it with
pulumi up
did work, and yes,
.rendered
seems to be outputting what I want. I just need to create a file out of that.
q
awesome! glad to hear you got it working 🙌