Created
April 18, 2019 18:14
-
-
Save c0bra/fcf2f5dfd83254061a5563e9ba0f8a5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as pulumi from '@pulumi/pulumi'; | |
import * as cloud from '@pulumi/cloud'; | |
import * as aws from '@pulumi/aws'; | |
import * as awsx from '@pulumi/awsx'; | |
const config = new pulumi.Config('seniorvu'); | |
const dbPassword = config.require('zabbixDbPassword'); | |
let vpc = awsx.ec2.Vpc.getDefault(); | |
const cluster = new awsx.ecs.Cluster('seniorvu', { vpc }); | |
const autoScalingGroup = cluster.createAutoScalingGroup('zabbix', { | |
subnetIds: vpc.publicSubnetIds, | |
templateParameters: { | |
minSize: 2, | |
}, | |
launchConfigurationArgs: { | |
instanceType: 't2.small', | |
}, | |
}); | |
const zabbixTargetGroup = new awsx.elasticloadbalancingv2.ApplicationTargetGroup('zabbix', { | |
protocol: 'HTTP', | |
port: 8081, | |
}); | |
const zabbixListener = zabbixTargetGroup.createListener('zabbix', { | |
external: true, | |
protocol: 'HTTP', | |
port: 80, | |
}); | |
// zabbixListener.addListenerRule('health_check', { | |
// actions: [{ | |
// fixedResponse: { | |
// contentType: 'text/html', | |
// statusCode: '200', | |
// }, | |
// type: 'fixed-response', | |
// }], | |
// conditions: [{ | |
// field: 'path-pattern', | |
// values: '/', | |
// }], | |
// }); | |
const securityGroupIds = cluster.securityGroups.map(g => g.id); | |
const dbSubnets = new aws.rds.SubnetGroup("dbsubnets", { | |
subnetIds: vpc.publicSubnetIds, | |
}); | |
const db = new aws.rds.Instance('postgresdb', { | |
engine: 'postgres', | |
instanceClass: 'db.t2.micro', | |
allocatedStorage: 100, | |
dbSubnetGroupName: dbSubnets.id, | |
vpcSecurityGroupIds: securityGroupIds, | |
name: 'zabbix', | |
username: 'zabbix', | |
password: dbPassword, | |
skipFinalSnapshot: true, | |
}); | |
const environment = [ | |
{ name: 'DB_SERVER_HOST', value: db.endpoint.apply(e => e.split(':')[0]) }, | |
{ name: 'POSTGRES_DB', value: 'zabbix' }, | |
{ name: 'POSTGRES_USER', value: 'zabbix' }, | |
{ name: 'POSTGRES_PASSWORD', value: dbPassword }, | |
]; | |
const zabbix = new awsx.ecs.EC2Service('zabbix', { | |
cluster, | |
desiredCount: 1, | |
taskDefinitionArgs: { | |
containers: { | |
zabbix: { | |
image: 'zabbix/zabbix-server-pgsql:alpine-4.2-latest', | |
portMappings: [{ containerPort: 10051 }], | |
cpu: 512, | |
memory: 512, | |
environment, | |
}, | |
frontend: { | |
image: 'zabbix/zabbix-web-nginx-pgsql:alpine-4.2-latest', | |
portMappings: [zabbixTargetGroup], | |
cpu: 512, | |
memory: 128, | |
environment: [ | |
...environment, | |
{ name: 'ZBX_SERVER_HOST', value: 'localhost' }, | |
], | |
}, | |
}, | |
}, | |
}, { | |
dependsOn: db, | |
}); | |
export const zabbixUrl = pulumi.interpolate `http://${zabbixListener.endpoint.hostname}`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment