1# This test verifies that the amazon-init service can treat the `user-data` ec2
2# metadata file as a shell script. If amazon-init detects that `user-data` is a
3# script (based on the presence of the shebang #! line) it executes it and
4# exits.
5# Note that other tests verify that amazon-init can treat user-data as a nixos
6# configuration expression.
7
8{ system ? builtins.currentSystem,
9 config ? {},
10 pkgs ? import ../.. { inherit system config; }
11}:
12
13with import ../lib/testing-python.nix { inherit system pkgs; };
14with pkgs.lib;
15
16makeTest {
17 name = "amazon-init";
18 meta = with maintainers; {
19 maintainers = [ urbas ];
20 };
21 nodes.machine = { ... }:
22 {
23 imports = [ ../modules/profiles/headless.nix ../modules/virtualisation/amazon-init.nix ];
24 services.openssh.enable = true;
25 networking.hostName = "";
26 environment.etc."ec2-metadata/user-data" = {
27 text = ''
28 #!/usr/bin/bash
29
30 echo successful > /tmp/evidence
31 '';
32 };
33 };
34 testScript = ''
35 # To wait until amazon-init terminates its run
36 unnamed.wait_for_unit("amazon-init.service")
37
38 unnamed.succeed("grep -q successful /tmp/evidence")
39 '';
40}