Add behavior :

- Personal SSH Key 🔐
- Deploy repository from variables ⚙️
- Import custom network images 🛜
This commit is contained in:
Damien A
2023-11-10 10:59:04 +01:00
parent 78322ee157
commit 609e616d7c
7 changed files with 84 additions and 18 deletions

View File

@@ -4,20 +4,6 @@ provider "aws" {
secret_key = var.AWS_SECRET_KEY
}
resource "aws_key_pair" "tf-key-pair" {
key_name = "tf-key-pair"
public_key = tls_private_key.rsa.public_key_openssh
}
resource "tls_private_key" "rsa" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "local_file" "tf-key" {
content = tls_private_key.rsa.private_key_pem
filename = "tf-key-pair.pem"
file_permission = "0600"
}
resource "aws_security_group" "netlab_sg" {
name = "netlab_sg"
@@ -45,14 +31,21 @@ resource "aws_security_group" "netlab_sg" {
resource "aws_instance" "containerlab_host" {
ami = var.AWS_AMIS[var.AWS_REGION]
instance_type = "t2.xlarge"
key_name = "tf-key-pair"
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 ./tf-key-pair.pem ../ansible/install_containerlab.yml"
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}"
}
}

View File

@@ -1,3 +1,7 @@
output "public_ip" {
value = aws_instance.containerlab_host.public_ip
}
}
output "containerlab_fqdn" {
value = "${aws_route53_record.containerlab_fqdn.name}.${data.aws_route53_zone.selected.name}"
}

View File

@@ -0,0 +1,12 @@
data "aws_route53_zone" "selected" {
zone_id = var.AWS_R53_ZONE_ID
}
resource "aws_route53_record" "containerlab_fqdn" {
zone_id = var.AWS_R53_ZONE_ID
name = "containerlab"
type = "A"
ttl = "300"
records = [aws_instance.containerlab_host.public_ip]
}

View File

@@ -1,5 +1,13 @@
variable "AWS_ACCESS_KEY" {}
variable "AWS_SECRET_KEY" {}
variable "AWS_KEY_NAME" {}
variable "AWS_KEY_LOCATION" {}
variable "AWS_R53_ZONE_ID" {}
variable "GITHUB_REPO_URL" {
type = string
default = ""
}
variable "AWS_REGION" {
type = string