Skip to content

Commit

Permalink
Revert "Unpin Ubuntu Focal version by default"
Browse files Browse the repository at this point in the history
This reverts commit b5a272e.

The DescribeRequest via Java SDK the filter didn't work like "contains", but as "equals".
Weird, because via GUI it always works like "contains". And on HTTP level the requests look almost identical (hostname is different).
Anyway, we're back to a pinned (and bumped) version.
  • Loading branch information
dagguh committed Jun 10, 2024
1 parent f7f476d commit 3cc15bb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Dropping a requirement of a major version of a dependency is a new contract.
- Add `CanonicalAmiProvider.Builder.avoidUnattendedUpgrades` for bumping `imageName` to Focal or higher.

### Fixed
- Unpin Ubuntu Focal version in `CanonicalAmiProvider.Builder` by default.
You can still pin a specific release date, e.g. `imageName("ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20240531")`
- Bump Ubuntu Focal AMI to `ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20240531`.
The previous one was 2 years old and disappeared: `ubuntu-focal-20.04-amd64-server-20220610`.

## [1.15.0] - 2024-01-23
[1.15.0]: https://github.com/atlassian-labs/aws-resources/compare/release-1.14.0...release-1.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ class CanonicalImageIdByNameResolver private constructor(
)
)
.images
.sortedByDescending { it.creationDate }
.map { it.imageId }
.firstOrNull()
?: throw Exception("Failed to find image containing $imageName in $region")
.let {
when {
it.isEmpty() -> throw Exception("Failed to find image $imageName in $region")
it.size > 1 -> throw Exception("More than one image found with name $imageName in declared region $region. Selecting any of them automatically could create a security risk, so we can't proceed")
else -> it.first()
}
}

class Builder(
private val ec2: AmazonEC2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CanonicalAmiProvider private constructor(
}

class Builder {
private val focal = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server"
private val focal = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20240531"
private var imageName = focal

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,27 @@ class CanonicalImageIdByNameResolverTest {
}

@Test
fun picksTheNewestImage() {
fun failsWhenMoreThanOneImageIsFound() {
val queriedImageName = "name-of-single-image"
val ec2 = object : AmazonEC2 by FakeEc2() {
override fun describeImages(
describeImagesRequest: DescribeImagesRequest?
) = DescribeImagesResult()
.withImages(
Image().withImageId("id-of-image-1").withCreationDate("2022-07-07T00:49:01.000Z"),
Image().withImageId("id-of-image-2").withCreationDate("2024-03-21T22:43:23.000Z"),
Image().withImageId("id-of-image-3").withCreationDate("2023-03-01T23:16:36.000Z")
Image().withImageId("id-of-image-1"),
Image().withImageId("id-of-image-2")
)
}
val resolver = CanonicalImageIdByNameResolver.Builder(ec2)
.build()

val result = resolver.invoke(queriedImageName)
val result = try {
resolver.invoke(queriedImageName)
null
} catch (e: Exception) {
e
}

assertThat(result).isEqualTo("id-of-image-2")
assertThat(result).isNotNull()
}
}

0 comments on commit 3cc15bb

Please sign in to comment.