Skip to content

Commit eff7fc0

Browse files
author
Shay Bergmann
authored
Merge pull request #165 from input-output-hk/clients-happy-path
2 parents fa5c2cf + 65ab111 commit eff7fc0

File tree

5 files changed

+52
-40
lines changed

5 files changed

+52
-40
lines changed

modules/terraform.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@
113113
# For available packages, see or modify /profiles/slim.nix
114114
in ''
115115
#!
116+
cat <<'EOF' > /etc/finish-bootstrap.sh
117+
#!/bin/sh
116118
export NIX_CONFIG="${nixConf}"
117119
export PATH="/run/current-system/sw/bin:$PATH"
118120
set -exuo pipefail
119121
pushd /run/keys
120122
err_code=0
121123
aws s3 cp \
122-
"s3://${cfg.s3Bucket}/infra/secrets/${cfg.name}/${cfg.kms}/source/${awsAsg}-source.tar.xz" \
124+
"s3://${cfg.s3Bucket}/${var "aws_s3_bucket_object.${awsAsg}-flake.id"}" \
123125
source.tar.xz || err_code=$?
124126
if test $err_code -eq 0
125127
then # automated provisioning
@@ -128,6 +130,9 @@
128130
nix build ./source#nixosConfigurations.${cfg.name}-${awsAsg}.config.system.build.toplevel
129131
nixos-rebuild --flake ./source#${cfg.name}-${awsAsg} switch
130132
fi # manual provisioning
133+
EOF
134+
chmod +x /etc/finish-bootstrap.sh
135+
systemd-run --unit=nixos-init $_
131136
'';
132137

133138
sshArgs = "-C -oConnectTimeout=5 -oUserKnownHostsFile=/dev/null -oNumberOfPasswordPrompts=0 -oServerAliveInterval=60 -oControlPersist=600 -oStrictHostKeyChecking=no -i ./secrets/ssh-${cfg.name}";
@@ -412,7 +417,7 @@
412417
cidr = net.cidr.subnet 8 idx cidr;
413418
availabilityZone =
414419
var
415-
"module.instance_types_to_azs.availability_zones[${toString idx}]";
420+
"element(module.instance_types_to_azs.availability_zones, ${toString idx})";
416421
}))
417422
lib.listToAttrs
418423
];
@@ -1115,7 +1120,7 @@
11151120
cidr = net.cidr.subnet 2 idx cidr;
11161121
availabilityZone =
11171122
var
1118-
"module.instance_types_to_azs_${region}.availability_zones[${toString idx}]";
1123+
"element(module.instance_types_to_azs_${region}.availability_zones, ${toString idx})";
11191124
}))
11201125
lib.listToAttrs
11211126
];

modules/terraform/clients.nix

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ in {
192192
id "aws_vpc_peering_connection.${vpc.region}";
193193
}));
194194

