at master 3.0 kB view raw
1{ pkgs, ... }: 2let 3 # See https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html. 4 iniFormat = pkgs.formats.ini { }; 5 6 region = "ap-northeast-1"; 7 sharedConfigurationDefaultProfile = "default"; 8 sharedConfigurationFile = iniFormat.generate "config" { 9 "${sharedConfigurationDefaultProfile}" = { 10 region = region; 11 }; 12 }; 13 sharedCredentialsFile = iniFormat.generate "credentials" { 14 "${sharedConfigurationDefaultProfile}" = { 15 aws_access_key_id = "placeholder"; 16 aws_secret_access_key = "placeholder"; 17 aws_session_token = "placeholder"; 18 }; 19 }; 20 sharedConfigurationDirectory = pkgs.runCommand ".aws" { } '' 21 mkdir $out 22 23 cp ${sharedConfigurationFile} $out/config 24 cp ${sharedCredentialsFile} $out/credentials 25 ''; 26in 27{ 28 name = "amazon-cloudwatch-agent"; 29 30 nodes.machine = 31 { config, pkgs, ... }: 32 { 33 services.amazon-cloudwatch-agent = { 34 enable = true; 35 commonConfiguration = { 36 credentials = { 37 shared_credential_profile = sharedConfigurationDefaultProfile; 38 shared_credential_file = "${sharedConfigurationDirectory}/credentials"; 39 }; 40 }; 41 configuration = { 42 agent = { 43 # Required despite documentation saying the agent ignores it in "onPremise" mode. 44 region = region; 45 46 # Show debug logs and write to a file for interactive debugging. 47 debug = true; 48 logfile = "/var/log/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log"; 49 }; 50 logs = { 51 logs_collected = { 52 files = { 53 collect_list = [ 54 { 55 file_path = "/var/log/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log"; 56 log_group_name = "/var/log/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log"; 57 log_stream_name = "{local_hostname}"; 58 } 59 ]; 60 }; 61 }; 62 }; 63 traces = { 64 local_mode = true; 65 traces_collected = { 66 xray = { }; 67 }; 68 }; 69 }; 70 mode = "onPremise"; 71 }; 72 73 # Keep the runtime directory for interactive debugging. 74 systemd.services.amazon-cloudwatch-agent.serviceConfig.RuntimeDirectoryPreserve = true; 75 }; 76 77 testScript = '' 78 start_all() 79 80 machine.wait_for_unit("amazon-cloudwatch-agent.service") 81 82 machine.wait_for_file("/run/amazon-cloudwatch-agent/amazon-cloudwatch-agent.pid") 83 machine.wait_for_file("/run/amazon-cloudwatch-agent/amazon-cloudwatch-agent.toml") 84 # "config-translator" omits this file if no trace configurations are specified. 85 # 86 # See https://github.com/aws/amazon-cloudwatch-agent/issues/1320. 87 machine.wait_for_file("/run/amazon-cloudwatch-agent/amazon-cloudwatch-agent.yaml") 88 machine.wait_for_file("/run/amazon-cloudwatch-agent/env-config.json") 89 ''; 90}