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