Skip to content

Instantly share code, notes, and snippets.

@tkamag
Last active November 23, 2023 05:13
Show Gist options
  • Select an option

  • Save tkamag/255b500c852cccb5e98acfdac09c0b33 to your computer and use it in GitHub Desktop.

Select an option

Save tkamag/255b500c852cccb5e98acfdac09c0b33 to your computer and use it in GitHub Desktop.
resource "aws_instance" "my-ec2-vm" {
  ami                    = "ami-047a51fa27710816e" # Amazon Linux
  instance_type          = "t2.micro"
  key_name               = "terraform-key"
  subnet_id              = aws_subnet.vpc-dev-public-subnet-1.id
  vpc_security_group_ids = [aws_security_group.dev-vpc-sg.id]
  #user_data = file("apache-install.sh")
  user_data = <<-EOF
    #!/bin/bash
    sudo yum update -y
    sudo yum install httpd -y
    sudo systemctl enable httpd
    sudo systemctl start httpd
    echo "<h1>Welcome ! AWS Infra created using Terraform in us-east-1 Region</h1>" > /var/www/html/index.html
    EOF
  tags = {
    "Name" = "myec2vm"
  }    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment