I'm using Pulumi.Command CopyToRemote to copy conf...
# general
f
I'm using Pulumi.Command CopyToRemote to copy configuration to EC2 instances. I've got a file I want to copy onto the EC2 instances whose contents is generated by my Pulumi script. It contains data that's derived from the Pulumi resources (essentially a map of various instances, hostnames and IPs.). At the moment there's no way to use an Output as the source for a StringAsset. Writing the file to disk is problematic because it doesn't exist at the planning stage, it will generated as part of the deployment/execute stage. Does anyone know of any workarounds?
e
You can't make the asset from an output you can make the whole asset in an output?
strdata : Output[string] strdata.apply(lambda d: StringAsset(d) Now you have an Output[StringAsset] But you should be able to pass that to the copy commands
f
I tried using apply
Copy code
command_remote.CopyToRemote(
                f'server-map-{fe_name}',
                connection=fe_conn,
                source=server_map.json.apply( lambda v: pulumi.StringAsset(v) ),
                remote_path="/usr/fl/etc/servers.conf",
                opts=pulumi.ResourceOptions(
                    parent=fe_server,
                    hooks=fe_hooks,
                    depends_on=[server_map],
                ),
            )
but I get the following error:
Copy code
error: command:remote:CopyToRemote resource 'server-map-fe-london-z0-0': property asset value {<nil>} has a problem: either asset or archive must be set
I can do this with an s3.BucketObject though
I've got a pulumi.dyanmic.DynamicResource which builds the JSON as an output:
Copy code
class ServerMapProvider(pulumi.dynamic.ResourceProvider):
    def _build_map(self, entries):
        server_map = {}
        for key, entry in entries.items():
            region = entry["region"]
            if region not in server_map:
                server_map[region] = []
            ipv6_addrs = entry.get("ipv6_addresses") or []
            server_map[region].append({
                "hostname": entry["hostname"],
                "instance_id": entry["instance_id"],
                "ipv4": entry["ipv4"] or "",
                "ipv6": ipv6_addrs[0] if ipv6_addrs else "",
            })
        return server_map

    def create(self, props):
        server_map = self._build_map(props["entries"])
        json_str = json.dumps(server_map, indent=2)
        return pulumi.dynamic.CreateResult(
            id_="server-map",
            outs={"json": json_str, "map": server_map},
        )

    def diff(self, _id, olds, news):
        changed = olds.get("entries") != news.get("entries")
        return pulumi.dynamic.DiffResult(changes=changed)

    def update(self, _id, olds, news):
        server_map = self._build_map(news["entries"])
        json_str = json.dumps(server_map, indent=2)
        return pulumi.dynamic.UpdateResult(
            outs={"json": json_str, "map": server_map},
        )

class ServerMap(pulumi.dynamic.Resource):
    json: pulumi.Output[str]
    map: pulumi.Output[dict]

    def __init__(self, name, entries, opts=None):
        super().__init__(
            ServerMapProvider(),
            name,
            {"entries": entries, "json": None, "map": None},
            opts,
        )