Skip to main content

Provisioners and Packaging

Updated Jan 24, 2021 ·

Overview

Terraform can package small deployment artifacts and run provisioners, but infrastructure definitions should stay the main responsibility of Terraform.

Archive File

The archive_file data source can create a zip file for simple Lambda deployments.

data "archive_file" "lambda_zip" {
type = "zip"
source_file = "main.py"
output_path = "main.zip"
}

The generated zip should not be committed. It can be recreated during terraform plan or terraform apply.

Provisioners

Provisioners run scripts or local commands as part of resource creation.

ProvisionerRuns onCommon use
local-execTerraform workstationBuild or registration commands.
remote-execCreated instanceBootstrap commands over SSH or WinRM.
fileCreated instanceCopy scripts or config files.
warning

Use provisioners carefully. Prefer cloud-init, user data, managed images, or a configuration management tool when those options fit the job.