Skip to content

Instantly share code, notes, and snippets.

@clstokes
Created January 10, 2020 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clstokes/269ed81cd5f70ad66161dc17a8d90b95 to your computer and use it in GitHub Desktop.
Save clstokes/269ed81cd5f70ad66161dc17a8d90b95 to your computer and use it in GitHub Desktop.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import { projectName, creator, amiId, instanceCount } from "./config";
/**
* Resources
*/
const baseTags = {
project: projectName,
creator: creator,
}
const privateNetwork = "10.0.0.0/16";
const publicInternet = "0.0.0.0/0";
// create a vpc
const vpc = new awsx.ec2.Vpc(`${projectName}-vpc`, {
numberOfAvailabilityZones: 1,
subnets: [{ type: "public" }],
tags: {
...baseTags,
// Name: `${projectName}-vpc`,
},
});
// create a security group
const webSg = new aws.ec2.SecurityGroup(`${projectName}-sg`, {
vpcId: vpc.id,
name: "web-sg",
ingress: [
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: [publicInternet] },
],
tags: {
...baseTags,
Name: `${projectName}-sg`,
},
});
// create a instance
const one = new aws.ec2.Instance(`${projectName}-one`, {
instanceType: aws.ec2.T2InstanceMedium,
associatePublicIpAddress: true,
ami: amiId,
subnetId: vpc.publicSubnetIds[0],
vpcSecurityGroupIds: [webSg.id],
tags: {
...baseTags,
Name: `${projectName}-server`,
},
});
const twoUserData = pulumi.interpolate`
IP Address: ${one.publicIp}
Subnet ID: ${vpc.publicSubnetIds[0]}
`;
const two = new aws.ec2.Instance(`${projectName}-two`, {
instanceType: aws.ec2.T2InstanceMedium,
associatePublicIpAddress: false,
ami: amiId,
subnetId: vpc.publicSubnetIds[0],
vpcSecurityGroupIds: [webSg.id],
userData: twoUserData,
tags: {
...baseTags,
Name: `${projectName}-server`,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment