Files
AWS-ContainerLab-Deployment/terraform/main.tf
Damien A 609e616d7c Add behavior :
- Personal SSH Key 🔐
- Deploy repository from variables ⚙️
- Import custom network images 🛜
2023-11-10 10:59:04 +01:00

51 lines
1.3 KiB
HCL

provider "aws" {
region = var.AWS_REGION
access_key = var.AWS_ACCESS_KEY
secret_key = var.AWS_SECRET_KEY
}
resource "aws_security_group" "netlab_sg" {
name = "netlab_sg"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 50080
to_port = 50080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "containerlab_host" {
ami = var.AWS_AMIS[var.AWS_REGION]
instance_type = "t2.xlarge"
key_name = var.AWS_KEY_NAME
vpc_security_group_ids = [aws_security_group.netlab_sg.id]
root_block_device {
volume_size = "128"
volume_type = "gp2"
encrypted = "false"
delete_on_termination = "true"
}
provisioner "local-exec" {
command = "echo ${aws_instance.containerlab_host.public_ip} > ../ansible/inventory"
}
provisioner "local-exec" {
command = "sleep 20; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u admin -i ../ansible/inventory --private-key ${var.AWS_KEY_LOCATION} ../ansible/install_containerlab.yml --extra-vars repo_git_url=${var.GITHUB_REPO_URL}"
}
}