Update filesha1.mdx

pull/35599/head
CJ 2 years ago committed by GitHub
parent 7a7e369e71
commit cdb6bd8c9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,19 +1,46 @@
---
page_title: filesha1 - Functions - Configuration Language
description: |-
The filesha1 function computes the SHA1 hash of the contents of
a given file and encodes it as hex.
description: he filesha1 function computes the SHA1 hash of the contents of a given file and encodes it as hex.
---
# `filesha1` Function
# filesha1 function reference
This topic provides reference information about the `filesha1` function, which calculates the SHA-1 hash of a file's contents.
`filesha1` is a variant of [`sha1`](/terraform/language/functions/sha1)
that hashes the contents of a given file rather than a literal string.
## Introduction
This is similar to `sha1(file(filename))`, but
The `filesha1` is a variant of [`sha1`](/terraform/language/functions/sha1) that hashes the contents of a given file rather than a literal string. This is similar to `sha1(file(filename))`, but
because [`file`](/terraform/language/functions/file) accepts only UTF-8 text it cannot be used to
create hashes for binary files.
Collision attacks have been successfully performed against this hashing
function. Before using this function for anything security-sensitive, review
relevant literature to understand the security implications.
! >**Security warning**: Collision attacks have been successfully performed against this hashing function. Before using this function for anything security-sensitive, review relevant literature to understand the security implications.
## Syntax
Use the filesha1 function with the following syntax:
```hcl
filesha1(path)
```
The `path` is the file path (relative or absolute) to the file whose SHA-1 hash you want to compute.
In the following example, the function returns the SHA-1 value.
```hcl
> filesha1("example.txt")
d3486ae9136e7856bc42212385ea797094475802
```
## Example use case
In the following example the `filesha1` function computes the SHA-1 hash of the file example.txt located in the current module's directory. The result will be a 40-character hexadecimal string representing the SHA-1 hash.
```hcl
output "file_hash" { value = filesha1("${path.module}/example.txt") }
```
## Related Functions
[`sha1`](/terraform/language/functions/sha1) computes the SHA1 hash of a given string and encodes it with hexadecimal digits.
[`sha256`](/terraform/language/functions/sha256) computes the SHA256 hash of a given string and encodes it with hexadecimal digits.
[`sha512`](/terraform/language/functions/sha512) computes the SHA512 hash of a given string and encodes it with hexadecimal digits.

Loading…
Cancel
Save