A terraform provider to create to create a zip file from different kind of source, this sources can be:
It uses zipper under the hood.
Requirements: You need, of course, terraform (>=0.12) which is available here: https://www.terraform.io/downloads.html
To install a specific version, set PROVIDER_CLOUDFOUNDRY_VERSION before executing the following command
$ export PROVIDER_ZIPPER_VERSION="v0.12.0"
$ bash -c "$(curl -fsSL https://raw.github.com/ArthurHlt/terraform-provider-zipper/master/bin/install.sh)"
$ bash -c "$(wget https://raw.github.com/ArthurHlt/terraform-provider-zipper/master/bin/install.sh -O -)"
- Get the build for your system in releases: https://github.com/ArthurHlt/terraform-provider-zipper/releases/latest
- Create a
providers
directory inside terraform user folder:mkdir -p ~/.terraform.d/providers
- Move the provider previously downloaded in this folder:
mv /path/to/download/directory/terraform-provider-zipper ~/.terraform.d/providers
- Ensure provider is executable:
chmod +x ~/.terraform.d/providers/terraform-provider-zipper
- add
providers
path to your.terraformrc
:
cat <<EOF > ~/.terraformrc
providers {
zipper = "/full/path/to/.terraform.d/providers/terraform-provider-zipper"
}
EOF
- you can now performs any terraform action on zipper resources
Simple example to retrieve a git repository and use it on AWS Lambda function:
provider "zipper" {
skip_ssl_validation = false
}
resource "zipper_file" "fixture" {
source = "https://github.com/ArthurHlt/go-lambda-ping.git"
output_path = "path/to/lambda/function.zip"
}
resource "aws_iam_role" "lambda_exec_role" {
name = "lambda_exec_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_lambda_function" "demo_lambda" {
function_name = "demo_lambda"
handler = "main"
runtime = "go1.x"
filename = "${zipper_file.fixture.output_path}"
source_code_hash = "${zipper_file.fixture.output_sha}"
role = "${aws_iam_role.lambda_exec_role.arn}"
}
Zip file from different kind of source as resource by using zipper. Using as resource permit to not download when not necessary.
Basic usage
resource "zipper_file" "fixture" {
type = "git"
source = "https://github.com/ArthurHlt/go-lambda-ping.git"
output_path = "path/to/lambda/function.zip"
not_when_nonexists = false
}
The following arguments are supported:
source
- (Required) Target source for zipper written in uri style (see zipper doc for more information).output_path
- (Required) The output of the archive file.type
- (Optional) Source type to use to create zip, e.g.: http, local or git. (if omitted type will be auto-detected)not_when_nonexists
- (Optional) Set to true to not create zip when not exists at output_path if sources files didn't change. (to earn time if not necessary)
The following attributes are exported:
id
- Id is actually equivalent tooutput_sha
.output_sha
- SHA1 checksum made by zipper.output_size
- Size of the zip file.
Equivalent to resource but less smart to know when to download or not source (less restrictive than a resource).