From 8cc7742d89c6c7943cb243efbb4d8ae75cbcc1ef Mon Sep 17 00:00:00 2001 From: Spengreb Date: Tue, 8 Aug 2023 16:12:36 +0200 Subject: [PATCH] Use generated keypair for broadcast side-car --- broadcast.tf | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/broadcast.tf b/broadcast.tf index 4f1f63b..fe6f1c3 100644 --- a/broadcast.tf +++ b/broadcast.tf @@ -2,11 +2,24 @@ resource "aws_instance" "broadcast" { count = var.broadcast_enabled ? 1 : 0 ami = "${data.aws_ami.image.id}" instance_type = "t3.medium" - key_name = "jamulus" + key_name = "${aws_key_pair.generated_key.key_name}" security_groups = [aws_security_group.ssh.name, aws_security_group.broadcast.name, aws_security_group.node-exporter.name] # Add your own IP to this group provisioner "local-exec" { - command = "sleep 30 && ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u ubuntu -i '${self.public_ip},' --private-key ${"${path.module}/jamulus.pem"} broadcast-install.yml" + command = <<-EOT + echo '${tls_private_key.jamulus.private_key_openssh}' > ${aws_key_pair.generated_key.key_name} && + chmod 600 ${aws_key_pair.generated_key.key_name} && + sleep 30 + EOT + } + + provisioner "local-exec" { + command = <<-EOT + ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u ubuntu \ + -i '${self.public_ip},' \ + --private-key "${path.module}/${aws_key_pair.generated_key.key_name}" \ + broadcast-install.yml --extra-vars 'ec2_id=${self.id}' + EOT } tags = {