kind-afternoon-60990
03/25/2025, 10:17 AMmodern-zebra-45309
03/25/2025, 10:39 AMapply()
will always be another output. But you can use a pulumi.Output
as a pulumi.Input
, its value will become available while Pulumi deploys your infrastructure. (You can use apply()
to convert between different output types, though, e.g., converting an pulumi.Output[int]
to pulumi.Output[str]
)
If you post the code (snippet) that doesn't work, I'm sure we can figure out the problem.kind-afternoon-60990
03/25/2025, 10:49 AMkind-afternoon-60990
03/25/2025, 10:50 AMkind-afternoon-60990
03/25/2025, 10:53 AMget_firewall_policy_rule_collection_group
sadly I couldn't update the rcg directly with my firewall rules so I decided to import the rcg if needed and do the update on "existing+rcg" later on. (will rename to imported_rcg)kind-afternoon-60990
03/25/2025, 10:53 AMdef get_or_import_existing_rule_collection_group(
selected_rcg: network.FirewallPolicyRuleCollectionGroup,
firewall_policy: network.FirewallPolicy,
resource_group_name: str,
subscription_id: Input[str],
virtual_wan_provider: pulumi.ProviderResource
) -> network.FirewallPolicyRuleCollectionGroup:
"""
Imports an existing FirewallPolicyRuleCollectionGroup if it exists, otherwise returns it
from the Pulumi state.
"""
# Construct the resource ID
resource_id = pulumi.Output.all(resource_group_name, firewall_policy.name, selected_rcg.name).apply(
lambda args: f"/subscriptions/{subscription_id}/resourceGroups/{args[0]}/providers/Microsoft.Network/firewallPolicies/{args[1]}/ruleCollectionGroups/{args[2]}"
)
# Attempt to import the resource. It will create the resource if the import doesn't exist.
imported_rcg = network.FirewallPolicyRuleCollectionGroup(
selected_rcg.name.apply(lambda name: '' + str(name)),
resource_group_name=resource_group_name,
firewall_policy_name=firewall_policy.name,
opts=ResourceOptions(
provider=virtual_wan_provider,
import_=resource_id,
)
)
return imported_rcg
modern-zebra-45309
03/25/2025, 11:02 AMOutput
, it has to be available at the point in time the Python code is executed.
You can do something like this:
groups: list[str] = ["group-a", "group-b"]
for group in groups:
the_group = MemberResource(f"member-of-{group}", ...)
Here, the value of the resource name is known when the program runs. But an `Output`'s value only becomes known later.kind-afternoon-60990
03/25/2025, 11:03 AMmodern-zebra-45309
03/25/2025, 11:05 AMkind-afternoon-60990
03/25/2025, 11:05 AMkind-afternoon-60990
03/25/2025, 11:06 AMkind-afternoon-60990
03/25/2025, 11:07 AMmodern-zebra-45309
03/25/2025, 11:07 AMmodern-zebra-45309
03/25/2025, 11:08 AMkind-afternoon-60990
03/25/2025, 11:08 AMkind-afternoon-60990
03/25/2025, 11:09 AMkind-afternoon-60990
03/25/2025, 11:10 AMmodern-zebra-45309
03/25/2025, 11:10 AMkind-afternoon-60990
03/25/2025, 11:11 AMmodern-zebra-45309
03/25/2025, 11:11 AMkind-afternoon-60990
03/25/2025, 11:12 AMmodern-zebra-45309
03/25/2025, 11:12 AMmodern-zebra-45309
03/25/2025, 11:13 AMkind-afternoon-60990
03/25/2025, 11:13 AMmodern-zebra-45309
03/25/2025, 11:16 AMkind-afternoon-60990
03/25/2025, 11:17 AMmodern-zebra-45309
03/25/2025, 11:20 AMkind-afternoon-60990
03/25/2025, 11:20 AMmodern-zebra-45309
03/25/2025, 11:21 AMkind-afternoon-60990
03/25/2025, 11:22 AMmodern-zebra-45309
03/25/2025, 11:22 AMkind-afternoon-60990
03/25/2025, 11:22 AMkind-afternoon-60990
03/25/2025, 11:35 AMhigh-painter-73966
03/25/2025, 4:38 PMx = aws.s3.bucket("backup", bucket=primary_bucket.name.apply(lambda primary_bucket: f"{primary_bucket}-backup"))
This won't work:
bucket_name = primary_bucket.name.apply(lambda primary_bucket: f"{primary_bucket}-backup")
x = aws.s3.bucket("backup", bucket=bucket_name)
Another tricky bit is about Output.json_dump
which is that f-strings are evaluated before the function is, so you can't use it if you will be using an f-string in the JSON, which is really common when you need an ARN that ends in /*
.modern-zebra-45309
03/25/2025, 4:46 PMprimary_bucket.bucket.apply(lambda primary_bucket: f"{primary_bucket]-backup")
to get the bucket's name, though.)high-painter-73966
03/25/2025, 4:49 PMprimary_bucket
. Overall, I've just tried to avoid evaluating any Outputs anywhere except within properties of resources and that seems to have helped me avoid chasing my tail over it.modern-zebra-45309
03/25/2025, 4:49 PMhigh-painter-73966
03/25/2025, 4:50 PMpolicy = pulumi.Output.json_dumps({Resources:[my_s3_bucket.arn, f"{my_s3_bucket.arn}/*"]})
modern-zebra-45309
03/25/2025, 4:51 PMI was thinking after I wrote this that actually that second one may work, but, there is something here that doesn't work.I'm very certain that this works, I use similar patterns a lot to keep resource definitions legible.
You definitely can't print the value ofYes, but that's unrelated to whether you assign the.primary_bucket
Output
to an intermediate variable or not.modern-zebra-45309
03/25/2025, 4:51 PMThis doesn't work:Yes, this needs an additional "apply" for the second entry.
high-painter-73966
03/25/2025, 4:52 PMmodern-zebra-45309
03/25/2025, 4:52 PMhigh-painter-73966
03/25/2025, 4:52 PMmodern-zebra-45309
03/25/2025, 4:53 PMmodern-zebra-45309
03/25/2025, 4:54 PMkind-afternoon-60990
03/26/2025, 3:33 AMkind-afternoon-60990
03/26/2025, 3:33 AMkind-afternoon-60990
04/04/2025, 1:46 PMkind-afternoon-60990
04/04/2025, 4:04 PM