git: bdd892341813 - releng/14.0 - EC2: Add experimental cloud-init images

From: Colin Percival <cperciva_at_FreeBSD.org>
Date: Thu, 05 Oct 2023 15:54:36 UTC
The branch releng/14.0 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=bdd89234181337347ea6a81677875fc676325380

commit bdd89234181337347ea6a81677875fc676325380
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2023-09-09 00:55:16 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2023-10-05 15:54:04 +0000

    EC2: Add experimental cloud-init images
    
    Known issues:
    
    1. The ec2-user user is created with a homedir of /usr/home/ec2-user
    instead of /home/ec2-user; this appears to be a bug in cloud-init's
    FreeBSD support.
    
    2. Cloud-init configures IPv4 networking but not IPv6 networking.
    
    Approved by:    re (gjb)
    Relnotes:       yes
    Sponsored by:   https://www.patreon.com/cperciva
    Differential Revision:  https://reviews.freebsd.org/D41793
    
    (cherry picked from commit 1f4ce7a39f0f4b0621ff55d228014ccddb366d37)
    (cherry picked from commit d9243c1ab3cd8e744aaf54177232cdbffa07392d)
---
 release/Makefile.vm               |  5 +++--
 release/tools/ec2-cloud-init.conf | 31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/release/Makefile.vm b/release/Makefile.vm
index 8828b99599e7..09e31e3c0b6f 100644
--- a/release/Makefile.vm
+++ b/release/Makefile.vm
@@ -30,8 +30,9 @@ BASIC-CI_FSLIST=	ufs
 BASIC-CI_DESC=		Image for CI
 EC2_FORMAT=	raw
 EC2_FSLIST=	ufs zfs
-EC2_DESC=	Amazon EC2 image
-EC2_FLAVOURS=	BASE
+EC2_FLAVOURS=	BASE CLOUD-INIT
+EC2-BASE_DESC=	Amazon EC2 image
+EC2-CLOUD-INIT_DESC=	Amazon EC2 Cloud-Init image
 GCE_FORMAT=	raw
 GCE_FSLIST=	ufs
 GCE_DESC=	Google Compute Engine image
diff --git a/release/tools/ec2-cloud-init.conf b/release/tools/ec2-cloud-init.conf
new file mode 100644
index 000000000000..2dd4df390fa3
--- /dev/null
+++ b/release/tools/ec2-cloud-init.conf
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+. ${WORLDDIR}/release/tools/ec2.conf
+
+# Packages to install into the image we're creating.  In addition to packages
+# present on all EC2 AMIs, we install cloud-init.
+export VM_EXTRA_PACKAGES="${VM_EXTRA_PACKAGES} net/cloud-init"
+
+# Services to enable in rc.conf(5).
+export VM_RC_LIST="${VM_RC_LIST} cloudinit sshd"
+
+vm_extra_pre_umount() {
+	# Configuration common to all EC2 AMIs
+	ec2_common
+
+	# Configure cloud-init
+	cat <<-'EOF' > ${DESTDIR}/usr/local/etc/cloud/cloud.cfg.d/98_ec2.cfg
+		disable_root: true
+		system_info:
+		  distro: freebsd
+		  default_user:
+		    name: ec2-user
+		    lock_passwd: True
+		    groups: [wheel]
+		    shell: /bin/sh
+		    # Currently broken, cloud-init hard-codes to /usr/home/*
+		    homedir: /home/ec2-user
+	EOF
+
+	return 0
+}