Skip to content

Commit 858faa9

Browse files
committed
first commit
0 parents  commit 858faa9

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform.exe
2+
.terraform
3+
terraform.tfvars
4+
terraform.tfstate.backup
5+
terraform.tfstate
6+
tfplan
7+
.terraform.lock.hcl
8+
terraform.tfstate
9+
.terraform.tfstate.lock.info

main.tf

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
resource "aws_key_pair" "deployer" {
6+
key_name = var.key_name
7+
public_key = var.public_key
8+
}
9+
10+
resource "aws_s3_bucket" "images_bucket" {
11+
bucket = "my-images-bucket"
12+
acl = "public-read"
13+
14+
website {
15+
index_document = "index.html"
16+
error_document = "error.html"
17+
}
18+
}
19+
20+
resource "aws_instance" "web_server" {
21+
ami = "ami-0c55b159cbfafe1f0" # Amazon Linux 2 AMI (HVM), SSD Volume Type
22+
instance_type = "t2.micro"
23+
key_name = aws_key_pair.deployer.key_name
24+
25+
user_data = <<-EOF
26+
#!/bin/bash
27+
sudo yum update -y
28+
sudo yum install -y httpd php php-cli php-json php-mbstring git
29+
sudo systemctl start httpd
30+
sudo systemctl enable httpd
31+
32+
# Installer Composer
33+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
34+
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
35+
php -r "unlink('composer-setup.php');"
36+
EOF
37+
38+
tags = {
39+
Name = "WebServer"
40+
}
41+
}
42+
43+
resource "aws_security_group" "web_sg" {
44+
name = "web_sg"
45+
description = "Allow HTTP and SSH traffic"
46+
47+
ingress {
48+
from_port = 80
49+
to_port = 80
50+
protocol = "tcp"
51+
cidr_blocks = ["0.0.0.0/0"]
52+
}
53+
54+
ingress {
55+
from_port = 22
56+
to_port = 22
57+
protocol = "tcp"
58+
cidr_blocks = ["0.0.0.0/0"]
59+
}
60+
61+
egress {
62+
from_port = 0
63+
to_port = 0
64+
protocol = "-1"
65+
cidr_blocks = ["0.0.0.0/0"]
66+
}
67+
}
68+
69+
resource "

terraform.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Initialiser Terraform
2+
terraform init
3+
4+
# Générer le plan et l'enregistrer dans un fichier nommé tfplan
5+
terraform plan -var-file="terraform.tfvars" -out=tfplan
6+
7+
# Appliquer le plan enregistré
8+
terraform apply "tfplan"
9+
10+
# Détruire les ressources sans demande de confirmation
11+
terraform destroy -var-file="terraform.tfvars" -auto-approve

variables.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "key_name" {
2+
description = "The name of the SSH key to use"
3+
type = string
4+
}
5+
6+
variable "public_key" {
7+
description = "The SSH public key"
8+
type = string
9+
}

0 commit comments

Comments
 (0)