userhas404d / terraform-external-file-cache

Terraform module to retrieve and cache files

Home Page:https://registry.terraform.io/modules/plus3it/file-cache/external

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

License Travis CI Build Status pullreminders

terraform-external-file-cache

Terraform module to retrieve and cache files. This module retrieves files from a list of URIs and caches them on the local system. If a file already exists in the cache, it is not retrieved again. To force retrieval, use refresh = true.

The module uses an external data resource because the Terraform HTTP provider can only retrieve text/* or application/json content types. It does not support arbitrary files.

Usage

module "file_cache" {
  source = "git::https://github.com/plus3it/terraform-external-file-cache"

  uris = [
    "https://url/to/some/file1",
    "s3://somebucket/some/file2",
    "file:///some/local/file3",
  ]

  refresh = "false"
}

Examples

Requirements

This module uses an external data resource based on a custom python library to retrieve the files, py_getter. You must have python installed and in the PATH to use this Terraform module. The py_getter library also requires the packages in the requirements.txt file. Install them using pip:

sudo pip install -r requirements.txt

If you do not have admin/root privileges to install packages, you can either install packages into the user space (and make sure pip's user environment is in your PATH):

pip install --user -r requirements.txt

Or you can use pipenv with the python_cmd variable to install packages into a virtualenv:

pip install --user pipenv  # or on macos `brew install pipenv`
pipenv install -r requirements.txt
terraform apply -var python_cmd='["pipenv","run","python"]' ...

Limitations

When retrieving files from an S3 bucket this module will resolve the credential based on the boto3 credential resolution order. However, only the ENV, config file, and instance role mechanisms are supported by this module (i.e. cannot pass access/secret/session keys through the module).

This module will not use any credential explicitly specified in a Terraform aws provider, as the external data resource is not (understandably) integrated with the aws provider.

Supported URI Protocols

The custom py_getter library is based on urllib, so this Terraform module supports any URI protocol that is understood by a urllib handler, including http://, https://, ftp://, file://, etc. See the urllib docs for details on built-in handlers.

The module also includes a custom handler for S3 URIs, s3://.

Providers

Name Version
external n/a

Inputs

Name Description Type Default Required
cache_dir Path where files will be cached string ".filecache" no
python_cmd Command to use when executing the python external resource list(string)
[
"python"
]
no
refresh Retrieve file even if the URI is already cached on the system string "false" no
uris List of URIs to the files to be retrieved and cached locally list(string) [] no

Outputs

Name Description
filepaths Map of uri => cached filepaths

Authors

This module is managed by Plus3 IT Systems.

License

Apache 2 licensed. See LICENSE for details.

About

Terraform module to retrieve and cache files

https://registry.terraform.io/modules/plus3it/file-cache/external

License:Apache License 2.0


Languages

Language:Python 62.0%Language:HCL 21.6%Language:Go 14.0%Language:Makefile 1.7%Language:Dockerfile 0.7%