aboutsummaryrefslogtreecommitdiffstats
path: root/fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf
diff options
context:
space:
mode:
Diffstat (limited to 'fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf')
-rw-r--r--fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf81
1 files changed, 47 insertions, 34 deletions
diff --git a/fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf b/fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf
index 699992db98..a7abab1214 100644
--- a/fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf
+++ b/fdio.infra.terraform/terraform-aws-2n-aws-c5n/main.tf
@@ -49,19 +49,24 @@ module "subnet_d" {
}
# Create Private Key
-resource "tls_private_key" "private_key" {
- algorithm = var.private_key_algorithm
- ecdsa_curve = var.private_key_ecdsa_curve
- rsa_bits = var.private_key_rsa_bits
+module "private_key" {
+ source = "pmikus/private-key/tls"
+ version = "4.0.4"
+
+ private_key_algorithm = var.private_key_algorithm
}
# Create Key Pair
-resource "aws_key_pair" "key_pair" {
- depends_on = [
- tls_private_key.private_key
- ]
- key_name = local.key_pair_key_name
- public_key = tls_private_key.private_key.public_key_openssh
+module "key_pair" {
+ source = "pmikus/key-pair/aws"
+ version = "5.7.0"
+
+ key_pair_key_name = local.key_pair_key_name
+ key_pair_public_key = module.private_key.public_key_openssh
+
+ key_pair_tags = {
+ "Environment" = local.environment
+ }
}
# Create Placement Group
@@ -81,7 +86,7 @@ resource "aws_instance" "tg" {
associate_public_ip_address = var.tg_associate_public_ip_address
instance_initiated_shutdown_behavior = var.tg_instance_initiated_shutdown_behavior
instance_type = var.tg_instance_type
- key_name = aws_key_pair.key_pair.key_name
+ key_name = module.key_pair.key_pair_key_name
placement_group = aws_placement_group.placement_group.id
private_ip = var.tg_private_ip
source_dest_check = var.tg_source_dest_check
@@ -180,7 +185,7 @@ resource "aws_instance" "sut1" {
associate_public_ip_address = var.sut1_associate_public_ip_address
instance_initiated_shutdown_behavior = var.sut1_instance_initiated_shutdown_behavior
instance_type = var.sut1_instance_type
- key_name = aws_key_pair.key_pair.key_name
+ key_name = module.key_pair.key_pair_key_name
placement_group = aws_placement_group.placement_group.id
private_ip = var.sut1_private_ip
source_dest_check = var.sut1_source_dest_check
@@ -264,7 +269,7 @@ resource "null_resource" "deploy_tg" {
connection {
user = "ubuntu"
host = aws_instance.tg.public_ip
- private_key = tls_private_key.private_key.private_key_pem
+ private_key = module.private_key.private_key_pem
}
provisioner "remote-exec" {
@@ -285,7 +290,7 @@ resource "null_resource" "deploy_sut1" {
connection {
user = "ubuntu"
host = aws_instance.sut1.public_ip
- private_key = tls_private_key.private_key.private_key_pem
+ private_key = module.private_key.private_key_pem
}
provisioner "remote-exec" {
@@ -293,30 +298,38 @@ resource "null_resource" "deploy_sut1" {
}
}
-resource "null_resource" "deploy_topology" {
+resource "local_file" "topology_file" {
depends_on = [
aws_instance.tg,
aws_instance.sut1
]
- provisioner "ansible" {
- plays {
- playbook {
- file_path = var.ansible_topology_path
- }
- hosts = ["local"]
- extra_vars = {
- ansible_python_interpreter = local.ansible_python_executable
- testbed_name = local.testbed_name
- cloud_topology = local.topology_name
- tg_if1_mac = data.aws_network_interface.tg_if1.mac_address
- tg_if2_mac = data.aws_network_interface.tg_if2.mac_address
- dut1_if1_mac = data.aws_network_interface.sut1_if1.mac_address
- dut1_if2_mac = data.aws_network_interface.sut1_if2.mac_address
- tg_public_ip = aws_instance.tg.public_ip
- dut1_public_ip = aws_instance.sut1.public_ip
- public_ip_list = "${aws_instance.tg.public_ip},${aws_instance.sut1.public_ip}"
- }
+ content = templatefile(
+ "${path.module}/topology-${local.topology_name}.tftpl",
+ {
+ tg_if1_mac = data.aws_network_interface.tg_if1.mac_address
+ tg_if2_mac = data.aws_network_interface.tg_if2.mac_address
+ dut1_if1_mac = data.aws_network_interface.sut1_if1.mac_address
+ dut1_if2_mac = data.aws_network_interface.sut1_if2.mac_address
+ tg_public_ip = aws_instance.tg.public_ip
+ dut1_public_ip = aws_instance.sut1.public_ip
}
- }
+ )
+ filename = "${path.module}/../../topologies/available/${local.topology_name}-${local.testbed_name}.yaml"
+}
+
+resource "local_file" "hosts" {
+ depends_on = [
+ aws_instance.tg,
+ aws_instance.sut1
+ ]
+
+ content = templatefile(
+ "${path.module}/hosts.tftpl",
+ {
+ tg_public_ip = aws_instance.tg.public_ip
+ dut1_public_ip = aws_instance.sut1.public_ip
+ }
+ )
+ filename = "${path.module}/../../fdio.infra.ansible/inventories/cloud_inventory/hosts.yaml"
} \ No newline at end of file