Skip to content

You are viewing documentation for Instruqt 2.0 Labs - our upcoming product releasing in September 2026. For current Tracks documentation, please visitdocs.instruqt.com.

Copy


Defined insandbox.hcl

The copy resource transfers files and directories from various sources to destinations. It supports local files, remote URLs, Git repositories, and automatically extracts archives like ZIP files.

As a lab author, you can use copy resources to:

  • Configuration Deployment: Copy configuration files, templates, and settings to application directories
  • Source Code Management: Clone Git repositories or specific subdirectories for lab exercises
  • Data Seeding: Load sample datasets, initial database files, and test data

Copy resources enable flexible file management across local and remote sources, supporting various lab setup scenarios.

resource "copy" "name" {
source = "./files/config.yaml"
destination = "./config/"
}
resource "copy" "name" {
source = "https://releases.hashicorp.com/consul/1.16.0/consul_1.16.0_linux_amd64.zip"
destination = "./binaries/"
permissions = "0755"
}

Fields

FieldTypeRequiredDescription
sourcestringPath to the source file or directory to copy. Can be a local path relative to the HCL file, an absolute path, or a URL (http://, https://)
destinationstringTarget path where the source will be copied to. Must be an absolute path.
permissionsstringOptional Unix permissions for the copied files in octal notation (e.g., '0755' for rwxr-xr-x)
ConstraintsPermissions must be in octal format (e.g., 0755)

Computed Attributes

These attributes are set by the system and are read-only.

AttributeTypeDescription
copied_fileslist(string)List of files that were copied during the operation

The copy resource supports multiple source types:

## Single file
source = "./files/config.yaml"
# Directory (copies all contents)
source = "./assets/"
# Absolute path
source = "/usr/share/data"
# Direct file download
source = "https://example.com/file.txt"
# Archive download (auto-extracted)
source = "https://github.com/org/repo/archive/main.zip"
# Full repository
source = "github.com/username/repository"
# Specific subdirectory
source = "github.com/username/repository//subdir"
# Specific branch/tag
source = "github.com/username/repository?ref=v1.0.0"
resource "copy" "app_config" {
source = "./config/application.yaml"
destination = "./app/config/"
permissions = "0644"
}
resource "copy" "scripts" {
source = "./scripts/"
destination = "./app/bin/"
permissions = "0755"
}
resource "copy" "consul_binary" {
source = "https://releases.hashicorp.com/consul/1.16.0/consul_1.16.0_linux_amd64.zip"
destination = "./binaries/"
permissions = "0755"
}
resource "copy" "examples" {
source = "github.com/instruqt/examples"
destination = "./examples/"
}
resource "copy" "terraform_modules" {
source = "github.com/terraform-aws-modules/terraform-aws-vpc//modules/vpc?ref=v3.14.0"
destination = "./modules/vpc/"
}
resource "copy" "sample_data" {
source = "https://api.example.com/data/sample.json"
destination = "./data/sample.json"
permissions = "0644"
}
# Configuration files
resource "copy" "config" {
source = "./config/"
destination = "./app/config/"
permissions = "0644"
}
# Scripts with execution permissions
resource "copy" "scripts" {
source = "./scripts/"
destination = "./app/scripts/"
permissions = "0755"
}
# Static assets
resource "copy" "assets" {
source = "https://cdn.example.com/assets.zip"
destination = "./app/static/"
permissions = "0644"
}
# External dependencies
resource "copy" "dependencies" {
source = "github.com/vendor/lib//dist"
destination = "./app/lib/"
permissions = "0755"
}
resource "copy" "app_files" {
source = "./application/"
destination = "./container-data/app/"
permissions = "0644"
}
resource "container" "web" {
image {
name = "nginx:alpine"
}
volume {
source = resource.copy.app_files.destination
destination = "/usr/share/nginx/html"
type = "bind"
read_only = true
}
}
resource "copy" "base_config" {
source = "./config/base/"
destination = "./app/config/"
}
resource "copy" "env_config" {
depends_on = [resource.copy.base_config]
source = "./config/production/"
destination = "./app/config/"
permissions = "0600" # Sensitive production config
}
# Download Docker Compose
resource "copy" "docker_compose" {
source = "https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-linux-x86_64"
destination = "./tools/docker-compose"
permissions = "0755"
}
# Download Terraform
resource "copy" "terraform" {
source = "https://releases.hashicorp.com/terraform/1.5.0/terraform_1.5.0_linux_amd64.zip"
destination = "./tools/"
permissions = "0755"
}
# Clone configuration templates
resource "copy" "templates" {
source = "github.com/company/infrastructure-templates//docker"
destination = "./templates/"
permissions = "0644"
}
# Copy application source code
resource "copy" "source_code" {
source = "github.com/mycompany/webapp//src"
destination = "./app/src/"
permissions = "0644"
}
# Copy configuration files
resource "copy" "config_files" {
depends_on = [resource.copy.source_code]
source = "./config/app.yaml"
destination = "./app/config/app.yaml"
permissions = "0600"
}
# Download dependencies
resource "copy" "node_modules" {
source = "https://registry.npmjs.org/@mycompany/shared/-/shared-1.0.0.tgz"
destination = "./app/node_modules/"
permissions = "0644"
}

Different permission settings for various file types:

# Read-only configuration files
resource "copy" "readonly_config" {
source = "./config.yaml"
destination = "./app/config.yaml"
permissions = "0444" # Read-only for all users
}
# Executable scripts
resource "copy" "startup_script" {
source = "./startup.sh"
destination = "./app/startup.sh"
permissions = "0755" # Read/execute for all, write for owner
}
# Sensitive files (owner only)
resource "copy" "secrets" {
source = "./secrets.env"
destination = "./app/secrets.env"
permissions = "0600" # Read/write for owner only
}
# Public files
resource "copy" "public_assets" {
source = "./public/"
destination = "./app/public/"
permissions = "0644" # Read for all, write for owner
}
  1. Permission Security: Use restrictive permissions for sensitive files (0600, 0644)
  2. Executable Permissions: Set 0755 for scripts and binaries
  3. Source Control: Use specific Git references (tags/commits) for reproducible builds
  4. Archive Handling: Copy resource automatically extracts common archive formats
  5. Path Consistency: Use consistent path conventions across your configuration
  6. Dependencies: Use depends_on for operations that must happen in sequence
  7. Validation: Test source URLs and paths before deploying