provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "ec2_example" {
ami = "ami-05fa00d4c63e32376"
instance_type = "t2.micro"
key_name= "newkey"
vpc_security_group_ids = [aws_security_group.main.id]
tags = {
"Name" = "UserData command "
}
user_data = <<-EOF
#!/bin/bash
sudo su
sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo echo "<h1>Hello World </h1>" > /var/www/html/index.html
EOF
}
resource "aws_security_group" "main" {
egress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 0
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "-1"
security_groups = []
self = false
to_port = 0
}
]
ingress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 22
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "tcp"
security_groups = []
self = false
to_port = 22
}
]
}
0 comments:
Post a Comment