LAB: Terraform Provisioners (EC2 + remote-exec + file)
Provision EC2 → upload script → execute script automatically 📁 Project Structure terraform-provisioners-lab/ │ ├── main.tf ├── variables.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars │ ├...

Source: DEV Community
Provision EC2 → upload script → execute script automatically 📁 Project Structure terraform-provisioners-lab/ │ ├── main.tf ├── variables.tf ├── outputs.tf ├── providers.tf ├── terraform.tfvars │ ├── scripts/ │ └── install_nginx.sh │ └── ssh/ └── id_rsa.pub # your public key 1️⃣ providers.tf terraform { required_version = ">= 1.5.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } provider "aws" { region = var.aws_region } 2️⃣ variables.tf variable "aws_region" { description = "AWS region" type = string } variable "instance_type" { description = "EC2 instance type" type = string } variable "key_name" { description = "SSH key name" type = string } variable "public_key_path" { description = "Path to public key" type = string } variable "private_key_path" { description = "Path to private key" type = string } variable "ami_owner" { description = "AMI owner" type = string default = "amazon" } 3️⃣ terraform.tfvars (NO hardcoding in code) aws_region = "us-e