195+
resource.aws_s3_bucket_object = lib.flip lib.mapAttrs' config.cluster.awsAutoScalingGroups (name: group:
196+
lib.nameValuePair "${name}-flake" rec {
197+
bucket = config.cluster.s3Bucket;
198+
key = with config; "infra/secrets/${cluster.name}/${cluster.kms}/source/${name}-source.tar.xz";
199+
etag = var ''filemd5("${source}")'';
200+
source = "${pkgs.runCommand "source.tar.xz" {} ''
201+
tar cvf $out -C ${config.cluster.flakePath} .
202+
''}";
203+
});
204+
195205
resource.aws_subnet = mapAwsAsgVpcs (vpc:
196206
lib.flip lib.mapAttrsToList vpc.subnets (suffix: subnet:
197207
lib.nameValuePair "${vpc.region}-${suffix}" {
@@ -316,7 +326,7 @@ in {
316326
lib.nameValuePair vpc.region {
317327
provider = awsProviderFor vpc.region;
318328
vpc_peering_connection_id =
319-
id "aws_vpc_peering_connection.${vpc.region}";
329+
id "aws_vpc_peering_connection_accepter.${vpc.region}";
320330

321331
requester = {allow_remote_vpc_dns_resolution = true;};
322332
});
@@ -334,9 +344,8 @@ in {
334344
requesterMeshPeeringOptions = mapAwsAsgVpcPeers (link:
335345
lib.nameValuePair "${link.connector}-connect-${link.accepter}" {
336346
provider = awsProviderFor link.connector;
337-
vpc_peering_connection_id =
338-
id
339-
"aws_vpc_peering_connection.${link.connector}-connect-${link.accepter}";
347+
vpc_peering_connection_id = id
348+
"aws_vpc_peering_connection_accepter.${link.accepter}-accept-${link.connector}";
340349

341350
requester = {allow_remote_vpc_dns_resolution = true;};
342351
});
@@ -378,10 +387,17 @@ in {
378387
lib.nameValuePair group.uid {
379388
name = group.uid;
380389
inherit (group.iam.instanceProfile) path;
381-
role = group.iam.instanceProfile.role.tfName;
382-
lifecycle = [{create_before_destroy = true;}];
390+
role = var "data.aws_iam_role.${config.cluster.iam.roles.client.uid}.name";
391+
lifecycle = [{ create_before_destroy = true; }];
383392
});
384393

394+
data.aws_iam_role = let
395+
# deploy for core role
396+
inherit (config.cluster.iam.roles.client) uid;
397+
in {
398+
"${uid}".name = "core-${uid}";
399+
};
400+
385401
data.aws_iam_policy_document = let
386402
# deploy for client role
387403
role = config.cluster.iam.roles.client;
@@ -395,31 +411,18 @@ in {
395411
inherit (policy) condition;
396412
});
397413
};
398-
in
399-
lib.listToAttrs (lib.mapAttrsToList op role.policies);
400-
401-
resource.aws_iam_role = let
402-
# deploy for client role
403-
role = config.cluster.iam.roles.client;
404-
in {
405-
"${role.uid}" = {
406-
name = role.uid;
407-
assume_role_policy = role.assumePolicy.tfJson;
408-
lifecycle = [{create_before_destroy = true;}];
409-
};
410-
};
414+
in lib.mapAttrs' op role.policies;
411415

412416
resource.aws_iam_role_policy = let
413417
# deploy for client role
414418
role = config.cluster.iam.roles.client;
415419
op = policyName: policy:
416420
lib.nameValuePair policy.uid {
417421
name = policy.uid;
418-
role = role.id;
422+
role = id "data.aws_iam_role.${role.uid}";
419423
policy = var "data.aws_iam_policy_document.${policy.uid}.json";
420424
};
421-
in
422-
lib.listToAttrs (lib.mapAttrsToList op role.policies);
425+
in lib.mapAttrs' op role.policies;
423426

424427
resource.aws_security_group =
425428
lib.flip lib.mapAttrsToList config.cluster.awsAutoScalingGroups

modules/terraform/core.nix

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,17 @@ in {
225225

226226
resource.aws_iam_role = let
227227
# deploy for core role
228-
role = config.cluster.iam.roles.core;
228+
inherit (config.cluster.iam.roles) client core;
229229
in {
230-
"${role.uid}" = {
231-
name = role.uid;
232-
assume_role_policy = role.assumePolicy.tfJson;
233-
lifecycle = [{create_before_destroy = true;}];
230+
"${client.uid}" = {
231+
name = "core-${client.uid}";
232+
assume_role_policy = client.assumePolicy.tfJson;
233+
lifecycle = [{ create_before_destroy = true; }];
234+
};
235+
"${core.uid}" = {
236+
name = core.uid;
237+
assume_role_policy = core.assumePolicy.tfJson;
238+
lifecycle = [{ create_before_destroy = true; }];
234239
};
235240
};
236241

profiles/client.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ in {
1919
./auxiliaries/reaper.nix
2020
];
2121

22-
services.s3-upload-flake.enable = deployType == "aws";
2322
services.zfs-client-options.enable = deployType == "aws";
2423

2524
services.telegraf.extraConfig.global_tags.role = "consul-client";

profiles/glusterfs/client.nix

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ in {
1414
path = with pkgs; [nettools];
1515
};
1616

17-
fileSystems."/mnt/gv0" = lib.mkIf cfg.enable {
18-
device = "glusterd.service.consul:/gv0";
19-
fsType = "glusterfs";
20-
};
21-
22-
systemd.services."mnt-gv0.mount" = lib.mkIf cfg.enable {
23-
after = ["consul.service"];
24-
wants = ["consul.service"];
25-
};
17+
systemd.mounts = [
18+
(lib.mkIf cfg.enable {
19+
after = [ "consul.service" "dnsmasq.service" ];
20+
wants = [ "consul.service" "dnsmasq.service" ];
21+
what = "glusterd.service.consul:/gv0";
22+
where = "/mnt/gv0";
23+
type = "glusterfs";
24+
})
25+
];
2626

2727
systemd.services.nomad = lib.mkIf cfg.enable {
2828
after = ["mnt-gv0.mount"];

0 commit comments

Comments
 (0)