Skip to content

Commit 5575d48

Browse files
committed
terraform/aws: Add a script to generate the Kconfig.instance menus
Enable kdevops to quickly pick up new instance families and types whenever they are introduced by AWS. boto3 reuses connections to the API endpoint, making the generation of the Kconfig menu quick. Jinja2 lets us manage a large amount of bespoke Kconfig help text painlessly. The new script reports some basic authentication issues and has a "raw" output to enable troubleshooting. This implementation is still missing information which can be retrieved via the 'pricing' API. To use: $ terraform/aws/scripts/gen_kconfig_instance > terraform/aws/kconfigs/Kconfig.instance Signed-off-by: Chuck Lever <[email protected]>
1 parent c917cf6 commit 5575d48

File tree

3 files changed

+490
-0
lines changed

3 files changed

+490
-0
lines changed

terraform/aws/scripts/families.j2

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
choice
2+
prompt "Instance family"
3+
help
4+
Instance families comprise varying combinations of
5+
hardware platform, CPU count, memory size, storage, and
6+
networking capacity. Select the type that provides an
7+
appropriate mix of resources for your preferred workflows.
8+
9+
Some instance types are region- and capacity-limited.
10+
11+
See https://aws.amazon.com/ec2/instance-types/ for
12+
details.
13+
14+
{% for family in sorted_families %}
15+
config TERRAFORM_AWS_INSTANCE_FAMILY_{{ family['family_name'].upper().replace('-', '_') }}
16+
bool "{{ family['family_name'] }}"
17+
{% if 'x86_64' in family['architectures'] %}
18+
depends on TARGET_ARCH_X86_64
19+
{% endif %}
20+
{% if 'arm64' in family['architectures'] %}
21+
depends on TARGET_ARCH_ARM64
22+
{% endif %}
23+
help
24+
See https://aws.amazon.com/ec2/instance-types/{{ family['family_name'] }}/ for
25+
details.
26+
27+
{% endfor %}
28+
endchoice

terraform/aws/scripts/family.j2

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
if TERRAFORM_AWS_INSTANCE_FAMILY_{{ family_name }}
2+
3+
choice
4+
prompt "Instance type"
5+
default TERRAFORM_AWS_INSTANCE_SIZE_{{ instances[0]['instance_type'].upper().replace('-', '_').replace('.', '_') }}
6+
help
7+
Add storage by increasing the number of EBS volumes per
8+
instance.
9+
10+
{% for instance in instances %}
11+
config TERRAFORM_AWS_INSTANCE_SIZE_{{ instance['instance_type'].upper().replace('-', '_').replace('.', '_') }}
12+
bool "{{ instance['instance_type'] }}"
13+
{% if 'x86_64' in instance['cpu_isa'] %}
14+
depends on TARGET_ARCH_X86_64
15+
{% elif 'arm64' in instance['cpu_isa'] %}
16+
depends on TARGET_ARCH_ARM64
17+
{% endif %}
18+
help
19+
vCPU count: {{ instance['vcpus'] }}
20+
RAM: {{ instance['memory_gb'] }} GiB
21+
Network speed: {{ instance['network_performance'] }}
22+
{% if instance['storage'] != 'EBS-only' %}
23+
Additional storage: {{ instance['storage'] }}
24+
{% endif %}
25+
{% if instance['gpu'] != 'None' %}
26+
GPU: {{ instance['gpu'] }}
27+
{% endif %}
28+
{% if instance['bare_metal'] %}
29+
Bare metal instance.
30+
{% endif %}
31+
{% if instance['free_tier'] %}
32+
Free tier eligible.
33+
{% endif %}
34+
35+
{% endfor %}
36+
endchoice
37+
38+
config TERRAFORM_AWS_INSTANCE_TYPE
39+
string
40+
output yaml
41+
{% for instance in instances %}
42+
default "{{ instance['instance_type'] }}" if TERRAFORM_AWS_INSTANCE_SIZE_{{ instance['instance_type'].upper().replace('-', '_').replace('.', '_') }}
43+
{% endfor %}
44+
45+
endif # TERRAFORM_AWS_INSTANCE_FAMILY_{{ family_name }}

0 commit comments

Comments
 (0)