generated from pulumi/pulumi-provider-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebase of #192. --------- Co-authored-by: Marc Ende <me@e-beyond.de>
- Loading branch information
Showing
28 changed files
with
2,040 additions
and
86 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: command-ec2-remote | ||
runtime: nodejs | ||
description: A simple command example |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { interpolate, Config, secret } from "@pulumi/pulumi"; | ||
import { local, remote, types } from "@pulumi/command"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as fs from "fs"; | ||
import * as os from "os"; | ||
import * as path from "path"; | ||
import { size } from "./size"; | ||
|
||
const config = new Config(); | ||
const keyName = config.get("keyName") ?? new aws.ec2.KeyPair("key", { publicKey: config.require("publicKey") }).keyName; | ||
const privateKeyBase64 = config.get("privateKeyBase64"); | ||
const privateKey = privateKeyBase64 ? Buffer.from(privateKeyBase64, 'base64').toString('ascii') : fs.readFileSync(path.join(os.homedir(), ".ssh", "id_rsa")).toString("utf8"); | ||
|
||
const ingress = new aws.ec2.SecurityGroup("ingress", { | ||
description: "A security group that will accept SSH connections from the outside world.", | ||
ingress: [ | ||
{ protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] }, | ||
{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] }, | ||
], | ||
egress: [ | ||
{ fromPort: 0, toPort: 0, protocol: "-1", cidrBlocks: ["0.0.0.0/0"], ipv6CidrBlocks: ["::/0"], }, | ||
], | ||
}); | ||
|
||
const validated = new aws.ec2.SecurityGroup("validated", { | ||
description: "A security group that will only accept connections that have already been validated.", | ||
ingress: [ | ||
{ protocol: "tcp", fromPort: 22, toPort: 22, securityGroups: [ingress.id] }, | ||
{ protocol: "tcp", fromPort: 80, toPort: 80, securityGroups: [ingress.id] }, | ||
], | ||
egress: [ | ||
{ fromPort: 0, toPort: 0, protocol: "-1", cidrBlocks: ["0.0.0.0/0"], ipv6CidrBlocks: ["::/0"], }, | ||
], | ||
}); | ||
|
||
const ami = aws.ec2.getAmiOutput({ | ||
owners: ["amazon"], | ||
mostRecent: true, | ||
filters: [{ | ||
name: "name", | ||
values: ["amzn-ami-hvm-*-x86_64-gp2"], | ||
}], | ||
}); | ||
|
||
const server = new aws.ec2.Instance("server", { | ||
instanceType: size, | ||
ami: ami.id, | ||
keyName: keyName, | ||
vpcSecurityGroupIds: [validated.id], | ||
}, { replaceOnChanges: ["instanceType"] }); | ||
|
||
const proxy = new aws.ec2.Instance("proxy", { | ||
instanceType: size, | ||
ami: ami.id, | ||
keyName: keyName, | ||
vpcSecurityGroupIds: [ingress.id], | ||
}, { replaceOnChanges: ["instanceType"] }); | ||
|
||
const connection: types.input.remote.ConnectionArgs = { | ||
host: server.privateDns, | ||
user: "ec2-user", | ||
privateKey: privateKey, | ||
proxy: { | ||
host: proxy.publicIp, | ||
user: "ec2-user", | ||
privateKey: privateKey, | ||
}, | ||
}; | ||
|
||
const hostname = new remote.Command("hostname", { | ||
connection: { | ||
...connection, | ||
dialErrorLimit: -1, | ||
proxy: { | ||
...connection.proxy, | ||
dialErrorLimit: -1, | ||
} | ||
}, | ||
create: "hostname", | ||
environment: secret({ | ||
"secret-key": secret("super-secret-value") | ||
}), | ||
}, { customTimeouts: { create: "10m" } }); | ||
|
||
new remote.Command("remotePrivateIP", { | ||
connection, | ||
create: interpolate`echo ${server.privateIp} > private_ip.txt`, | ||
delete: `rm private_ip.txt`, | ||
}, { deleteBeforeReplace: true, dependsOn: hostname }); | ||
|
||
new local.Command("localPrivateIP", { | ||
create: interpolate`echo ${server.privateIp} > private_ip.txt`, | ||
delete: `rm private_ip.txt`, | ||
}, { deleteBeforeReplace: true, dependsOn: hostname }); | ||
|
||
const sizeFile = new remote.CopyFile("size", { | ||
connection: connection, | ||
localPath: "./size.ts", | ||
remotePath: "size.ts", | ||
}, { dependsOn: hostname }) | ||
|
||
const catSize = new remote.Command("checkSize", { | ||
connection: connection, | ||
create: "cat size.ts", | ||
}, { dependsOn: sizeFile }) | ||
|
||
export const connectionSecret = hostname.connection; | ||
export const secretEnv = hostname.environment; | ||
export const confirmSize = catSize.stdout; | ||
export const publicIp = server.publicIp; | ||
export const publicHostName = server.publicDns; | ||
export const hostnameStdout = hostname.stdout; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "command-typescript", | ||
"version": "0.1.0", | ||
"devDependencies": { | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/aws": "^4.18.0", | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/random": "^4.2.0" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const size = "t2.micro"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const size = "t2.nano"; |
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
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
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
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
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
Oops, something went wrong.