summaryrefslogtreecommitdiff
path: root/src/ec2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ec2.rs')
-rw-r--r--src/ec2.rs44
1 files changed, 6 insertions, 38 deletions
diff --git a/src/ec2.rs b/src/ec2.rs
index 998b98b..0457643 100644
--- a/src/ec2.rs
+++ b/src/ec2.rs
@@ -3,29 +3,24 @@ use std::collections::HashSet;
use anyhow::Result;
use aws_sdk_ec2 as ec2;
use aws_sdk_ec2::types::Filter;
-use aws_sdk_route53::types::{ResourceRecord, ResourceRecordSet, RrType};
-// Needed until try_collect is stable, see <https://github.com/rust-lang/rust/issues/94047>
-use itertools::Itertools;
-use trust_dns_proto::rr::Name;
+use aws_sdk_route53::types::{ResourceRecordSet, RrType};
use crate::hashable::Hashable;
+use crate::route53::Target;
pub trait Ec2 {
fn ec2(&self) -> &ec2::Client;
}
-pub async fn instance_proposal<C>(
+pub async fn asg_instances_proposal<C>(
aws_context: &C,
+ target: &Target,
asg_name: &str,
- dns_name: &Name,
- dns_ttl: i64,
live_instance_ids: &[String],
) -> Result<HashSet<Hashable<ResourceRecordSet>>>
where
C: Ec2,
{
- assert!(dns_name.is_fqdn());
-
// If there's nothing running, then (a) we don't need to ask AWS about
// running instances, and (b) we can't anyways as the API call requires at
// least one instance ID. Abort here.
@@ -69,9 +64,8 @@ where
}
}
- let dns_name = dns_name.to_ascii();
- let ip4_proposal = host_proposal(&dns_name, dns_ttl, RrType::A, ip4)?;
- let ip6_proposal = host_proposal(&dns_name, dns_ttl, RrType::Aaaa, ip6)?;
+ let ip4_proposal = target.host_proposal(RrType::A, ip4)?;
+ let ip6_proposal = target.host_proposal(RrType::Aaaa, ip6)?;
Ok(ip4_proposal
.into_iter()
@@ -79,29 +73,3 @@ where
.map(Hashable::from)
.collect())
}
-
-fn host_proposal(
- dns_name: &str,
- dns_ttl: i64,
- rr_type: RrType,
- addresses: HashSet<impl Into<String>>,
-) -> Result<Option<ResourceRecordSet>> {
- if addresses.is_empty() {
- Ok(None)
- } else {
- let records = addresses
- .into_iter()
- .map(|address| address.into())
- .map(|address| ResourceRecord::builder().value(address).build())
- .try_collect()?;
-
- let record_set = ResourceRecordSet::builder()
- .name(dns_name)
- .r#type(rr_type)
- .ttl(dns_ttl)
- .set_resource_records(Some(records))
- .build()?;
-
- Ok(Some(record_set))
- }
-}