Skip to content

Commit fdefcf1

Browse files
committed
fix error when writing file with empty content
Previously, attempting to write a local file with content of "" would set the resource Id to "", since the Id is based on a SHA1 of the content. This caused the file to be deleted during the apply step. The resource Id of an empty file is now the SHA1 of the filename concatenated with the SHA1 of the content, so it will never be "".
1 parent fc6bace commit fdefcf1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

local/resource_local_file.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ func resourceLocalFileCreate(d *schema.ResourceData, _ interface{}) error {
9191
return err
9292
}
9393

94-
checksum := sha1.Sum([]byte(content))
95-
d.SetId(hex.EncodeToString(checksum[:]))
94+
filenameChecksum := sha1.Sum([]byte(destination))
95+
contentChecksum := sha1.Sum([]byte(content))
96+
d.SetId(hex.EncodeToString(append(filenameChecksum[:], contentChecksum[:]...)))
9697

9798
return nil
9899
}

0 commit comments

Comments
 (0)