Skip to content

Commit 21e23bb

Browse files
authored
Merge pull request #1350 from gruntwork-io/feature/ami-support-for-ubuntu-2004-2204
expand ami module to support ubuntu 20.04 and 22.04
2 parents 677094b + 5921d61 commit 21e23bb

File tree

8 files changed

+66
-8
lines changed

8 files changed

+66
-8
lines changed

examples/packer-basic-example/build.pkr.hcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ variable "oci_subnet_ocid" {
5151
default = ""
5252
}
5353

54-
data "amazon-ami" "ubuntu-xenial" {
54+
data "amazon-ami" "ubuntu-jammy" {
5555
filters = {
5656
architecture = "x86_64"
5757
"block-device-mapping.volume-type" = "gp2"
58-
name = "*ubuntu-xenial-16.04-amd64-server-*"
58+
name = "*ubuntu-jammy-22.04-amd64-server-*"
5959
root-device-type = "ebs"
6060
virtualization-type = "hvm"
6161
}
@@ -70,7 +70,7 @@ source "amazon-ebs" "ubuntu-example" {
7070
encrypt_boot = false
7171
instance_type = var.instance_type
7272
region = var.aws_region
73-
source_ami = data.amazon-ami.ubuntu-xenial.id
73+
source_ami = data.amazon-ami.ubuntu-jammy.id
7474
ssh_username = "ubuntu"
7575
}
7676

examples/terraform-asg-scp-example/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ data "aws_ami" "ubuntu" {
9494

9595
filter {
9696
name = "name"
97-
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
97+
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
9898
}
9999
}
100100

examples/terraform-aws-example/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data "aws_ami" "ubuntu" {
4949

5050
filter {
5151
name = "name"
52-
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
52+
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
5353
}
5454
}
5555

examples/terraform-http-example/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ data "aws_ami" "ubuntu" {
9090

9191
filter {
9292
name = "name"
93-
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
93+
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
9494
}
9595
}
9696

examples/terraform-remote-exec-example/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ data "aws_ami" "ubuntu" {
124124

125125
filter {
126126
name = "name"
127-
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
127+
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
128128
}
129129
}
130130

examples/terraform-ssh-example/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ data "aws_ami" "ubuntu" {
105105

106106
filter {
107107
name = "name"
108-
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
108+
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
109109
}
110110
}
111111

modules/aws/ami.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,50 @@ func GetUbuntu1604AmiE(t testing.TestingT, region string) (string, error) {
192192
return GetMostRecentAmiIdE(t, region, CanonicalAccountId, filters)
193193
}
194194

195+
// GetUbuntu2004Ami gets the ID of the most recent Ubuntu 20.04 HVM x86_64 EBS GP2 AMI in the given region.
196+
func GetUbuntu2004Ami(t testing.TestingT, region string) string {
197+
amiID, err := GetUbuntu2004AmiE(t, region)
198+
if err != nil {
199+
t.Fatal(err)
200+
}
201+
return amiID
202+
}
203+
204+
// GetUbuntu2004AmiE gets the ID of the most recent Ubuntu 20.04 HVM x86_64 EBS GP2 AMI in the given region.
205+
func GetUbuntu2004AmiE(t testing.TestingT, region string) (string, error) {
206+
filters := map[string][]string{
207+
"name": {"*ubuntu-focal-20.04-amd64-server-*"},
208+
"virtualization-type": {"hvm"},
209+
"architecture": {"x86_64"},
210+
"root-device-type": {"ebs"},
211+
"block-device-mapping.volume-type": {"gp2"},
212+
}
213+
214+
return GetMostRecentAmiIdE(t, region, CanonicalAccountId, filters)
215+
}
216+
217+
// GetUbuntu2204Ami gets the ID of the most recent Ubuntu 22.04 HVM x86_64 EBS GP2 AMI in the given region.
218+
func GetUbuntu2204Ami(t testing.TestingT, region string) string {
219+
amiID, err := GetUbuntu2204AmiE(t, region)
220+
if err != nil {
221+
t.Fatal(err)
222+
}
223+
return amiID
224+
}
225+
226+
// GetUbuntu2204AmiE gets the ID of the most recent Ubuntu 22.04 HVM x86_64 EBS GP2 AMI in the given region.
227+
func GetUbuntu2204AmiE(t testing.TestingT, region string) (string, error) {
228+
filters := map[string][]string{
229+
"name": {"*ubuntu-jammy-22.04-amd64-server-*"},
230+
"virtualization-type": {"hvm"},
231+
"architecture": {"x86_64"},
232+
"root-device-type": {"ebs"},
233+
"block-device-mapping.volume-type": {"gp2"},
234+
}
235+
236+
return GetMostRecentAmiIdE(t, region, CanonicalAccountId, filters)
237+
}
238+
195239
// GetCentos7Ami returns a CentOS 7 public AMI from the given region.
196240
// WARNING: you may have to accept the terms & conditions of this AMI in AWS MarketPlace for your AWS Account before
197241
// you can successfully launch the AMI.

modules/aws/ami_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ func TestGetUbuntu1604AmiReturnsSomeAmi(t *testing.T) {
2020
assert.Regexp(t, "^ami-[[:alnum:]]+$", amiID)
2121
}
2222

23+
func TestGetUbuntu2004AmiReturnsSomeAmi(t *testing.T) {
24+
t.Parallel()
25+
26+
amiID := GetUbuntu2004Ami(t, "us-west-1")
27+
assert.Regexp(t, "^ami-[[:alnum:]]+$", amiID)
28+
}
29+
30+
func TestGetUbuntu2204AmiReturnsSomeAmi(t *testing.T) {
31+
t.Parallel()
32+
33+
amiID := GetUbuntu2204Ami(t, "us-west-1")
34+
assert.Regexp(t, "^ami-[[:alnum:]]+$", amiID)
35+
}
36+
2337
func TestGetCentos7AmiReturnsSomeAmi(t *testing.T) {
2438
t.Parallel()
2539

0 commit comments

Comments
 (0)