Skip to content

Commit 301c2c0

Browse files
committed
terraform/AWS: Re-organize the selection of OS images
The point of this exercise is to make it easier for newbies to select the Linux distribution of their choice, without having to learn the ins & outs of how Amazon publishes the images, but also make it easier for kdevops developers to add new choices to the menu. Signed-off-by: Chuck Lever <[email protected]>
1 parent 50dd75e commit 301c2c0

File tree

9 files changed

+302
-159
lines changed

9 files changed

+302
-159
lines changed

scripts/terraform.Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ KDEVOPS_MRPROPER += $(KDEVOPS_NODES)
4848
DEFAULT_DEPS_REQS_EXTRA_VARS += $(KDEVOPS_TFVARS)
4949

5050
ifeq (y,$(CONFIG_TERRAFORM_AWS))
51-
TERRAFORM_EXTRA_VARS += terraform_aws_ami_owner=$(subst ",,$(CONFIG_TERRAFORM_AWS_AMI_OWNER))
52-
TERRAFORM_EXTRA_VARS += terraform_aws_ns='$(CONFIG_TERRAFORM_AWS_NS)'
53-
5451
ifeq (y,$(CONFIG_TERRAFORM_AWS_ENABLE_EBS_VOLUMES))
5552
TERRAFORM_EXTRA_VARS += terraform_aws_enable_ebs='True'
5653
TERRAFORM_EXTRA_VARS += terraform_aws_ebs_num_volumes_per_instance=$(subst ",,$(CONFIG_TERRAFORM_AWS_EBS_NUM_VOLUMES_PER_INSTANCE))

terraform/aws/kconfigs/Kconfig.compute

Lines changed: 23 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -83,168 +83,36 @@ source "terraform/aws/kconfigs/instance-types/Kconfig.im4gn"
8383
source "terraform/aws/kconfigs/instance-types/Kconfig.c7a"
8484

8585
choice
86-
prompt "AWS AMI owner"
87-
default TERRAFORM_AWS_AMI_DEBIAN if DISTRO_DEBIAN
88-
default TERRAFORM_AWS_AMI_AMAZON_X86_64 if TARGET_ARCH_X86_64
89-
default TERRAFORM_AWS_AMI_AMAZON_ARM64 if TARGET_ARCH_ARM64
90-
91-
config TERRAFORM_AWS_AMI_DEBIAN
92-
bool "Debian"
93-
help
94-
This option will set AWS AMI owner to Debian.
95-
96-
config TERRAFORM_AWS_AMI_AMAZON_X86_64
97-
bool "Amazon Linux 2023 x86_64 - ami-0efa651876de2a5ce"
98-
depends on TARGET_ARCH_X86_64 && TERRAFORM_AWS_US_WEST_2
99-
help
100-
This option will set AWS AMI owner to Amazon EC2 images for x86_64.
101-
102-
config TERRAFORM_AWS_AMI_AMAZON_ARM64
103-
bool "Amazon Linux 2023 ARM64 - ami-0699f753302dd8b00"
104-
depends on TARGET_ARCH_ARM64 && TERRAFORM_AWS_US_WEST_2
105-
help
106-
This option will set AWS AMI owner to Amazon EC2 images for arm64.
107-
108-
config TERRAFORM_AWS_FEDORA40_X86_64
109-
bool "Fedora 40 on x86_64"
110-
depends on TARGET_ARCH_X86_64
86+
prompt "Linux distribution"
87+
default TERRAFORM_AWS_DISTRO_DEBIAN
11188
help
112-
This option sets the AWS AMI owner to Fedora 40 for x86_64.
89+
Select a popular Linux distribution to install on your
90+
instances, or use the "Custom AMI image" selection to
91+
choose an image that is off the beaten path.
11392

114-
config TERRAFORM_AWS_FEDORA40_ARM64
115-
bool "Fedora 40 on aarch64"
116-
depends on TARGET_ARCH_ARM64
117-
help
118-
This option sets the AWS AMI owner to Fedora 40 for ARM 64-bit.
119-
120-
config TERRAFORM_AWS_FEDORA41_X86_64
121-
bool "Fedora 41 on x86_64"
122-
depends on TARGET_ARCH_X86_64
123-
help
124-
This option sets the AWS AMI owner to Fedora 41 for x86_64.
125-
126-
config TERRAFORM_AWS_FEDORA41_ARM64
127-
bool "Fedora 41 on aarch64"
128-
depends on TARGET_ARCH_ARM64
129-
help
130-
This option sets the AWS AMI owner to Fedora 41 for ARM 64-bit.
131-
132-
config TERRAFORM_AWS_RHEL9_X86_64
133-
bool "RHEL9 x86_64"
134-
depends on TARGET_ARCH_X86_64
135-
help
136-
This option will set AWS AMI owner to RHEL9 for x86_64.
137-
138-
config TERRAFORM_AWS_RHEL9_ARM64
139-
bool "RHEL9 ARM 64"
140-
depends on TARGET_ARCH_ARM64
141-
help
142-
This option will set AWS AMI owner to RHEL9 for ARM64
143-
144-
config TERRAFORM_AWS_SLE15_SP4_X86_64
145-
bool "SUSE Linux Enterprise Server 15 SP4 x86_64 - ami-079ba66a5e9f2b70e"
146-
depends on TARGET_ARCH_X86_64 && TERRAFORM_AWS_US_WEST_2
147-
help
148-
This option will set AWS AMI owner to SLE15-SP4 for x86_64.
149-
150-
config TERRAFORM_AWS_SLE15_SP4_ARM64
151-
bool "SUSE Linux Enterprise Server 15 SP4 ARM64 - ami-00f902c807805f51a"
152-
depends on TARGET_ARCH_ARM64 && TERRAFORM_AWS_US_WEST_2
153-
help
154-
This option will set AWS AMI owner to SLE15-SP4 for arm64.
93+
config TERRAFORM_AWS_DISTRO_AMAZON
94+
bool "Amazon Linux"
15595

156-
endchoice
157-
158-
if TERRAFORM_AWS_AMI_DEBIAN
159-
160-
choice
161-
prompt "AWS debian release to use"
162-
default TERRAFORM_AWS_NS_DEBIAN_12_X86_64 if TARGET_ARCH_X86_64
163-
default TERRAFORM_AWS_NS_DEBIAN_12_ARM64 if TARGET_ARCH_ARM64
164-
165-
config TERRAFORM_AWS_NS_DEBIAN_12_X86_64
166-
bool "Debian 12 - Bookworm x86_64"
167-
depends on TARGET_ARCH_X86_64
168-
help
169-
This option will set aws name search to debian-12-hvm-amd64-*
170-
Note, to expand on this get the AMI owner ID and then you can
171-
see what is available with something like this:
172-
173-
aws ec2 describe-images --owners 136693071363 --query 'Images[*].[Description]'
96+
config TERRAFORM_AWS_DISTRO_DEBIAN
97+
bool "Debian"
17498

175-
In theory we should be able to just automate Kconfig language then
176-
for AWS for a distro using 'make dynconfig' on kdevops.
99+
config TERRAFORM_AWS_DISTRO_FEDORA
100+
bool "Fedora Core"
177101

178-
config TERRAFORM_AWS_NS_DEBIAN_12_ARM64
179-
bool "Debian 12 - Bookworm ARM64"
180-
depends on TARGET_ARCH_ARM64
181-
help
182-
This option will set aws name search to debian-12-hvm-arm64-*
102+
config TERRAFORM_AWS_DISTRO_RHEL
103+
bool "Red Hat Enterprise Linux"
183104

184-
config TERRAFORM_AWS_NS_DEBIAN_11_X86_64
185-
bool "Debian 11 - Bullseye x86_64"
186-
depends on TARGET_ARCH_X86_64
187-
help
188-
This option will set aws name search to debian-11-hvm-amd64-*
105+
config TERRAFORM_AWS_DISTRO_SLES
106+
bool "Suse Linux Enterprise Server"
189107

190-
config TERRAFORM_AWS_NS_DEBIAN_11_ARM64
191-
bool "Debian 11 - Bullseye arm64"
192-
depends on TARGET_ARCH_ARM64
193-
help
194-
This option will set aws name search to debian-11-hvm-arm64-*
108+
config TERRAFORM_AWS_DISTRO_CUSTOM
109+
bool "Custom AMI image"
195110

196111
endchoice
197112

198-
endif
199-
200-
config TERRAFORM_AWS_AMI_OWNER
201-
string
202-
default "136693071363" if TERRAFORM_AWS_NS_DEBIAN_11_X86_64 || TERRAFORM_AWS_NS_DEBIAN_11_ARM64
203-
default "136693071363" if TERRAFORM_AWS_NS_DEBIAN_12_X86_64 || TERRAFORM_AWS_NS_DEBIAN_12_ARM64
204-
default "137112412989" if TERRAFORM_AWS_AMI_AMAZON_X86_64 || TERRAFORM_AWS_AMI_AMAZON_ARM64
205-
default "309956199498" if TERRAFORM_AWS_RHEL9_X86_64 || TERRAFORM_AWS_RHEL9_ARM64
206-
default "013907871322" if TERRAFORM_AWS_SLE15_SP4_X86_64 || TERRAFORM_AWS_SLE15_SP4_ARM64
207-
default "125523088429" if TERRAFORM_AWS_FEDORA40_X86_64 || TERRAFORM_AWS_FEDORA40_ARM64
208-
default "125523088429" if TERRAFORM_AWS_FEDORA41_X86_64 || TERRAFORM_AWS_FEDORA41_ARM64
209-
210-
config TERRAFORM_AWS_NS
211-
string
212-
default "debian-12-amd64-*" if TERRAFORM_AWS_NS_DEBIAN_12_X86_64
213-
default "debian-12-arm64-*" if TERRAFORM_AWS_NS_DEBIAN_12_ARM64
214-
default "debian-11-amd64-*" if TERRAFORM_AWS_NS_DEBIAN_11_X86_64
215-
default "debian-11-arm64-*" if TERRAFORM_AWS_NS_DEBIAN_11_ARM64
216-
default "al2023-*-x86_64" if TARGET_ARCH_X86_64 && TERRAFORM_AWS_AMI_AMAZON_X86_64
217-
default "al2023-*-arm64" if TARGET_ARCH_ARM64 && TERRAFORM_AWS_AMI_AMAZON_ARM64
218-
default "RHEL-9.*x86_64-*" if TERRAFORM_AWS_RHEL9_X86_64
219-
default "RHEL-9.*arm64-*" if TERRAFORM_AWS_RHEL9_ARM64
220-
default "Fedora-Cloud-Base-AmazonEC2.x86_64-40-*" if TERRAFORM_AWS_FEDORA40_X86_64
221-
default "Fedora-Cloud-Base-AmazonEC2.aarch64-40-*" if TERRAFORM_AWS_FEDORA40_ARM64
222-
default "Fedora-Cloud-Base-AmazonEC2.x86_64-41-*" if TERRAFORM_AWS_FEDORA41_X86_64
223-
default "Fedora-Cloud-Base-AmazonEC2.aarch64-41-*" if TERRAFORM_AWS_FEDORA41_ARM64
224-
default "suse-sles-15-sp4-*x86_64" if TARGET_ARCH_X86_64 && TERRAFORM_AWS_SLE15_SP4_X86_64
225-
default "suse-sles-15-sp4-*arm64" if TARGET_ARCH_ARM64 && TERRAFORM_AWS_SLE15_SP4_ARM64
226-
help
227-
This option will set aws image search to use. Using this filter glob
228-
lets us get the latest ami for this owner / release.
229-
230-
For debian updates you can use this list for AMI updates:
231-
232-
https://wiki.debian.org/Cloud/AmazonEC2Image/Stretch
233-
234-
If you want to expand on this list or just use a value yourself here
235-
read:
236-
237-
https://letslearndevops.com/2018/08/23/terraform-get-latest-centos-ami/
238-
239-
To get filter values you can first setup aws cli:
240-
241-
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration
242-
243-
Get your image ami id, for debian 9 amd64 on the us-west1 this is
244-
ami-0adbaf2e0ce044437 so you can run:
245-
246-
aws ec2 describe-images --image-ids ami-0adbaf2e0ce044437 | grep Name
247-
248-
For details:
249-
250-
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html
113+
source "terraform/aws/kconfigs/distros/Kconfig.amazon"
114+
source "terraform/aws/kconfigs/distros/Kconfig.debian"
115+
source "terraform/aws/kconfigs/distros/Kconfig.fedora"
116+
source "terraform/aws/kconfigs/distros/Kconfig.rhel"
117+
source "terraform/aws/kconfigs/distros/Kconfig.sles"
118+
source "terraform/aws/kconfigs/distros/Kconfig.custom"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
if TERRAFORM_AWS_DISTRO_AMAZON
2+
3+
config TERRAFORM_AWS_AMI_OWNER
4+
string
5+
output yaml
6+
default "amazon"
7+
8+
if TARGET_ARCH_X86_64
9+
10+
choice
11+
prompt "Amazon Linux release"
12+
default TERRAFORM_AWS_AMI_AMAZON_X86_64
13+
14+
config TERRAFORM_AWS_AMI_AMAZON_X86_64
15+
bool "Amazon Linux 2023 (x86)"
16+
17+
endchoice
18+
19+
config TERRAFORM_AWS_NS
20+
string
21+
output yaml
22+
default "al2023-*-x86_64" if TERRAFORM_AWS_AMI_AMAZON_X86_64
23+
24+
endif # TARGET_ARCH_X86_64
25+
26+
if TARGET_ARCH_ARM64
27+
28+
choice
29+
prompt "Amazon Linux release"
30+
default TERRAFORM_AWS_AMI_AMAZON_ARM64
31+
32+
config TERRAFORM_AWS_AMI_AMAZON_ARM64
33+
bool "Amazon Linux 2023 (arm64)"
34+
35+
endchoice
36+
37+
config TERRAFORM_AWS_NS
38+
string
39+
output yaml
40+
default "al2023-*-arm64" if TERRAFORM_AWS_AMI_AMAZON_ARM64
41+
42+
endif # TARGET_ARCH_ARM64
43+
44+
endif # TERRAFORM_AWS_DISTRO_AMAZON
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
if TERRAFORM_AWS_DISTRO_CUSTOM
2+
3+
config TERRAFORM_AWS_AMI_OWNER
4+
string "AWS AMI owner or owner alias"
5+
output yaml
6+
default "amazon"
7+
help
8+
The owner is a string of digits that represents a
9+
collection of published images to search, such as
10+
"137112412989". Sometimes the publisher also provides
11+
an alias, which is a human-readable name of that
12+
collection, such as "aws-marketplace".
13+
14+
config TERRAFORM_AWS_NS
15+
string "AWS AMI name search expression"
16+
output yaml
17+
help
18+
This option sets a custom aws image search expression to
19+
use. Using this filter glob lets us get the latest AMI for
20+
your preferred OS release.
21+
22+
To get filter values you can first setup aws cli:
23+
24+
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration
25+
26+
Get your image ami id, for debian 9 amd64 on the us-west1 this is
27+
ami-0adbaf2e0ce044437 so you can run:
28+
29+
aws ec2 describe-images --image-ids ami-0adbaf2e0ce044437 | grep Name
30+
31+
For details:
32+
33+
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html
34+
35+
endif # TERRAFORM_AWS_DISTRO_CUSTOM
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
if TERRAFORM_AWS_DISTRO_DEBIAN
2+
3+
config TERRAFORM_AWS_AMI_OWNER
4+
string
5+
output yaml
6+
default "amazon"
7+
8+
if TARGET_ARCH_X86_64
9+
10+
choice
11+
prompt "Debian Linux release"
12+
default TERRAFORM_AWS_NS_DEBIAN_12_X86_64
13+
14+
config TERRAFORM_AWS_NS_DEBIAN_11_X86_64
15+
bool "Debian 11 Bullseye (x86)"
16+
17+
config TERRAFORM_AWS_NS_DEBIAN_12_X86_64
18+
bool "Debian 12 Bookworm (x86)"
19+
20+
endchoice
21+
22+
config TERRAFORM_AWS_NS
23+
string
24+
output yaml
25+
default "debian-11-amd64-*" if TERRAFORM_AWS_NS_DEBIAN_11_X86_64
26+
default "debian-12-amd64-*" if TERRAFORM_AWS_NS_DEBIAN_12_X86_64
27+
28+
endif # TARGET_ARCH_X86_64
29+
30+
if TARGET_ARCH_ARM64
31+
32+
choice
33+
prompt "Debian Linux release"
34+
default TERRAFORM_AWS_NS_DEBIAN_12_ARM64
35+
36+
config TERRAFORM_AWS_NS_DEBIAN_11_ARM64
37+
bool "Debian 11 Bullseye (arm64)"
38+
39+
config TERRAFORM_AWS_NS_DEBIAN_12_ARM64
40+
bool "Debian 12 Bookworm (arm64)"
41+
42+
endchoice
43+
44+
config TERRAFORM_AWS_NS
45+
string
46+
default "debian-11-arm64-*" if TERRAFORM_AWS_NS_DEBIAN_11_ARM64
47+
default "debian-12-arm64-*" if TERRAFORM_AWS_NS_DEBIAN_12_ARM64
48+
49+
endif # TARGET_ARCH_ARM64
50+
51+
endif # TERRAFORM_AWS_DISTRO_DEBIAN
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
if TERRAFORM_AWS_DISTRO_FEDORA
2+
3+
config TERRAFORM_AWS_AMI_OWNER
4+
string
5+
output yaml
6+
default "125523088429" # Community Platform Engineering
7+
8+
if TARGET_ARCH_X86_64
9+
10+
choice
11+
prompt "Fedora Core release"
12+
default TERRAFORM_AWS_FEDORA40_X86_64
13+
14+
config TERRAFORM_AWS_FEDORA40_X86_64
15+
bool "Fedora 40 (x86_64)"
16+
17+
config TERRAFORM_AWS_FEDORA41_X86_64
18+
bool "Fedora 41 (x86_64)"
19+
20+
endchoice
21+
22+
config TERRAFORM_AWS_NS
23+
string
24+
output yaml
25+
default "Fedora-Cloud-Base-AmazonEC2.x86_64-40-*" if TERRAFORM_AWS_FEDORA40_X86_64
26+
default "Fedora-Cloud-Base-AmazonEC2.x86_64-41-*" if TERRAFORM_AWS_FEDORA41_X86_64
27+
28+
endif # TARGET_ARCH_X86_64
29+
30+
if TARGET_ARCH_ARM64
31+
32+
choice
33+
prompt "Fedora Core release"
34+
default TERRAFORM_AWS_FEDORA40_ARM64
35+
36+
config TERRAFORM_AWS_FEDORA40_ARM64
37+
bool "Fedora 40 (arm64)"
38+
39+
config TERRAFORM_AWS_FEDORA41_ARM64
40+
bool "Fedora 41 (arm64"
41+
42+
endchoice
43+
44+
config TERRAFORM_AWS_NS
45+
string
46+
output yaml
47+
default "Fedora-Cloud-Base-AmazonEC2.aarch64-40-*" if TERRAFORM_AWS_FEDORA40_ARM64
48+
default "Fedora-Cloud-Base-AmazonEC2.aarch64-41-*" if TERRAFORM_AWS_FEDORA41_ARM64
49+
50+
endif # TARGET_ARCH_ARM64
51+
52+
endif # TERRAFORM_AWS_DISTRO_FEDORA

0 commit comments

Comments
 (0)