Skip to content

Instantly share code, notes, and snippets.

@olafurnielsen
Created March 12, 2024 17:08
Show Gist options
  • Save olafurnielsen/60ca122ab197060d5121fd32572c2814 to your computer and use it in GitHub Desktop.
Save olafurnielsen/60ca122ab197060d5121fd32572c2814 to your computer and use it in GitHub Desktop.
Writing Pulumi Outputs to files in Python
import pulumi
import yaml
config = pulumi.Config()
password: pulumi.Output[str] = config.require_secret("password")
other_value: str | None = config.get("other_value")
# Writing inside the apply lambda function
pulumi.Output.all(password=password, other_value=other_value).apply(
func=lambda args: yaml.dump(
data={
"password": args["password"],
"other_value": args["other_value"],
},
stream=open("bar.yaml", mode="w"),
)
)
## Using a "callback" function
def write_template(tpl: dict) -> None:
yaml.dump(data=tpl, stream=open("foo.yaml", mode="w"))
pulumi.Output.all(password=password, other_value=other_value).apply(
func=lambda args: write_template(
tpl={
"password": args["password"],
"other_value": args["other_value"],
}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment