1. Packages
  2. Local Provider
  3. API Docs
  4. getFile
local 2.5.2 published on Thursday, Feb 6, 2025 by hashicorp

local.getFile

Explore with Pulumi AI

local 2.5.2 published on Thursday, Feb 6, 2025 by hashicorp

Reads a file from the local filesystem.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as local from "@pulumi/local";

const foo = local.getFile({
    filename: `${path.module}/foo.bar`,
});
const sharedZip = new aws.index.Aws_s3_object("sharedZip", {
    bucket: "my-bucket",
    key: "my-key",
    content: foo.content,
});
Copy
import pulumi
import pulumi_aws as aws
import pulumi_local as local

foo = local.get_file(filename=f"{path['module']}/foo.bar")
shared_zip = aws.index.Aws_s3_object("sharedZip",
    bucket=my-bucket,
    key=my-key,
    content=foo.content)
Copy
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/go/aws"
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/local/v2/local"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		foo, err := local.LookupFile(ctx, &local.LookupFileArgs{
			Filename: fmt.Sprintf("%v/foo.bar", path.Module),
		}, nil)
		if err != nil {
			return err
		}
		_, err = aws.NewAws_s3_object(ctx, "sharedZip", &aws.Aws_s3_objectArgs{
			Bucket:  "my-bucket",
			Key:     "my-key",
			Content: foo.Content,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
using Local = Pulumi.Local;

return await Deployment.RunAsync(() => 
{
    var foo = Local.GetFile.Invoke(new()
    {
        Filename = $"{path.Module}/foo.bar",
    });

    var sharedZip = new Aws.Index.Aws_s3_object("sharedZip", new()
    {
        Bucket = "my-bucket",
        Key = "my-key",
        Content = foo.Apply(getFileResult => getFileResult.Content),
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.local.LocalFunctions;
import com.pulumi.local.inputs.GetFileArgs;
import com.pulumi.aws.aws_s3_object;
import com.pulumi.aws.Aws_s3_objectArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var foo = LocalFunctions.getFile(GetFileArgs.builder()
            .filename(String.format("%s/foo.bar", path.module()))
            .build());

        var sharedZip = new Aws_s3_object("sharedZip", Aws_s3_objectArgs.builder()
            .bucket("my-bucket")
            .key("my-key")
            .content(foo.applyValue(getFileResult -> getFileResult.content()))
            .build());

    }
}
Copy
resources:
  sharedZip:
    type: aws:aws_s3_object
    properties:
      bucket: my-bucket
      key: my-key
      content: ${foo.content}
variables:
  foo:
    fn::invoke:
      function: local:getFile
      arguments:
        filename: ${path.module}/foo.bar
Copy

Using getFile

Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

function getFile(args: GetFileArgs, opts?: InvokeOptions): Promise<GetFileResult>
function getFileOutput(args: GetFileOutputArgs, opts?: InvokeOptions): Output<GetFileResult>
Copy
def get_file(filename: Optional[str] = None,
             opts: Optional[InvokeOptions] = None) -> GetFileResult
def get_file_output(filename: Optional[pulumi.Input[str]] = None,
             opts: Optional[InvokeOptions] = None) -> Output[GetFileResult]
Copy
func LookupFile(ctx *Context, args *LookupFileArgs, opts ...InvokeOption) (*LookupFileResult, error)
func LookupFileOutput(ctx *Context, args *LookupFileOutputArgs, opts ...InvokeOption) LookupFileResultOutput
Copy

> Note: This function is named LookupFile in the Go SDK.

public static class GetFile 
{
    public static Task<GetFileResult> InvokeAsync(GetFileArgs args, InvokeOptions? opts = null)
    public static Output<GetFileResult> Invoke(GetFileInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetFileResult> getFile(GetFileArgs args, InvokeOptions options)
public static Output<GetFileResult> getFile(GetFileArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: local:index/getFile:getFile
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

Filename This property is required. string
Path to the file that will be read. The data source will return an error if the file does not exist.
Filename This property is required. string
Path to the file that will be read. The data source will return an error if the file does not exist.
filename This property is required. String
Path to the file that will be read. The data source will return an error if the file does not exist.
filename This property is required. string
Path to the file that will be read. The data source will return an error if the file does not exist.
filename This property is required. str
Path to the file that will be read. The data source will return an error if the file does not exist.
filename This property is required. String
Path to the file that will be read. The data source will return an error if the file does not exist.

getFile Result

The following output properties are available:

Content string
Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in content replaced with the Unicode replacement character.
ContentBase64 string
Base64 encoded version of the file content (use this when dealing with binary data).
ContentBase64sha256 string
Base64 encoded SHA256 checksum of file content.
ContentBase64sha512 string
Base64 encoded SHA512 checksum of file content.
ContentMd5 string
MD5 checksum of file content.
ContentSha1 string
SHA1 checksum of file content.
ContentSha256 string
SHA256 checksum of file content.
ContentSha512 string
SHA512 checksum of file content.
Filename string
Path to the file that will be read. The data source will return an error if the file does not exist.
Id string
The hexadecimal encoding of the SHA1 checksum of the file content.
Content string
Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in content replaced with the Unicode replacement character.
ContentBase64 string
Base64 encoded version of the file content (use this when dealing with binary data).
ContentBase64sha256 string
Base64 encoded SHA256 checksum of file content.
ContentBase64sha512 string
Base64 encoded SHA512 checksum of file content.
ContentMd5 string
MD5 checksum of file content.
ContentSha1 string
SHA1 checksum of file content.
ContentSha256 string
SHA256 checksum of file content.
ContentSha512 string
SHA512 checksum of file content.
Filename string
Path to the file that will be read. The data source will return an error if the file does not exist.
Id string
The hexadecimal encoding of the SHA1 checksum of the file content.
content String
Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in content replaced with the Unicode replacement character.
contentBase64 String
Base64 encoded version of the file content (use this when dealing with binary data).
contentBase64sha256 String
Base64 encoded SHA256 checksum of file content.
contentBase64sha512 String
Base64 encoded SHA512 checksum of file content.
contentMd5 String
MD5 checksum of file content.
contentSha1 String
SHA1 checksum of file content.
contentSha256 String
SHA256 checksum of file content.
contentSha512 String
SHA512 checksum of file content.
filename String
Path to the file that will be read. The data source will return an error if the file does not exist.
id String
The hexadecimal encoding of the SHA1 checksum of the file content.
content string
Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in content replaced with the Unicode replacement character.
contentBase64 string
Base64 encoded version of the file content (use this when dealing with binary data).
contentBase64sha256 string
Base64 encoded SHA256 checksum of file content.
contentBase64sha512 string
Base64 encoded SHA512 checksum of file content.
contentMd5 string
MD5 checksum of file content.
contentSha1 string
SHA1 checksum of file content.
contentSha256 string
SHA256 checksum of file content.
contentSha512 string
SHA512 checksum of file content.
filename string
Path to the file that will be read. The data source will return an error if the file does not exist.
id string
The hexadecimal encoding of the SHA1 checksum of the file content.
content str
Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in content replaced with the Unicode replacement character.
content_base64 str
Base64 encoded version of the file content (use this when dealing with binary data).
content_base64sha256 str
Base64 encoded SHA256 checksum of file content.
content_base64sha512 str
Base64 encoded SHA512 checksum of file content.
content_md5 str
MD5 checksum of file content.
content_sha1 str
SHA1 checksum of file content.
content_sha256 str
SHA256 checksum of file content.
content_sha512 str
SHA512 checksum of file content.
filename str
Path to the file that will be read. The data source will return an error if the file does not exist.
id str
The hexadecimal encoding of the SHA1 checksum of the file content.
content String
Raw content of the file that was read, as UTF-8 encoded string. Files that do not contain UTF-8 text will have invalid UTF-8 sequences in content replaced with the Unicode replacement character.
contentBase64 String
Base64 encoded version of the file content (use this when dealing with binary data).
contentBase64sha256 String
Base64 encoded SHA256 checksum of file content.
contentBase64sha512 String
Base64 encoded SHA512 checksum of file content.
contentMd5 String
MD5 checksum of file content.
contentSha1 String
SHA1 checksum of file content.
contentSha256 String
SHA256 checksum of file content.
contentSha512 String
SHA512 checksum of file content.
filename String
Path to the file that will be read. The data source will return an error if the file does not exist.
id String
The hexadecimal encoding of the SHA1 checksum of the file content.

Package Details

Repository
local hashicorp/terraform-provider-local
License
Notes
This Pulumi package is based on the local Terraform Provider.
local 2.5.2 published on Thursday, Feb 6, 2025 by hashicorp