Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand ami module to support ubuntu 20.04 and 22.04 #1350

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/packer-basic-example/build.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform-asg-scp-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/terraform-aws-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"]
}
}

2 changes: 1 addition & 1 deletion examples/terraform-http-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"]
}
}

2 changes: 1 addition & 1 deletion examples/terraform-remote-exec-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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-focal-20.04-amd64-server-*"]
}
}

2 changes: 1 addition & 1 deletion examples/terraform-ssh-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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-*"]
}
}

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-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.
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