-
-
Save olafurnielsen/60ca122ab197060d5121fd32572c2814 to your computer and use it in GitHub Desktop.
Writing Pulumi Outputs to files in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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