Skip to content

Commit

Permalink
Make all JS/TS invokes async (pulumi#502)
Browse files Browse the repository at this point in the history
This standardizes all data source calls to pass `async: true` to avoid potential for hangs.  See pulumi/pulumi#3528.
  • Loading branch information
lukehoban committed Dec 17, 2019
1 parent 6c97ab4 commit 7447138
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions aws-js-webserver-component/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const pulumi = require("@pulumi/pulumi");
const aws = require("@pulumi/aws");

// Get the id for the latest Amazon Linux AMI
let ami = pulumi.output(aws.getAmi({
let ami = aws.getAmi({
filters: [
{ name: "name", values: ["amzn-ami-hvm-*-x86_64-ebs"] },
],
owners: ["137112412989"], // Amazon
mostRecent: true,
})).apply(result => result.id);
}, { async: true }).then(result => result.id);

// create a new security group for port 80
let group = new aws.ec2.SecurityGroup("web-secgrp", {
Expand Down
4 changes: 2 additions & 2 deletions aws-js-webserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const aws = require("@pulumi/aws");
let size = "t2.micro"; // t2.micro is available in the AWS free tier

// Get the id for the latest Amazon Linux AMI
let ami = pulumi.output(aws.getAmi({
let ami = aws.getAmi({
filters: [
{ name: "name", values: ["amzn-ami-hvm-*-x86_64-ebs"] },
],
owners: ["137112412989"], // Amazon
mostRecent: true,
})).apply(result => result.id);
}, { async: true }).then(result => result.id);

// create a new security group for port 80
let group = new aws.ec2.SecurityGroup("web-secgrp", {
Expand Down
2 changes: 1 addition & 1 deletion aws-stackreference-architecture/networking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
};
const availabilityZones = aws.getAvailabilityZones({
state: "available",
});
}, { async: true });

const appVpc = new Vpc("app-vpc", {
description: `${baseTags.ManagedBy} App VPC`,
Expand Down
2 changes: 1 addition & 1 deletion aws-stackreference-architecture/networking/src/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class Vpc extends ComponentResource {
let autoAccept = false;
let peerOwner = args.peerOwnerId;
if (!args.peerOwnerId) {
peerOwner = output(aws.getCallerIdentity()).apply(i => i.accountId);
peerOwner = aws.getCallerIdentity({ async: true }).then(i => i.accountId);
autoAccept = true;
}
const peerName = args.peerVpc.name;
Expand Down
4 changes: 2 additions & 2 deletions aws-ts-appsync/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createIamRole(name: string, table: aws.dynamodb.Table) {
}],
effect: "Allow",
}],
}).json,
}, { async: true }).then(doc => doc.json),
});

const policy = new aws.iam.Policy(`${name}-policy`, {
Expand All @@ -24,7 +24,7 @@ export function createIamRole(name: string, table: aws.dynamodb.Table) {
resources: [arn],
effect: "Allow",
}],
})).json,
}, { async: true }).then(doc => doc.json)),
});

const attachment = new aws.iam.RolePolicyAttachment(`${name}-rpa`, {
Expand Down
2 changes: 1 addition & 1 deletion aws-ts-ec2-provisioners/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const amiId = aws.getAmi({
name: "name",
values: ["amzn2-ami-hvm-2.0.????????-x86_64-gp2"],
}],
}, { async: true}).then(ami => ami.id);
}, { async: true }).then(ami => ami.id);

// Create an EC2 server that we'll then provision stuff onto.
const size = "t2.micro";
Expand Down
4 changes: 2 additions & 2 deletions aws-ts-ruby-on-rails/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const amiId = aws.getAmi({
],
mostRecent: true,
owners: ["137112412989"],
});
}, { async: true }).then(ami => ami.id);

