-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathterraform_schema.nix
39 lines (35 loc) · 1.18 KB
/
terraform_schema.nix
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
28
29
30
31
32
33
34
35
36
37
38
39
providers:
{ lib, runCommand, formats, terraform, cacert, schema-merge }:
let
required_providers = providers: lib.mapAttrs
(_: p: {
inherit (p) version;
source = lib.toLower p.provider-source-address;
})
providers;
retrieveProviderSchema = name: provider:
let
mainJson = (formats.json { }).generate "main.tf.json" {
terraform.required_providers = required_providers { "${name}" = provider; };
};
terraform-with-plugins = terraform.withPlugins (_: [ provider ]);
in
runCommand "${name}.json" { } ''
cp ${mainJson} main.tf.json
${terraform-with-plugins}/bin/terraform init
${terraform-with-plugins}//bin/terraform providers schema -json >$out
'';
providersJson = (formats.json { }).generate "providers.json" (required_providers providers);
in
runCommand "schemas" { } ''
mkdir schemas
${lib.concatStringsSep "\n" (lib.mapAttrsToList
(name: provider: ''
ln -s ${retrieveProviderSchema name provider} schemas/"${name}.json"
'')
providers)}
ln -s ${providersJson} providers.json
mkdir -p $out
ln -s ${providersJson} $out/providers.json
${schema-merge}/bin/schema-merge . > $out/schema.json
''