From efdbf890818480755ddbc4905a03924bc145e225 Mon Sep 17 00:00:00 2001 From: Gustav Behm Date: Fri, 31 May 2024 11:55:19 +0200 Subject: [PATCH] Populate values that make terraform replace the aws_ebs_snapshot --- openbsd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openbsd b/openbsd index 1e3c567..27536fa 100755 --- a/openbsd +++ b/openbsd @@ -1835,6 +1835,9 @@ class AWS: self.logger.info(f"snapshot import: s3://{bucket}/{key} -> {si}") return si + def describe_snapshot(self, si): + return self.ec2.describe_snapshots(SnapshotIds=[si])["Snapshots"][0] + def ami_cmd(self, args): aws = Spec.from_args(args, "aws") ami_spec = aws["ami"] @@ -1928,6 +1931,7 @@ class AWS: default_resource_label = "%APP-%OS-%VERSION-%SALT" ami = render_template(tf.get("aws_ami", default_resource_label)) snap = render_template(tf.get("aws_ebs_snapshot", default_resource_label)) + snap_description = self.describe_snapshot(si) i = ' '*tf.get("indent", 2) tag_lines = [ f'{i}tags = {{' ] + [ f'{i}{i}{k} = "{v}"' for k, v in tags.items() ] + [ f'{i}}}' ] @@ -1970,7 +1974,8 @@ class AWS: f'}}', f'', f'resource "aws_ebs_snapshot" "{snap}" {{', - f' volume_id = "vol-ffffffff"', + f' volume_id = "{snap_description["VolumeId"]}"', + f' description = "{snap_description["Description"]}"', ] + tag_lines + [ f'}}', ]