Skip to content

Commit 1d8ec64

Browse files
committed
terraform/aws: Add a script to generate the Kconfig.ami menu
Enable kdevops to quickly pick up new Linux distributions whenever they are introduced by AWS or in the marketplace. 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. To use: $ terraform/aws/scripts/gen_kconfig_ami > terraform/aws/kconfigs/Kconfig.ami Signed-off-by: Chuck Lever <[email protected]>
1 parent 594ac8a commit 1d8ec64

File tree

7 files changed

+801
-1
lines changed

7 files changed

+801
-1
lines changed

playbooks/roles/gen_tfvars/templates/aws/terraform.tfvars.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ aws_region = "{{ terraform_aws_region }}"
33
aws_availability_zone = "{{ terraform_aws_av_zone }}"
44
aws_name_search = "{{ terraform_aws_ns }}"
55
aws_ami_owner = "{{ terraform_aws_ami_owner }}"
6+
aws_ami_arch = "{{ terraform_aws_ami_arch }}"
67
aws_instance_type = "{{ terraform_aws_instance_type }}"
78
aws_ebs_volumes_per_instance = "{{ terraform_aws_ebs_volumes_per_instance }}"
89
aws_ebs_volume_size = {{ terraform_aws_ebs_volume_size }}

terraform/aws/kconfigs/Kconfig.compute

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ config TERRAFORM_AWS_DISTRO_CUSTOM
2626

2727
endchoice
2828

29+
config TERRAFORM_AWS_AMI_ARCH
30+
string
31+
output yaml
32+
default "x86_64" if TARGET_ARCH_X86_64
33+
default "arm64" if TARGET_ARCH_ARM64
34+
2935
source "terraform/aws/kconfigs/distros/Kconfig.amazon"
3036
source "terraform/aws/kconfigs/distros/Kconfig.debian"
3137
source "terraform/aws/kconfigs/distros/Kconfig.fedora"

terraform/aws/main.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
data "aws_ami" "kdevops_ami" {
22
most_recent = true
3+
owners = [var.aws_ami_owner]
4+
5+
filter {
6+
name = "architecture"
7+
values = [var.aws_ami_arch]
8+
}
39
filter {
410
name = "name"
511
values = [var.aws_name_search]
612
}
13+
filter {
14+
name = "state"
15+
values = ["available"]
16+
}
717
filter {
818
name = "virtualization-type"
919
values = ["hvm"]
1020
}
11-
owners = [var.aws_ami_owner]
1221
}
1322

1423
resource "aws_vpc" "kdevops_vpc" {

terraform/aws/scripts/distro.j2

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if TERRAFORM_AWS_DISTRO_{{ owner_name }}
2+
3+
choice
4+
prompt "Release"
5+
help
6+
Choose a specific release from the {{ owner_description }}
7+
distribution.
8+
9+
{% for name, info in discovered %}
10+
config TERRAFORM_AWS_AMI_{{ name.upper().replace(' ', '_').replace('.', '_') }}
11+
bool "{{ name }}"
12+
13+
{% endfor %}
14+
endchoice
15+
16+
config TERRAFORM_AWS_AMI_OWNER
17+
string
18+
output yaml
19+
default "{{ owner_id }}"
20+
21+
config TERRAFORM_AWS_NS
22+
string
23+
output yaml
24+
{% for name, info in discovered %}
25+
default "{{ info['terraform_filter'] }}" if TERRAFORM_AWS_AMI_{{ name.upper().replace(' ', '_').replace('.', '_') }}
26+
{% endfor %}
27+
28+
endif # TERRAFORM_AWS_DISTRO_{{ owner_name }}

0 commit comments

Comments
 (0)