From 22072de929a89f2c2bee9345a868a71af2a84ba4 Mon Sep 17 00:00:00 2001 From: Damien A Date: Tue, 2 Jan 2024 19:32:23 +0100 Subject: [PATCH] DNS Configuration Conditioning : - Add AWS_R53_ENABLED variable - Update Documentation - Add ToDo --- README.md | 12 +++++++++++- terraform/ec2.tf | 3 +++ terraform/outputs.tf | 2 +- terraform/route53-record.tf | 2 +- terraform/terraform.tfvars.sample | 1 + terraform/variables.tf | 4 ++++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f84e018..97c7b4b 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ This project automates the deployment of ContainerLab on an AWS EC2 instance using Terraform for infrastructure provisioning and Ansible for software setup and configuration. It also configures a Route53 DNS record for easy access to the ContainerLab instance. +## To Do + +- [ ] Improving documentation +- [ ] Complete DNS configuration conditioning + ## Prerequisites Before you begin, ensure you have the following prerequisites installed and configured: @@ -84,7 +89,12 @@ The `network_images` folder is intended for Docker images that will be used by C - You can access the ContainerLab instance via SSH using the public IP or the DNS name provided by Route53. - The public IP of the instance can be found in the Terraform output. -- The DNS name will be in the format containerlab `` +- The DNS name will be in the format containerlab ``. + +> :warning: **ROUTE 53** +> By default, Route 53 is disabled to avoid errors in case of incomplete configuration. +> To enable it, modify the variables: `AWS_R53_ENABLED` and `AWS_R53_ZONE_ID`. +> In any case, `AWS_R53_ZONE_ID` need to be configured. ## Customization diff --git a/terraform/ec2.tf b/terraform/ec2.tf index 444a7f2..a5af368 100755 --- a/terraform/ec2.tf +++ b/terraform/ec2.tf @@ -33,6 +33,9 @@ resource "aws_instance" "containerlab_host" { instance_type = var.INSTANCE_TYPE key_name = var.AWS_KEY_NAME vpc_security_group_ids = [aws_security_group.netlab_sg.id] + tags = { + Name = "ContainerLab" + } root_block_device { volume_size = "128" diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 236fff1..5b1e939 100755 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -3,5 +3,5 @@ output "public_ip" { } output "containerlab_fqdn" { - value = "${aws_route53_record.containerlab_fqdn.name}.${data.aws_route53_zone.selected.name}" + value = var.AWS_R53_ENABLED && length(aws_route53_record.containerlab_fqdn) > 0 ? "${aws_route53_record.containerlab_fqdn[0].name}.${data.aws_route53_zone.selected.name}" : "" } diff --git a/terraform/route53-record.tf b/terraform/route53-record.tf index 73faaf8..7f901d3 100755 --- a/terraform/route53-record.tf +++ b/terraform/route53-record.tf @@ -2,8 +2,8 @@ data "aws_route53_zone" "selected" { zone_id = var.AWS_R53_ZONE_ID } - resource "aws_route53_record" "containerlab_fqdn" { + count = var.AWS_R53_ENABLED ? 1 : 0 zone_id = var.AWS_R53_ZONE_ID name = "containerlab" type = "A" diff --git a/terraform/terraform.tfvars.sample b/terraform/terraform.tfvars.sample index 4e1cfdc..1ee77d0 100755 --- a/terraform/terraform.tfvars.sample +++ b/terraform/terraform.tfvars.sample @@ -2,4 +2,5 @@ AWS_ACCESS_KEY = "YOURACCESSKEY" AWS_SECRET_KEY = "YOURACCESSTOKEN" AWS_KEY_NAME = "AWS_key_name" AWS_KEY_LOCATION = "~/.ssh/aws_key.pem" +AWS_R53_ENABLED = "false" AWS_R53_ZONE_ID = "R53_ZONE_ID" \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index b2e2441..865b22f 100755 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -3,6 +3,10 @@ variable "AWS_SECRET_KEY" {} variable "AWS_KEY_NAME" {} variable "AWS_KEY_LOCATION" {} variable "AWS_R53_ZONE_ID" {} +variable "AWS_R53_ENABLED" { + type = bool + default = false +} variable "GITHUB_REPO_URL" { type = string