Skip to content

Commit 151e06a

Browse files
Add AMI IDs for ubuntu 22 (#12)
Signed-off-by: AbdullahAlShaad <abdullah.alshaad@appscode.com>
1 parent 22e6fc2 commit 151e06a

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

pkg/controller/aws_region.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controller
18+
19+
// This list generated using scripts/ami.sh file and
20+
// https://cloud-images.ubuntu.com/locator/ec2/
21+
var amiIDs = map[string]string{
22+
"ap-south-1": "ami-0fc76d1fc60a822e2",
23+
"eu-north-1": "ami-09619f1544394c186",
24+
"eu-west-3": "ami-0e7bc13af71a7ace1",
25+
"eu-west-2": "ami-0ef73863dbddaa97f",
26+
"eu-west-1": "ami-07e2abe41a3dd4483",
27+
"ap-northeast-3": "ami-06c6d2fb039aedeb2",
28+
"ap-northeast-2": "ami-0e73d7a01dba794a4",
29+
"ap-northeast-1": "ami-07ac8e5b1fefaa9e5",
30+
"ca-central-1": "ami-0cd354c076a038948",
31+
"sa-east-1": "ami-07f5d4171b892af81",
32+
"ap-southeast-1": "ami-09329fa58ea564a19",
33+
"ap-southeast-2": "ami-0266d373beca3c7fa",
34+
"eu-central-1": "ami-0b6226e8488760b25",
35+
"us-east-1": "ami-0111190769c4329ae",
36+
"us-east-2": "ami-0b00f5183519c196c",
37+
"us-west-1": "ami-0b1da0df74f3b4b0b",
38+
"us-west-2": "ami-03ab9db8dada95e36",
39+
"me-central-1": "ami-0170c48a53a986edc",
40+
"eu-south-1": "ami-0494d18a3b83a9b91",
41+
"il-central-1": "ami-079087d4fb0b82225",
42+
"af-south-1": "ami-01015442638eed255",
43+
"cn-northwest-1": "ami-00978db6a05d06273",
44+
"cn-north-1": "ami-0b820a65426833e1f",
45+
"ap-east-1": "ami-06aacaba45deda8f5",
46+
"ca-west-1": "ami-0989e7880da01e922",
47+
"me-south-1": "ami-004a63c72a7208abc",
48+
"eu-south-2": "ami-0de5f498466655517",
49+
"eu-central-2": "ami-0868b61eaac7c1688",
50+
"ap-south-2": "ami-09fd1f9e60e374015",
51+
"ap-southeast-3": "ami-002fde9f4f8bf8faf",
52+
"ap-southeast-4": "ami-010a2c002f5940231",
53+
}
54+
55+
func (r *MachineReconciler) getAMIIDArg() []string {
56+
args := []string{}
57+
region := r.machineObj.Spec.Parameters[awsRegionField]
58+
if amiIDs[region] != "" {
59+
args = append(args, "--amazonec2-ami", amiIDs[region])
60+
}
61+
62+
return args
63+
}

pkg/controller/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (r *MachineReconciler) getMachineCreationArgs() ([]string, error) {
114114
}
115115
cutil.MarkTrue(r.machineObj, api.MachineConditionTypeAuthDataReady)
116116
args = append(args, authArgs...)
117-
117+
args = append(args, r.getAMIIDArg()...)
118118
args = append(args, r.getAnnotationsArgsForAWS()...)
119119
args = append(args, r.machineObj.Name)
120120

pkg/script/ami.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Copyright AppsCode Inc. and Contributors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
19+
regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output json | jq -r '.[]')
20+
21+
for region in $regions; do
22+
ami_id=$(aws ec2 describe-images \
23+
--owners "099720109477" \
24+
--filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" \
25+
--query "Images | sort_by(@, &CreationDate) | [-1].[ImageId]" \
26+
--output text \
27+
--region "$region")
28+
echo "\"$region\": \"$ami_id\","
29+
done

0 commit comments

Comments
 (0)