-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add terraform script for staging env
- Loading branch information
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//provider "aws" { | ||
// region = var.aws_region | ||
// access_key = var.access_key | ||
// secret_key = var.secret_key | ||
//} | ||
|
||
# Create Security Group to allow port 80, 443 | ||
resource "aws_security_group" "allow_web" { | ||
name = "plm-staging-sg-br-X" | ||
description = "Allow Web inbound traffic" | ||
vpc_id = var.vpc_id | ||
ingress { | ||
description = "HTTPS" | ||
from_port = 443 | ||
to_port = 443 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
ingress { | ||
description = "HTTP" | ||
from_port = 80 | ||
to_port = 80 | ||
protocol = "tcp" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
} | ||
ingress { | ||
description = "SSH" | ||
from_port = 22 | ||
to_port = 22 | ||
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"] | ||
} | ||
tags = { | ||
Name = "plm-staging-sg-br-X" | ||
} | ||
} | ||
|
||
|
||
# Create a network interface with an ip in the subnet | ||
resource "aws_network_interface" "web-server-nic" { | ||
subnet_id = var.subnet_id | ||
security_groups = [aws_security_group.allow_web.id] | ||
tags = { | ||
Name = "plm-staging-ni-br-X" | ||
} | ||
} | ||
|
||
|
||
# Assign an Elastic IP to the network interface created | ||
resource "aws_eip" "elastic-ip" { | ||
domain = "vpc" | ||
network_interface = aws_network_interface.web-server-nic.id | ||
associate_with_private_ip = aws_network_interface.web-server-nic.private_ip | ||
tags = { | ||
Name = "plm-staging-eip-br-X" | ||
} | ||
} | ||
|
||
output "server_public_ip" { | ||
value = aws_eip.elastic-ip.public_ip | ||
} | ||
|
||
|
||
# Create an EC2 instance and install Docker | ||
resource "aws_instance" "ec2-staging" { | ||
ami = var.ami_id | ||
instance_type = var.instance_type | ||
availability_zone = var.ec2_availability_zone | ||
|
||
network_interface { | ||
device_index = 0 | ||
network_interface_id = aws_network_interface.web-server-nic.id | ||
} | ||
|
||
user_data = <<-EOF | ||
#!/bin/bash | ||
sudo yum update -y | ||
sudo amazon-linux-extras install docker | ||
sudo service docker start | ||
sudo usermod -a -G docker ec2-user | ||
EOF | ||
|
||
tags = { | ||
Name = "plm-staging-instance-branch-X" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//aws_region = "eu-west-3" | ||
//access_key = ${{ secrets.AWS_TF_ACCESS_KEY_ID }} | ||
//secret_key = ${{ secrets.AWS_TF_SECRET_ACCESS_KEY }} | ||
vpc_id = "vpc-d2d538ba" | ||
subnet_id = "subnet-d5a1d598" | ||
ami_id = "ami-072056ff9d3689e7b" | ||
instance_type = "t2.micro" | ||
ec2_availability_zone = "eu-west-3c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
variable "aws_region" { | ||
description = "AWS Region" | ||
type = string | ||
} | ||
variable "access_key" { | ||
description = "AWS Access Key" | ||
type = string | ||
} | ||
variable "secret_key" { | ||
description = "AWS Secret Key" | ||
type = string | ||
} | ||
*/ | ||
|
||
variable "vpc_id" { | ||
description = "VPC ID" | ||
type = string | ||
} | ||
|
||
variable "subnet_id" { | ||
description = "Subnet ID" | ||
type = string | ||
} | ||
|
||
variable "ami_id" { | ||
description = "ID de l'AMI EC2" | ||
type = string | ||
} | ||
|
||
variable "instance_type" { | ||
description = "Type d'instance EC2" | ||
type = string | ||
} | ||
|
||
variable "ec2_availability_zone" { | ||
description = "EC2 Availability Zone" | ||
type = string | ||
} |