aws_throwaway/
ec2_instance_definition.rs

1use crate::InstanceType;
2
3/// Defines an instance that can be launched via [`crate::Aws::create_ec2_instance`]
4pub struct Ec2InstanceDefinition {
5    pub(crate) instance_type: InstanceType,
6    pub(crate) volume_size_gb: u32,
7    pub(crate) network_interface_count: u32,
8    pub(crate) os: InstanceOs,
9    pub(crate) ami: Option<String>,
10}
11
12impl Ec2InstanceDefinition {
13    /// Start defining an instance with the specified instance type
14    pub fn new(instance_type: InstanceType) -> Self {
15        Ec2InstanceDefinition {
16            instance_type,
17            volume_size_gb: 8,
18            network_interface_count: 1,
19            os: InstanceOs::Ubuntu22_04,
20            ami: None,
21        }
22    }
23
24    // Set instance to have a root volume of the specified size.
25    // Defaults to 8GB.
26    pub fn volume_size_gigabytes(mut self, size_gb: u32) -> Self {
27        self.volume_size_gb = size_gb;
28        self
29    }
30
31    /// Sets the amount of network interfaces to use on this instance.
32    /// Defaults to 1
33    ///
34    /// Setting this to a value other than 1 will result in the creation of an elastic ip to point at your instance.
35    /// This is an unfortunate requirement of AWS ECS, instances with multiple network interfaces do not get the automatically assigned ipv4 address given to instances with 1 network interface.
36    /// For most users there is a hard limit of 5 elastic ip addresses allowed at one time.
37    pub fn network_interface_count(mut self, count: u32) -> Self {
38        self.network_interface_count = count;
39        self
40    }
41
42    // Set the OS used by the instance.
43    // Defaults to `Ubuntu 22.04`
44    pub fn os(mut self, os: InstanceOs) -> Self {
45        self.os = os;
46        self
47    }
48
49    /// Override the AMI used.
50    /// When used together with the `os` setting, the os setting is used to determine how to configure the instance while the specified AMI is used as the instances image.
51    /// Defaults to None which indicates that the appropriate AMI should be looked up via SSM.
52    ///
53    /// This option is useful when you have custom variation of the configured OS or if your user does not have access to SSM.
54    /// AMI's are region specific so be careful in picking your AMI.
55    pub fn override_ami(mut self, ami: Option<String>) -> Self {
56        self.ami = ami;
57        self
58    }
59}
60
61/// aws-throwaway needs to manually support each OS, so the only OS's you can use are those listed in this enum.
62/// Support for more (similar) OS's is welcome via pull request.
63#[derive(Clone, Copy)]
64#[non_exhaustive]
65pub enum InstanceOs {
66    Ubuntu20_04,
67    Ubuntu22_04,
68}