https://pulumi.com logo
#python
Title
# python
a

ambitious-king-70853

02/21/2024, 7:33 PM
Hey all, I'm using the python Cloudflare provider to create a tunnel + tunnel route in CF, then I have a deployment yaml file push into my k8s cluster to link the route to my service. I need the tunnel ID for the yaml, I just do a replace string on a templated field. However, this isn't working as replace doesn't accept pulumi.Output type. I tried using tunnel.token.apply(..print(token)) but that also didn't work. My question is: in the same script / pulumi up command, is there a way to create a dynamic cloud resource (tunnel), get the tunnel token, and use that token in a python string replace for my deployment yaml?
r

red-match-15116

02/21/2024, 8:40 PM
Can you show us your code? Is the yaml also an output? You may need to use pulumi.all
a

ambitious-king-70853

02/22/2024, 3:50 PM
I'll check this out when I get back home in a few days @red-match-15116
Output.all(...) got past the initial issue, thanks! Next up, I'm trying to use my templated yaml in a ConfigGroup but it's just not having it:
TypeError: 'Output' object is not iterable, consider iterating the underlying value inside an 'apply'
Relevant Code:
Copy code
...
with open('manifest_yamls/cloudflared-deployment.yaml', 'r') as file:
    templated_yaml_content = file.read()

deploy_yaml = Output.all(namespace_ckc, tunnel.tunnel_token).apply(
    lambda outputs: replace_placeholders(
        templated_yaml_content,
        {
            "namespace": outputs[0],
            "tunnel_token": outputs[1],
        }
    )
)

deployment = ConfigGroup(
    "cloudflared-deployment",
    resource_prefix="cloudflared",
    yaml=deploy_yaml,
    opts=pulumi.ResourceOptions(
        provider=k8s_provider,
        depends_on=[namespace_obj_ckc]
    )
)
I've output "deploy_yaml" as a string into the console and I know that my values are being replaced, but I can't run pulumi up due to the type error.
I think I can leverage the "transformations" param here, so I'm going to work with that for a bit.
I ultimately ended up just breaking the yaml into pulumi objects so that I could just leverage the
Awaitable[str]
type and not worry about conversions / async. Thanks for the tip on
Output.all(...)