Skip to content

Commit

Permalink
Merge pull request #143 from johnbedeir/dev
Browse files Browse the repository at this point in the history
Pulumi-AWS-EC2-Typescript
  • Loading branch information
JohnyDev authored Oct 17, 2022
2 parents c32c1e6 + 6537353 commit be216e4
Show file tree
Hide file tree
Showing 8 changed files with 3,213 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ __pycache__

.env

*.sqlite3
*.sqlite3

token.txt
kubectl
k10primer.yaml
ns.json
2 changes: 2 additions & 0 deletions Pulumi/AWS/Pulumi-aws-ec2-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
2 changes: 2 additions & 0 deletions Pulumi/AWS/Pulumi-aws-ec2-typescript/Pulumi.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config:
aws:region: eu-central-1
3 changes: 3 additions & 0 deletions Pulumi/AWS/Pulumi-aws-ec2-typescript/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: pulumi-aws-typescript
description: A minimal AWS TypeScript Pulumi program
runtime: nodejs
107 changes: 107 additions & 0 deletions Pulumi/AWS/Pulumi-aws-ec2-typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";


// Create a VPC.
const vpc = new aws.ec2.Vpc("vpc", {
cidrBlock: "10.0.0.0/16",
});

// Create an an internet gateway.
const gateway = new aws.ec2.InternetGateway("gateway", {
vpcId: vpc.id,
});

// Create a subnet that automatically assigns new instances a public IP address.
const subnet = new aws.ec2.Subnet("subnet", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
mapPublicIpOnLaunch: true,
});

// Create a route table.
const routes = new aws.ec2.RouteTable("routes", {
vpcId: vpc.id,
routes: [
{
cidrBlock: "0.0.0.0/0",
gatewayId: gateway.id,
},
],
});

// Associate the route table with the public subnet.
const routeTableAssociation = new aws.ec2.RouteTableAssociation("route-table-association", {
subnetId: subnet.id,
routeTableId: routes.id,
});

// Create a security group allowing inbound access over port 80 and outbound
// access to anywhere.
const securityGroup = new aws.ec2.SecurityGroup("security-group", {
vpcId: vpc.id,
ingress: [
{
cidrBlocks: [ "0.0.0.0/0" ],
protocol: "tcp",
fromPort: 22,
toPort: 22,
},
],
egress: [
{
cidrBlocks: [ "0.0.0.0/0" ],
fromPort: 0,
toPort: 0,
protocol: "-1",
},
],
});

// Fine the latest Amazon Linux 2 AMI.
const ami = pulumi.output(aws.ec2.getAmi({
owners: [ "amazon" ],
mostRecent: true,
filters: [
{ name: "description", values: [ "Amazon Linux 2 *" ] },
],
}));

// Create and launch an Amazon Linux EC2 instance into the public subnet.
const instance = new aws.ec2.Instance("instance", {
ami: ami.id,
instanceType: "t3.nano",
subnetId: subnet.id,
vpcSecurityGroupIds: [
securityGroup.id,
],
userData: `
#!/bin/bash
amazon-linux-extras install nginx1
amazon-linux-extras enable nginx
systemctl enable nginx
systemctl start nginx
`,
});

// Export the instance's publicly accessible URL.
module.exports = {
instanceURL: pulumi.interpolate `http://${instance.publicIp}`,
};

const userUser = new aws.iam.User("userUser", {path: "/"});
const userSshKey = new aws.iam.SshKey("userSshKey", {
username: userUser.name,
encoding: "SSH",
publicKey: " ", //write here the public ssh key
});

// const deployer = new aws.ec2.KeyPair("deployer", {
// publicKey: "", //write here the public ssh key
// });

// export const bucketName = bucket.id;
export const amiId = ami.id
export const instancePublicIp = instance.publicIp
export const user = userUser.name
Loading

0 comments on commit be216e4

Please sign in to comment.