X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=fdio.infra.terraform%2Fterraform-aws-1n-aws-c5n%2Fmain.tf;h=e455b6b10431c18bfae19a6e2875b96ea25dacd7;hb=HEAD;hp=c99d839bd2fe83ccdae685d242099f079027bc3e;hpb=9153649f4d6a56821be494fe02d5cd6faa11ebc2;p=csit.git diff --git a/fdio.infra.terraform/terraform-aws-1n-aws-c5n/main.tf b/fdio.infra.terraform/terraform-aws-1n-aws-c5n/main.tf index c99d839bd2..e455b6b104 100644 --- a/fdio.infra.terraform/terraform-aws-1n-aws-c5n/main.tf +++ b/fdio.infra.terraform/terraform-aws-1n-aws-c5n/main.tf @@ -38,19 +38,24 @@ module "subnet_b" { } # 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 @@ -70,7 +75,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 @@ -167,7 +172,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" { @@ -175,27 +180,32 @@ resource "null_resource" "deploy_tg" { } } +resource "local_file" "topology_file" { + depends_on = [ + aws_instance.tg + ] -resource "null_resource" "deploy_topology" { + 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 + tg_public_ip = aws_instance.tg.public_ip + } + ) + filename = "${path.module}/../../topologies/available/${local.topology_name}-${local.testbed_name}.yaml" +} + +resource "local_file" "hosts" { depends_on = [ aws_instance.tg ] - 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 - tg_public_ip = aws_instance.tg.public_ip - public_ip_list = "${aws_instance.tg.public_ip}" - } + content = templatefile( + "${path.module}/hosts.tftpl", + { + tg_public_ip = aws_instance.tg.public_ip } - } + ) + filename = "${path.module}/../../fdio.infra.ansible/inventories/cloud_inventory/hosts.yaml" } \ No newline at end of file