Launch An AWS Debian AMI and install a Web Server

# Main.tf

/////////////////////////////////////////////////////////////////////
// Fire an AWS instance
/////////////////////////////////////////////////////////////////////


terraform {
required_providers {
aws = {
source = "hashicorp/aws"
#version = "4.64.0"
}
}
}

provider "aws" {
region = "eu-north-1"
#shared_credentials_file = "/home/peter/.aws/credentials"
profile = "testing"
}

resource "aws_instance" "Debian-Server" {
ami = var.debian_ami
instance_type = var.instance_type
key_name = "terraform"
vpc_security_group_ids = [aws_security_group.public_sg.id]

user_data = templatefile("./install_apache.sh.tpl", {
f_name = "peter"
l_name = "Lorimer"
names = ["John", "Alison", "David"]
}
)
}

#resource "aws_default_vpc" "vpc-0bb717b517a4bdd39" {}

resource "aws_security_group" "public_sg" {
name = "Webserver.sg"
description = "Security group for webserver"
vpc_id = "vpc-0bb717b517a4bdd39"


dynamic "ingress" {
for_each = ["80","443","1196","8443","22"]
content {
description = "Allow ports (HTTP,HTTPD,OpenVPN,Plesk,SSH)"
from_port = ingress.value
to_port = ingress.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]

}
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]

}
 
}


variable "debian_ami" {
type = string
default = "ami-0506d6d51f1916a96"
}

variable "instance_type" {
type = string
default = "t3.micro"
}


Previous page: Launch an AWS instance remotely
Next page: AWS


From bland to brand, get your business online
Website hosting and design by Dedicated to Servers, contact info@dedicatedtoservers.com

Click to send a quick inquiry

All rights Reserved © 2014-2024