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