# README
go-slug
Package go-slug
offers functions for packing and unpacking Terraform Enterprise
compatible slugs. Slugs are gzip compressed tar files containing Terraform configuration files.
Installation
Installation can be done with a normal go get
:
go get -u github.com/hashicorp/go-slug
Documentation
For the complete usage of go-slug
, see the full package docs.
Example
Packing or unpacking a slug is pretty straight forward as shown in the following example:
package main
import (
"bytes"
"io/ioutil"
"log"
"os"
slug "github.com/hashicorp/go-slug"
)
func main() {
// First create a buffer for storing the slug.
buf := bytes.NewBuffer(nil)
// Then call the Pack function with a directory path containing the
// configuration files and an io.Writer to write the slug to.
if _, err := slug.Pack("testdata/archive-dir", buf, false); err != nil {
log.Fatal(err)
}
// Create a directory to unpack the slug contents into.
dst, err := ioutil.TempDir("", "slug")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(dst)
// Unpacking a slug is done by calling the Unpack function with an
// io.Reader to read the slug from and a directory path of an existing
// directory to store the unpacked configuration files.
if err := slug.Unpack(buf, dst); err != nil {
log.Fatal(err)
}
}
Issues and Contributing
If you find an issue with this package, please report an issue. If you'd like, we welcome any contributions. Fork this repository and submit a pull request.
# Packages
Package sourceaddrs deals with the various types of source code address that Terraform can gather into a source bundle via the sibling package "sourcebundle".
Package sourcebundle deals with the construction of and later consumption of "source bundles", which are in some sense "meta-slugs" that capture a variety of different source packages together into a single working directory, which can optionally be bundled up into an archive for insertion into a blob storage system.
# Functions
AllowSymlinkTarget relaxes safety checks on symlinks with targets matching path.
ApplyTerraformIgnore is a PackerOption that will apply the .terraformignore rules and skip packing files it specifies.
DereferenceSymlinks is a PackerOption that will allow symlinks that reference a target outside of the source directory by copying the link target, turning it into a normal file within the archive.
NewPacker is a constructor for Packer.
Pack at the package level is used to maintain compatibility with existing code that relies on this function signature.
Unpack is used to read and extract the contents of a slug to the dst directory, which must be an absolute path.
# Structs
IllegalSlugError indicates the provided slug (io.Writer for Pack, io.Reader for Unpack) violates a rule about its contents.
Meta provides detailed information about a slug.
Packer holds options for the Pack function.
# Type aliases
PackerOption is a functional option that can configure non-default Packers.