sparse-intern-71089
03/14/2023, 2:30 AMlittle-cartoon-10569
03/14/2023, 2:37 AMacceptable-plumber-31485
03/14/2023, 2:47 AMacceptable-plumber-31485
03/14/2023, 2:48 AMpulumi new aws-typescript
. Then I copied the code from that page and placed it all on index.ts. Then I ran pulumi upacceptable-plumber-31485
03/14/2023, 2:48 AMacceptable-plumber-31485
03/14/2023, 2:52 AM$ pulumi preview
Previewing update (dev-ts):
Type Name Plan Info
+ pulumi:pulumi:Stack t-dev-ts create 1 error
Diagnostics:
pulumi:pulumi:Stack (t-dev-ts):
error: Running program '/usr/local/src/repos/IaC/t/' failed with an unhandled exception:
TSError: ⨯ Unable to compile TypeScript:
index.ts(53,1): error TS1128: Declaration or statement expected.
index.ts(5,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
index.ts(9,28): error TS2339: Property 'getDefault' does not exist on type 'typeof Vpc'.
index.ts(10,27): error TS2339: Property 'SecurityGroup' does not exist on type 'typeof import("/usr/local/src/repos/IaC/t/node_modules/@pulumi/awsx/ec2/index")'.
index.ts(21,24): error TS2339: Property 'createListener' does not exist on type 'ApplicationLoadBalancer'.
index.ts(40,36): error TS2339: Property 'securityGroups' does not exist on type 'ApplicationLoadBalancer'.
index.ts(40,55): error TS7006: Parameter 'sg' implicitly has an 'any' type.
index.ts(47,13): error TS2339: Property 'attachTarget' does not exist on type 'ApplicationLoadBalancer'.
index.ts(52,27): error TS2304: Cannot find name 'listener'.
acceptable-plumber-31485
03/14/2023, 2:55 AMimport * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";
export = async () => {
const config = new pulumi.Config("aws");
const providerOpts = { provider: new aws.Provider("prov", { region: <aws.Region>config.require("region") }) };
// Create a security group to open ingress to our load balancer on port 80, and egress out of the VPC.
const vpc = awsx.ec2.Vpc.getDefault();
const sg = new awsx.ec2.SecurityGroup("web-sg", {
vpc,
// 1) Open ingress traffic to your load balancer. Explicitly needed for NLB, but not ALB:
// ingress: [{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: [ "0.0.0.0/0" ] }],
// 2) Open egress traffic from your EC2 instance to your load balancer (for health checks).
egress: [{ protocol: "-1", fromPort: 0, toPort: 0, cidrBlocks: [ "0.0.0.0/0" ] }],
});
// Creates an ALB associated with the default VPC for this region and listen on port 80.
// 3) Be sure to pass in our explicit SecurityGroup created above so that traffic may flow.
const alb = new awsx.lb.ApplicationLoadBalancer("web-traffic", { securityGroups: [ sg ] });
const listener = alb.createListener("web-listener", { port: 80 });
const publicIps: pulumi.Output<string>[] = [];
const subnets = await vpc.publicSubnets;
// For each subnet, and each subnet/zone, create a VM and a listener.
for (let i = 0; i < subnets.length; i++) {
// 4) Create the instance in the same VPC, passing in the security group with egress rule.
const vm = new aws.ec2.Instance(`web-${i}`, {
ami: aws.getAmi({
filters: [
{ name: "name", values: [ "ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*" ] },
{ name: "virtualization-type", values: [ "hvm" ] },
],
mostRecent: true,
owners: [ "099720109477" ], // Canonical
}).then(ami => ami.id),
instanceType: "t2.micro",
subnetId: subnets[i].subnet.id,
availabilityZone: subnets[i].subnet.availabilityZone,
vpcSecurityGroupIds: alb.securityGroups.map(sg => sg.securityGroup.id),
userData: `#!/bin/bash
echo "Hello World, from Server ${i+1}!" > index.html
nohup python -m SimpleHTTPServer 80 &`,
}, providerOpts);
publicIps.push(vm.publicIp);
// 5) Attach your load balancer's target group the target EC2 instance(s).
alb.attachTarget("target-" + i, vm);
};
}
// Export the resulting URL so that it's easy to access.
export const endpoint = listener.endpoint.hostname;
};
acceptable-plumber-31485
03/14/2023, 3:12 AMacceptable-plumber-31485
03/14/2023, 3:39 AMacceptable-plumber-31485
03/14/2023, 3:39 AMlittle-cartoon-10569
03/14/2023, 4:05 AMexport = async () {
syntax before. I removed that and sorted the trailing }
and it's good.little-cartoon-10569
03/14/2023, 4:06 AMacceptable-plumber-31485
03/14/2023, 4:06 AMNo matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by