Group IGS IPI Toulouse |
Master IL 2023/2025 |
Devops & Cloud |
Priscilla Joly |
Create and manage an AWS virtual machine using Ansible
and Terraform
.
Create a Docker Image containing a README
and a web-server application.
- Node.js version >= v18.17.0 is required.
- Have an AWS Account
- Docker install on your machine (local test)
cd client
Install packages :
npm install
Run app :
npm run dev # Or see cleint/REAMDE.md
AWS service name | |
---|---|
Virtual Machine (VM) | EC2 |
Subnet | VPC |
Key pair | EC2 |
Connect AWS CLI
You have to already have a secret key and an access key Easy goto to create key
aws configure
File : Dockerfile
- Create a Docker Image of my application
Check if Docker is running on your computer
docker build DOCKERFILE_PATH
# docker build DOCKERFILE_PATH -t TAG_NAME
List Docker Images and get Image ID
docker images
docker run -p LOCAL_PORT:CONTAINER_PORT IMAGE-ID
# or docker run -p LOCAL_PORT:CONTAINER_PORT TAG_NAME
Folder : terraform-aws
- Create VM on AWS
cd terraform-aws
💡Generate a SSH key
💡You can add your own variables value in
prod.tfvars
terraform init
terraform plan
terraform apply
# or terraform apply -var-file {FILE NAME VARS}
terraform destroy
# or terraform apply -var-file {FILE NAME VARS}
Try to connect to your EC2 instance
Terraform will return your Instance Public IP
Folder : ansible
- Install Docker
- Build and push Docker Image on AWS VM
🚨 In
ansible/inventory
add theansible_hostname
corresponding to your EC2 Adress IP
Run playbook
ansible-playbook -i inventory.ini playbook.yml
Access to your application :
http://YOUR_ADRESS_IP:3000/
ssh-keygen -t rsa -b 2048 -f my-key-name
Documentation AWS EC2
Connexion à votre instance Linux depuis Linux ou macOS à l’aide de SSH
Connectez-vous à votre instance Linux
ssh -i private-key username@IP-adress
💡 username is ubuntu
💡 Terraform will return your Instance Public IP or Get IP adresse
Copy / past your secret key
You can also download CSV file to save it in your computer