Skip to content

Commit

Permalink
expand ami module to support ubuntu 20.04 and 22.04
Browse files Browse the repository at this point in the history
  • Loading branch information
gcagle3 committed Oct 2, 2023
1 parent 677094b commit 32a8137
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
44 changes: 44 additions & 0 deletions modules/aws/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-lunar-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.
Expand Down
14 changes: 14 additions & 0 deletions modules/aws/ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 32a8137

Please sign in to comment.