From ec9d7039f74fbb9bcd40d9e5191e3ebc321b72b2 Mon Sep 17 00:00:00 2001 From: George Date: Mon, 2 Oct 2023 11:30:13 -0500 Subject: [PATCH 1/3] expand ami module to support ubuntu 2004 and 2204 --- modules/aws/ami.go | 44 +++++++++++++++++++++++++++++++++++++++++ modules/aws/ami_test.go | 14 +++++++++++++ 2 files changed, 58 insertions(+) diff --git a/modules/aws/ami.go b/modules/aws/ami.go index 44329339b..8fcc5c7dd 100644 --- a/modules/aws/ami.go +++ b/modules/aws/ami.go @@ -192,6 +192,50 @@ func GetUbuntu1604AmiE(t testing.TestingT, region string) (string, error) { return GetMostRecentAmiIdE(t, region, CanonicalAccountId, filters) } +// GetUbuntu2004Ami gets the ID of the most recent Ubuntu 20.04 HVM x86_64 EBS GP2 AMI in the given region. +func GetUbuntu2004Ami(t testing.TestingT, region string) string { + amiID, err := GetUbuntu2004AmiE(t, region) + if err != nil { + t.Fatal(err) + } + return amiID +} + +// GetUbuntu2004AmiE gets the ID of the most recent Ubuntu 20.04 HVM x86_64 EBS GP2 AMI in the given region. +func GetUbuntu2004AmiE(t testing.TestingT, region string) (string, error) { + filters := map[string][]string{ + "name": {"*ubuntu-focal-20.04-amd64-server-*"}, + "virtualization-type": {"hvm"}, + "architecture": {"x86_64"}, + "root-device-type": {"ebs"}, + "block-device-mapping.volume-type": {"gp2"}, + } + + return GetMostRecentAmiIdE(t, region, CanonicalAccountId, filters) +} + +// GetUbuntu2204Ami gets the ID of the most recent Ubuntu 22.04 HVM x86_64 EBS GP2 AMI in the given region. +func GetUbuntu2204Ami(t testing.TestingT, region string) string { + amiID, err := GetUbuntu2204AmiE(t, region) + if err != nil { + t.Fatal(err) + } + return amiID +} + +// GetUbuntu2204AmiE gets the ID of the most recent Ubuntu 22.04 HVM x86_64 EBS GP2 AMI in the given region. +func GetUbuntu2204AmiE(t testing.TestingT, region string) (string, error) { + filters := map[string][]string{ + "name": {"*ubuntu-jammy-22.04-amd64-server-*"}, + "virtualization-type": {"hvm"}, + "architecture": {"x86_64"}, + "root-device-type": {"ebs"}, + "block-device-mapping.volume-type": {"gp2"}, + } + + return GetMostRecentAmiIdE(t, region, CanonicalAccountId, filters) +} + // GetCentos7Ami returns a CentOS 7 public AMI from the given region. // WARNING: you may have to accept the terms & conditions of this AMI in AWS MarketPlace for your AWS Account before // you can successfully launch the AMI. diff --git a/modules/aws/ami_test.go b/modules/aws/ami_test.go index 6692034bc..95cfb2cfc 100644 --- a/modules/aws/ami_test.go +++ b/modules/aws/ami_test.go @@ -20,6 +20,20 @@ func TestGetUbuntu1604AmiReturnsSomeAmi(t *testing.T) { assert.Regexp(t, "^ami-[[:alnum:]]+$", amiID) } +func TestGetUbuntu2004AmiReturnsSomeAmi(t *testing.T) { + t.Parallel() + + amiID := GetUbuntu2004Ami(t, "us-west-1") + assert.Regexp(t, "^ami-[[:alnum:]]+$", amiID) +} + +func TestGetUbuntu2204AmiReturnsSomeAmi(t *testing.T) { + t.Parallel() + + amiID := GetUbuntu2204Ami(t, "us-west-1") + assert.Regexp(t, "^ami-[[:alnum:]]+$", amiID) +} + func TestGetCentos7AmiReturnsSomeAmi(t *testing.T) { t.Parallel() From d3677e9ea35a5d13dc48957a7ec6a64f36a26234 Mon Sep 17 00:00:00 2001 From: George Date: Mon, 2 Oct 2023 14:59:30 -0500 Subject: [PATCH 2/3] update examples to use ubuntu 22.04 instead of 16.04 --- examples/packer-basic-example/build.pkr.hcl | 6 +++--- examples/terraform-asg-scp-example/main.tf | 2 +- examples/terraform-aws-example/main.tf | 2 +- examples/terraform-http-example/main.tf | 2 +- examples/terraform-remote-exec-example/main.tf | 2 +- examples/terraform-ssh-example/main.tf | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/packer-basic-example/build.pkr.hcl b/examples/packer-basic-example/build.pkr.hcl index a38de4b81..72d14114d 100644 --- a/examples/packer-basic-example/build.pkr.hcl +++ b/examples/packer-basic-example/build.pkr.hcl @@ -51,11 +51,11 @@ variable "oci_subnet_ocid" { default = "" } -data "amazon-ami" "ubuntu-xenial" { +data "amazon-ami" "ubuntu-jammy" { filters = { architecture = "x86_64" "block-device-mapping.volume-type" = "gp2" - name = "*ubuntu-xenial-16.04-amd64-server-*" + name = "*ubuntu-jammy-22.04-amd64-server-*" root-device-type = "ebs" virtualization-type = "hvm" } @@ -70,7 +70,7 @@ source "amazon-ebs" "ubuntu-example" { encrypt_boot = false instance_type = var.instance_type region = var.aws_region - source_ami = data.amazon-ami.ubuntu-xenial.id + source_ami = data.amazon-ami.ubuntu-jammy.id ssh_username = "ubuntu" } diff --git a/examples/terraform-asg-scp-example/main.tf b/examples/terraform-asg-scp-example/main.tf index d665e1e48..e3aa4cab2 100644 --- a/examples/terraform-asg-scp-example/main.tf +++ b/examples/terraform-asg-scp-example/main.tf @@ -94,7 +94,7 @@ data "aws_ami" "ubuntu" { filter { name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } } diff --git a/examples/terraform-aws-example/main.tf b/examples/terraform-aws-example/main.tf index 8e864a622..e660e64fb 100644 --- a/examples/terraform-aws-example/main.tf +++ b/examples/terraform-aws-example/main.tf @@ -49,7 +49,7 @@ data "aws_ami" "ubuntu" { filter { name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } } diff --git a/examples/terraform-http-example/main.tf b/examples/terraform-http-example/main.tf index a0be8cfd0..bf11b92cd 100644 --- a/examples/terraform-http-example/main.tf +++ b/examples/terraform-http-example/main.tf @@ -90,7 +90,7 @@ data "aws_ami" "ubuntu" { filter { name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } } diff --git a/examples/terraform-remote-exec-example/main.tf b/examples/terraform-remote-exec-example/main.tf index 8d221844e..ed0fbfc19 100644 --- a/examples/terraform-remote-exec-example/main.tf +++ b/examples/terraform-remote-exec-example/main.tf @@ -124,7 +124,7 @@ data "aws_ami" "ubuntu" { filter { name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } } diff --git a/examples/terraform-ssh-example/main.tf b/examples/terraform-ssh-example/main.tf index 2ab6a1fd3..63d7c45fc 100644 --- a/examples/terraform-ssh-example/main.tf +++ b/examples/terraform-ssh-example/main.tf @@ -105,7 +105,7 @@ data "aws_ami" "ubuntu" { filter { name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] } } From 5921d6130d2a1fd503b273a904e82ca26ac5fcdd Mon Sep 17 00:00:00 2001 From: George Date: Mon, 2 Oct 2023 16:10:21 -0500 Subject: [PATCH 3/3] test with ubuntu 20.04 --- examples/terraform-remote-exec-example/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/terraform-remote-exec-example/main.tf b/examples/terraform-remote-exec-example/main.tf index ed0fbfc19..2d6a1df96 100644 --- a/examples/terraform-remote-exec-example/main.tf +++ b/examples/terraform-remote-exec-example/main.tf @@ -124,7 +124,7 @@ data "aws_ami" "ubuntu" { filter { name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] + values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } }