-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.nix
91 lines (83 loc) · 2.33 KB
/
ec2.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{
zabbixServer ? "default"
, account ? "default"
, instanceType ? "m5.large"
, region ? "us-east-1"
, zone ? "us-east-1d"
, dnsName ? ""
, subnetId ? ""
, dnsZoneName ? ""
, ...
}:
{
require = [
];
defaults =
{ config, pkgs, name, resources, lib, ... }:
{
deployment.targetEnv = "ec2";
deployment.ec2 = lib.mkDefault {
region = region;
zone = zone;
subnetId = subnetId;
elasticIPv4 = resources.elasticIPs."zabbix-${zabbixServer}-eipv4";
securityGroupIds = [
resources.ec2SecurityGroups."zabbix-${zabbixServer}-https-sg".name
resources.ec2SecurityGroups."zabbix-${zabbixServer}-agent-sg".name
resources.ec2SecurityGroups."zabbix-${zabbixServer}-ssh-sg".name
];
ebsInitialRootDiskSize = 50;
instanceType = instanceType;
securityGroups = [];
associatePublicIpAddress = true;
accessKeyId = account;
instanceProfile = resources.iamRoles."zabbix-${zabbixServer}-role".name;
keyPair = resources.ec2KeyPairs."zabbix-${zabbixServer}-keypair".name;
tags = {
Name = "${config.deployment.name}.${name}";
Project = "Zabbix";
};
};
};
resources.ec2KeyPairs."zabbix-${zabbixServer}-keypair" =
{
accessKeyId = account;
inherit region;
};
resources.elasticIPs."zabbix-${zabbixServer}-eipv4" =
{
accessKeyId = account;
inherit region;
vpc = true;
};
resources.route53HostedZones."zabbix-${zabbixServer}-hosted-zone" =
{ config, resources, ... }:
{
accessKeyId = account;
name = dnsZoneName;
};
resources.route53RecordSets."zabbix-${zabbixServer}-dns" =
{ config, resources, lib, ... }:
{
accessKeyId = account;
zoneId = resources.route53HostedZones."zabbix-${zabbixServer}-hosted-zone";
name = dnsName;
domainName = "${dnsName}.";
routingPolicy = "simple";
recordType = "A";
recordValues = [ resources.machines.machine ];
};
resources.iamRoles."zabbix-${zabbixServer}-role" =
{ lib, ... }:
{
accessKeyId = account;
policy = builtins.toJSON
{ Statement =
[{
Effect = "Allow";
Action = [ "ses:SendEmail" "ses:SendRawEmail" ];
Resource = "*";
}];
};
};
}