LAB: Terraform EC2 with `user_data`
🎯 Goal Provision an EC2 instance that: Installs Nginx automatically Starts the service Serves a custom web page 👉 All using user_data (bootstrapping) 📁 Project Structure terraform-userdata-lab/ ...

Source: DEV Community
🎯 Goal Provision an EC2 instance that: Installs Nginx automatically Starts the service Serves a custom web page 👉 All using user_data (bootstrapping) 📁 Project Structure terraform-userdata-lab/ ├── main.tf ├── variables.tf ├── terraform.tfvars ├── providers.tf ├── versions.tf ├── outputs.tf └── user_data.sh.tpl 📄 versions.tf terraform { required_version = ">= 1.5.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } 📄 providers.tf provider "aws" { region = var.aws_region } 📄 variables.tf variable "aws_region" { type = string description = "AWS region" } variable "instance_type" { type = string description = "EC2 type" } variable "instance_name" { type = string description = "Name of instance" } variable "web_message" { type = string description = "Message shown on web page" } variable "common_tags" { type = map(string) description = "Common tags" } 📄 terraform.tfvars aws_region = "us-east-2" instance_type = "t2.micro" instance_name = "userdata-l