const webServer = new aws.ec2.Instance("webServer", {
ami: amiId.id,
ami: amiId,
instanceType: config.instanceType,
securityGroups: [ webSg.name ],
userData: createUserData(
Expand Down
6 changes: 3 additions & 3 deletions aws-ts-stackreference/team/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const combinedTags = {
"Managed By": "Pulumi",
};

const ami = aws.getAmi({
const amiId = aws.getAmi({
owners: ["099720109477"], // Ubuntu
mostRecent: true,
filters: [
{ name: "name", values: ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] },
],
});
}, { async: true }).then(ami => ami.id);

const instance = new aws.ec2.Instance("tagged", {
ami: ami.id,
ami: amiId,
instanceType: "t2.medium",
tags: combinedTags,
});
Expand Down
6 changes: 3 additions & 3 deletions aws-ts-static-website/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if (config.certificateArn === undefined) {
}, { provider: eastRegion });

const domainParts = getDomainAndSubdomain(config.targetDomain);
const hostedZoneId = aws.route53.getZone({ name: domainParts.parentDomain }).id;
const hostedZoneId = aws.route53.getZone({ name: domainParts.parentDomain }, { async: true }).then(zone => zone.zoneId);

/**
* Create a DNS record to prove that we _own_ the domain we're requesting a certificate for.
Expand Down Expand Up @@ -230,12 +230,12 @@ function getDomainAndSubdomain(domain: string): { subdomain: string, parentDomai
function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): aws.route53.Record {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZone = aws.route53.getZone({ name: domainParts.parentDomain });
const hostedZoneId = aws.route53.getZone({ name: domainParts.parentDomain }, { async: true }).then(zone => zone.zoneId);
return new aws.route53.Record(
targetDomain,
{
name: domainParts.subdomain,
zoneId: hostedZone.zoneId,
zoneId: hostedZoneId,
type: "A",
aliases: [
{
Expand Down
2 changes: 1 addition & 1 deletion azure-js-webserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ exports.publicIP = pulumi.all({ id: vm.id, name: publicIP.name, resourceGroupNam
azure.network.getPublicIP({
name: ip.name,
resourceGroupName: ip.resourceGroupName,
}).then(ip => ip.ipAddress)
}, { async: true }).then(ip => ip.ipAddress)
);
6 changes: 3 additions & 3 deletions azure-ts-msi-keyvault-rbac/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const blob = new azure.storage.ZipBlob("zip", {
content: new pulumi.asset.FileArchive("./webapp/bin/Debug/netcoreapp2.2/publish"),
});

const clientConfig = azure.core.getClientConfig({});
const tenantId = clientConfig.tenantId;
const currentPrincipal = clientConfig.objectId;
const clientConfig = azure.core.getClientConfig({ async: true });
const tenantId = clientConfig.then(config => config.tenantId);
const currentPrincipal = clientConfig.then(config => config.objectId);

// Key Vault to store secrets (e.g. Blob URL with SAS)
const vault = new azure.keyvault.KeyVault("vault", {
Expand Down
9 changes: 5 additions & 4 deletions azure-ts-webserver-component/webserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ export class WebServer extends pulumi.ComponentResource {
// The public IP address is not allocated until the VM is running, so wait for that
// resource to create, and then lookup the IP address again to report its public IP.
const ready = pulumi.all({ _: this.vm.id, name: this.publicIp.name, resourceGroupName: this.publicIp.resourceGroupName });
return ready.apply(d => {
const ip = azure.network.getPublicIP({ name: d.name, resourceGroupName: d.resourceGroupName });
return ip.ipAddress;
});
return ready.apply(d =>
azure.network.getPublicIP({
name: d.name,
resourceGroupName: d.resourceGroupName,
}, { async: true }).then(ip => ip.ipAddress));
}
}

Expand Down
6 changes: 4 additions & 2 deletions azure-ts-webserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ nohup python -m SimpleHTTPServer 80 &`,
const done = pulumi.all({ _: vm.id, name: publicIp.name, resourceGroupName: publicIp.resourceGroupName });

export const ipAddress = done.apply(d => {
const ip = azure.network.getPublicIP({ name: d.name, resourceGroupName: d.resourceGroupName });
return ip.ipAddress;
return azure.network.getPublicIP({
name: d.name,
resourceGroupName: d.resourceGroupName,
}, { async: true }).then(ip => ip.ipAddress);
});
2 changes: 1 addition & 1 deletion f5bigip-ts-ltm-pool/nginx-ec2-instance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ubuntuAmiId = aws.getAmi({
mostRecent: true,
nameRegex: "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
owners: ["099720109477"],
}).then(ami => ami.id);
}, { async: true }).then(ami => ami.id);

const nginxUserData =
`#!/bin/bash
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-ts-multicloud/aks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class AksCluster extends pulumi.ComponentResource {
clientId: adApp.applicationId,
clientSecret: adSpPassword.value,
},
kubernetesVersion: "1.13.5",
kubernetesVersion: "1.15.5",
roleBasedAccessControl: {enabled: true},
networkProfile: {
networkPlugin: "azure",
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-ts-multicloud/gke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class GkeCluster extends pulumi.ComponentResource {
super("examples:kubernetes-ts-multicloud:GkeCluster", name, {}, opts);

// Find the latest engine version.
const engineVersion = gcp.container.getEngineVersions().latestMasterVersion;
const engineVersion = gcp.container.getEngineVersions({}, { async: true }).then(v => v.latestMasterVersion);

// Generate a strong password for the Kubernetes cluster.
const password = new random.RandomPassword("password", {
Expand Down
2 changes: 1 addition & 1 deletion linode-js-webserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const startupScript = `#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &`;

const profile = pulumi.output(linode.getProfile());
const profile = pulumi.output(linode.getProfile({ async: true }));

const stackscript = new linode.StackScript("simple-server", {
label: "simple-server",
Expand Down

0 comments on commit 7447138

Please sign in to comment.