about summary refs log tree commit diff
path: root/nixos/modules/virtualisation/openstack-metadata-fetcher.nix
blob: 2aff8ccd2c26fde401aac7bfa3697adab5a6dcc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{ targetRoot, wgetExtraOptions }:
''
  metaDir=${targetRoot}etc/ec2-metadata
  mkdir -m 0755 -p "$metaDir"

  echo "getting instance metadata..."

  wget_imds() {
    wget ${wgetExtraOptions} "$@"
  }

  if ! [ -e "$metaDir/ami-manifest-path" ]; then
    wget_imds -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path
  fi

  if ! [ -e "$metaDir/user-data" ]; then
    wget_imds -O "$metaDir/user-data" http://169.254.169.254/1.0/user-data && chmod 600 "$metaDir/user-data"
  fi

  if ! [ -e "$metaDir/hostname" ]; then
    wget_imds -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname
  fi

  if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then
    wget_imds -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
  fi
''