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

adventurous-butcher-54166

02/29/2024, 12:51 PM
The documentation on
pulumi.FileAsset
states
FileAsset: The contents of the asset are read from a file on disk.
However I only get an object with a path to the file and not its contents. Am I doing something wrong or does it only return the path? https://www.pulumi.com/docs/concepts/assets-archives/
w

witty-battery-28013

02/29/2024, 3:08 PM
I am just learning pulumi myself, so take with a grain of salt, but I believe this is the intended behavior. The wording is a bit confusing but I think the FileAsset will give you just a reference to a local file that will be read from when you pass the reference to a function (like the example here https://www.pulumi.com/ai/answers/e3XToQpQVgkoCnMjfS9oK8/file-upload-to-amazon-s3-bucket )
.. thus adding this file reference to the state i suppose
a

adventurous-butcher-54166

02/29/2024, 3:10 PM
Yep, seems like some resource providers accept FileAsset inputs and will take care of reading the contents. Looked at the definition which only returns path so there's no reading of contents going on.
Copy code
class FileAsset(Asset):
    """
    A FileAsset is a kind of asset produced from a given path to a file on
    the local filesystem.
    """

    path: str

    def __init__(self, path: Union[str, PathLike]) -> None:
        if not isinstance(path, (str, PathLike)):
            raise TypeError("FileAsset path must be a string or os.PathLike")
        self.path = fspath(path)