Skip to content

Commit

Permalink
Use synchronous data sources. (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Aug 10, 2019
1 parent b367a7c commit 8d30933
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 58 deletions.
12 changes: 5 additions & 7 deletions aws-ts-appsync/iam.ts
Expand Up @@ -3,18 +3,16 @@ import * as aws from "@pulumi/aws";

export function createIamRole(name: string, table: aws.dynamodb.Table) {
const role = new aws.iam.Role(`${name}-role`, {
assumeRolePolicy: pulumi.output(
aws.iam.getPolicyDocument({
assumeRolePolicy: aws.iam.getPolicyDocument({
statements: [{
actions: ["sts:AssumeRole"],
principals: [{
identifiers: ["appsync.amazonaws.com"],
identifiers: ["appsync.amazonaws.com"],
type: "Service",
}],
effect: "Allow",
}],
})
).apply(r => r.json),
}).json,
});

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

new aws.iam.RolePolicyAttachment(`${name}-rpa`, {
role: role,
Expand Down
4 changes: 2 additions & 2 deletions aws-ts-ruby-on-rails/index.ts
Expand Up @@ -13,7 +13,7 @@ const webSg = new aws.ec2.SecurityGroup("webServerSecurityGroup", {
],
});

const amiId = pulumi.output(aws.getAmi({
const amiId = aws.getAmi({
filters: [
{
name: "name",
Expand All @@ -26,7 +26,7 @@ const amiId = pulumi.output(aws.getAmi({
],
mostRecent: true,
owners: ["137112412989"],
}));
});

const webServer = new aws.ec2.Instance("webServer", {
ami: amiId.id,
Expand Down
2 changes: 1 addition & 1 deletion aws-ts-stackreference/team/index.ts
Expand Up @@ -25,7 +25,7 @@ const amiId = aws.getAmi({
{ name: "owner-id", values: ["099720109477"] }, // Ubuntu
{ name: "name", values: ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"] },
],
}).then(x => x.id);
}).id;

const instance = new aws.ec2.Instance("tagged", {
ami: amiId,
Expand Down
8 changes: 4 additions & 4 deletions aws-ts-static-website/index.ts
Expand Up @@ -96,7 +96,7 @@ if (config.certificateArn === undefined) {
}, { provider: eastRegion });

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

/**
* Create a DNS record to prove that we _own_ the domain we're requesting a certificate for.
Expand Down Expand Up @@ -225,10 +225,10 @@ function getDomainAndSubdomain(domain: string): { subdomain: string, parentDomai
}

// Creates a new Route53 DNS record pointing the domain to the CloudFront distribution.
async function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): Promise<aws.route53.Record> {
function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): aws.route53.Record {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZone = await aws.route53.getZone({ name: domainParts.parentDomain });
const hostedZone = aws.route53.getZone({ name: domainParts.parentDomain });
return new aws.route53.Record(
targetDomain,
{
Expand Down
30 changes: 15 additions & 15 deletions aws-ts-twitter-athena/index.ts
Expand Up @@ -35,7 +35,7 @@ let handler = eventRule.onEvent("on-timer-event", async() => {
access_token_key: accessTokenKey,
access_token_secret: accessTokenSecret,
});

const tweets = await new Promise<string[]>((resolve, reject) => {
client.get('search/tweets', {q: twitterQuery, count: 100}, function(error: any, tweets: any, response: any) {
if (error) {
Expand All @@ -44,17 +44,17 @@ let handler = eventRule.onEvent("on-timer-event", async() => {

let statuses = tweets.statuses;
console.log(`Got ${statuses.length} statuses.`);

let results = statuses.map((s: any) => {
let user = s.user.screen_name;
return JSON.stringify({

return JSON.stringify({
created_at: s.created_at,
id: s.id_str,
text: s.text,
id: s.id_str,
text: s.text,
user: user,
hashtags: s.entities.hashtags,
followers: s.user.followers_count,
followers: s.user.followers_count,
isVerified: s.user.verified,
isRetweet: s.retweeted_status != null,
url: `https://twitter.com/${user}/status/${s.id_str}`,
Expand All @@ -66,7 +66,7 @@ let handler = eventRule.onEvent("on-timer-event", async() => {
});

console.log(`Got ${tweets.length} tweets from Twitter for query ${twitterQuery}`);

let filename = `${outputFolder}/${Date.now()}`;
let contents = Buffer.from(tweets.join("\n"), "utf8");

Expand All @@ -79,11 +79,11 @@ let handler = eventRule.onEvent("on-timer-event", async() => {
});

// athena setup
let athena = new aws.athena.Database("tweets_database",
{ name: "tweets_database", bucket: bucket.id, forceDestroy: true }
let athena = new aws.athena.Database("tweets_database_1",
{ name: "tweets_database_1", bucket: bucket.id, forceDestroy: true }
);

// Sadly, there isn't support for Athena tables in Terraform.
// Sadly, there isn't support for Athena tables in Terraform.
// See https://github.com/terraform-providers/terraform-provider-aws/pull/1893#issuecomment-351300973
// So, we'll instead create a query for the table definition
function createTableQuery(bucket: string) {
Expand All @@ -101,9 +101,9 @@ function createTableQuery(bucket: string) {
LOCATION 's3://${bucket}/${outputFolder}/';`;
}

let topUsersQuery =
`select distinct user, followers, text, url
from tweets
let topUsersQuery =
`select distinct user, followers, text, url
from tweets
where isRetweet = false and followers > 1000
order by followers desc`;

Expand All @@ -121,4 +121,4 @@ function getQueryUri(queryId: string) {
exports.bucketName = bucketName
exports.athenaDatabase = athena.id;
exports.topUsersQueryUri = topUsersAthenaQuery.id.apply(getQueryUri);
exports.createTableQueryUri = createTableAthenaQuery.id.apply(getQueryUri);
exports.createTableQueryUri = createTableAthenaQuery.id.apply(getQueryUri);
19 changes: 9 additions & 10 deletions azure-ts-msi-keyvault-rbac/index.ts
Expand Up @@ -69,16 +69,15 @@ const blob = new azure.storage.ZipBlob("zip", {
content: new pulumi.asset.FileArchive("./webapp/bin/Debug/netcoreapp2.2/publish")
});

const clientConfig = pulumi.output(azure.core.getClientConfig({}));
const tenantId = clientConfig.apply(c => c.tenantId);

const currentPrincipal = clientConfig.apply(c =>
// Currently, only service principal ID is available in the context. If we are provided the principle in the config, then
// just use it. Otherwise, if logged in with a user, find their ID via Azure CLI.
// see https://github.com/terraform-providers/terraform-provider-azurerm/issues/3234
c.servicePrincipalObjectId !== ""
? c.servicePrincipalObjectId
: <string>JSON.parse(execSync("az ad signed-in-user show --query objectId").toString()));
const clientConfig = azure.core.getClientConfig({});
const tenantId = clientConfig.tenantId;

// Currently, only service principal ID is available in the context. If we are provided the
// principle in the config, then just use it. Otherwise, if logged in with a user, find their ID
// via Azure CLI. see https://github.com/terraform-providers/terraform-provider-azurerm/issues/3234
const currentPrincipal = clientConfig.servicePrincipalObjectId !== ""
? clientConfig.servicePrincipalObjectId
: <string>JSON.parse(execSync("az ad signed-in-user show --query objectId").toString());

// Key Vault to store secrets (e.g. Blob URL with SAS)
const vault = new azure.keyvault.KeyVault("vault", {
Expand Down
4 changes: 2 additions & 2 deletions azure-ts-webserver-component/webserver.ts
Expand Up @@ -65,8 +65,8 @@ 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(async d => {
const ip = await azure.network.getPublicIP({ name: d.name, resourceGroupName: d.resourceGroupName });
return ready.apply(d => {
const ip = azure.network.getPublicIP({ name: d.name, resourceGroupName: d.resourceGroupName });
return ip.ipAddress;
});
}
Expand Down
4 changes: 2 additions & 2 deletions azure-ts-webserver/index.ts
Expand Up @@ -74,7 +74,7 @@ nohup python -m SimpleHTTPServer 80 &`,
// resource to create, and then lookup the IP address again to report its public IP.
const done = pulumi.all({ _: vm.id, name: publicIp.name, resourceGroupName: publicIp.resourceGroupName });

export const ipAddress = done.apply(async d => {
const ip = await azure.network.getPublicIP({ name: d.name, resourceGroupName: d.resourceGroupName });
export const ipAddress = done.apply(d => {
const ip = azure.network.getPublicIP({ name: d.name, resourceGroupName: d.resourceGroupName });
return ip.ipAddress;
});
28 changes: 14 additions & 14 deletions cloud-js-twitter-athena/index.js
Expand Up @@ -22,20 +22,20 @@ cloud.timer.interval("twitter-search-timer", { minutes: 2 }, async() => {
access_token_key: accessTokenKey,
access_token_secret: accessTokenSecret,
});

client.get('search/tweets', {q: twitterQuery, count: 100}, function(error, tweets, response) {
let statuses = tweets.statuses;

let results = statuses.map(s => {
let user = s.user.screen_name;
return JSON.stringify({

return JSON.stringify({
created_at: s.created_at,
id: s.id_str,
text: s.text,
id: s.id_str,
text: s.text,
user: user,
hashtags: s.entities.hashtags,
followers: s.user.followers_count,
followers: s.user.followers_count,
isVerified: s.user.verified,
isRetweet: s.retweeted_status != null,
url: `https://twitter.com/${user}/status/${s.id_str}`,
Expand All @@ -48,15 +48,15 @@ cloud.timer.interval("twitter-search-timer", { minutes: 2 }, async() => {
let contents = Buffer.from(results.join("\n"), "utf8");

bucket.put(filename, contents);
});
});
});

// athena setup
let athena = new aws.athena.Database("tweets_database",
{ name: "tweets_database", bucket: bucket.bucket.id, forceDestroy: true }
let athena = new aws.athena.Database("tweets_database_2",
{ name: "tweets_database_2", bucket: bucket.bucket.id, forceDestroy: true }
);

// Sadly, there isn't support for Athena tables in Terraform.
// Sadly, there isn't support for Athena tables in Terraform.
// See https://github.com/terraform-providers/terraform-provider-aws/pull/1893#issuecomment-351300973
// So, we'll instead create a query for the table definition
function createTableQuery(bucket) {
Expand All @@ -74,9 +74,9 @@ function createTableQuery(bucket) {
LOCATION 's3://${bucket}/${outputFolder}/';`;
}

let topUsersQuery =
`select distinct user, followers, text, url
from tweets
let topUsersQuery =
`select distinct user, followers, text, url
from tweets
where isRetweet = false and followers > 1000
order by followers desc`;

Expand All @@ -96,4 +96,4 @@ function getQueryUri(queryId) {
exports.bucketName = bucketName
exports.athenaDatabase = athena.id;
exports.topUsersQueryUri = topUsersAthenaQuery.id.apply(getQueryUri);
exports.createTableQueryUri = createTableAthenaQuery.id.apply(getQueryUri);
exports.createTableQueryUri = createTableAthenaQuery.id.apply(getQueryUri);
2 changes: 1 addition & 1 deletion kubernetes-ts-multicloud/gke.ts
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().then(v => v.latestMasterVersion);
const engineVersion = gcp.container.getEngineVersions().latestMasterVersion;

// Generate a strong password for the Kubernetes cluster.
const password = new random.RandomString("password", {
Expand Down

0 comments on commit 8d30933

Please sign in to comment.