From 15188a6475890ffbcea81d9337aa1358d78d277c Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Mon, 5 Feb 2024 10:30:32 +1100 Subject: [PATCH] Various bugfixes (#46) Co-authored-by: Conor --- aws-throwaway/src/backend/cli/mod.rs | 37 +++++++++++++++------------- aws-throwaway/src/backend/sdk/aws.rs | 3 ++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/aws-throwaway/src/backend/cli/mod.rs b/aws-throwaway/src/backend/cli/mod.rs index 3637b58..32c00ab 100644 --- a/aws-throwaway/src/backend/cli/mod.rs +++ b/aws-throwaway/src/backend/cli/mod.rs @@ -226,7 +226,8 @@ impl Aws { let result: SecurityGroup = run_command(&command).await.unwrap(); tracing::info!("created security group"); - let mut futures = FuturesUnordered::>>>::new(); + let mut futures = + FuturesUnordered:: + Send>>>::new(); futures.push(Box::pin(Aws::create_ingress_rule_internal(tags, name))); if !ports.contains(&22) { // SSH @@ -505,13 +506,14 @@ impl Aws { struct ElasticIp { #[serde(alias = "PublicIp")] public_ip: String, + #[serde(alias = "AllocationId")] allocation_id: String, } let result: ElasticIp = run_command(&[ "ec2", "allocate-address", "--tag-specifications", - &self.tags.create_tags("elastic-Ip", "aws-throwaway"), + &self.tags.create_tags("elastic-ip", "aws-throwaway"), ]) .await .unwrap(); @@ -576,7 +578,7 @@ impl Aws { "AvailabilityZone={AZ},GroupName={}", self.placement_group_name ); - let user_data = base64::engine::general_purpose::STANDARD.encode(format!( + let user_data = format!( r#"#!/bin/bash sudo systemctl stop ssh echo "{}" > /etc/ssh/ssh_host_ed25519_key.pub @@ -586,7 +588,8 @@ echo "ClientAliveInterval 30" >> /etc/ssh/sshd_config sudo systemctl start ssh "#, self.host_public_key, self.host_private_key - )); + ); + let user_data = base64::engine::general_purpose::STANDARD.encode(user_data); let block_device_mappings = format!( "DeviceName=/dev/sda1,Ebs={{DeleteOnTermination=true,VolumeSize={},VolumeType=gp2}}", definition.volume_size_gb @@ -612,7 +615,7 @@ sudo systemctl start ssh "--block-device-mappings", &block_device_mappings, ]; - let value; + let mut value = vec![]; if definition.network_interface_count == 1 { command.push("--subnet-id"); command.push(&self.subnet_id); @@ -621,18 +624,18 @@ sudo systemctl start ssh command.push("--security-group-ids"); command.push(&self.security_group_id); } else { - command.push("--networking-interfaces"); - value = (0..definition.network_interface_count) - .map(|i| { - format!( - "DeleteOnTermination=true,AssociatePublicIpAddress=false,DeviceIndex={i},Groups={},SubnetId={},Description={i}", - &self.security_group_id, - &self.subnet_id - ) - }) - .collect::>() - .join(","); - command.push(&value); + command.push("--network-interfaces"); + for i in 0..definition.network_interface_count { + value.push(format!( + "DeleteOnTermination=true,AssociatePublicIpAddress=false,DeviceIndex={i},Groups={},SubnetId={},Description={i}", + &self.security_group_id, + &self.subnet_id + )); + } + // lifetimes workaround + for value in &value { + command.push(value) + } } let result: RunInstancesResponse = run_command(&command).await.unwrap(); diff --git a/aws-throwaway/src/backend/sdk/aws.rs b/aws-throwaway/src/backend/sdk/aws.rs index 6a84b62..65924fc 100644 --- a/aws-throwaway/src/backend/sdk/aws.rs +++ b/aws-throwaway/src/backend/sdk/aws.rs @@ -160,7 +160,8 @@ impl Aws { .unwrap(); tracing::info!("created security group"); - let mut futures = FuturesUnordered::>>>::new(); + let mut futures = + FuturesUnordered:: + Send>>>::new(); futures.push(Box::pin(Aws::create_ingress_rule_internal( client, tags, name, )));