Skip to content

Commit

Permalink
Update Google Native examples to the current version (pulumi#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailshilkov committed Aug 9, 2021
1 parent 6eefb2a commit 830494c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 57 deletions.
33 changes: 3 additions & 30 deletions google-native-ts-functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,17 @@

import * as gcloud from "@pulumi/google-native";
import * as pulumi from "@pulumi/pulumi";
import * as random from "@pulumi/random";

const config = new pulumi.Config("google-native");
const project = config.require("project");
const region = config.require("region");
const bucket = new gcloud.storage.v1.Bucket("bucket");

const randomString = new random.RandomString("name", {
upper: false,
number: false,
special: false,
length: 8,
});

const bucketName = pulumi.interpolate`bucket-${randomString.result}`;
const bucket = new gcloud.storage.v1.Bucket("bucket", {
project: project,
bucket: bucketName,
name: bucketName,
});

const archiveName = "zip";
const bucketObject = new gcloud.storage.v1.BucketObject(archiveName, {
object: archiveName,
name: archiveName,
const bucketObject = new gcloud.storage.v1.BucketObject("zip", {
bucket: bucket.name,
source: new pulumi.asset.AssetArchive({
".": new pulumi.asset.FileArchive("./pythonfunc"),
}),
});

const functionName = pulumi.interpolate`func-${randomString.result}`;
const func = new gcloud.cloudfunctions.v1.Function("function-py", {
projectsId: project,
locationsId: region,
functionsId: functionName,
name: pulumi.interpolate`projects/${project}/locations/${region}/functions/${functionName}`,
sourceArchiveUrl: pulumi.interpolate`gs:https://${bucket.name}/${bucketObject.name}`,
httpsTrigger: {},
entryPoint: "handler",
Expand All @@ -48,9 +23,7 @@ const func = new gcloud.cloudfunctions.v1.Function("function-py", {
});

const invoker = new gcloud.cloudfunctions.v1.FunctionIamPolicy("function-py-iam", {
projectsId: project,
locationsId: region,
functionsId: functionName, // func.name returns the long `projects/foo/locations/bat/functions/buzz` name which doesn't suit here
functionId: func.name.apply(name => name.split("/")[name.split("/").length-1]),
bindings: [
{
members: ["allUsers"],
Expand Down
5 changes: 2 additions & 3 deletions google-native-ts-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"@types/express": "^4.16.0"
},
"dependencies": {
"@pulumi/google-native": "^0.0.1a",
"@pulumi/pulumi": "^3.0.0a",
"@pulumi/random": "^4.0.0a"
"@pulumi/google-native": "^0.7.0",
"@pulumi/pulumi": "^3.0.0"
}
}
17 changes: 9 additions & 8 deletions google-native-ts-k8s-ruby-on-rails-postgresql/infra/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import * as pulumi from "@pulumi/pulumi";
import { clusterPassword, clusterUsername, project, region} from "./config";
import { db, testDb } from "./db";

const clusterName = "gke-native";
const cluster = new gcloud.container.v1.Cluster("cluster", {
projectsId: project,
locationsId: region,
clustersId: clusterName,
parent: `projects/${project}/locations/${region}`,
initialClusterVersion: "1.18.16-gke.2100",
initialNodeCount: 1,
name: clusterName,
network: `projects/${project}/global/networks/default`,
nodeConfig: {
nodePools: [{
config: {
oauthScopes: [
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
Expand All @@ -26,7 +21,13 @@ const cluster = new gcloud.container.v1.Cluster("cluster", {
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/compute",
],
},
},
initialNodeCount: 1,
management: {
autoRepair: false,
},
name: "initial",
}],
}, {dependsOn: [db, testDb]});

// Uncomment the following to create a custom nodepool instead of
Expand Down
12 changes: 0 additions & 12 deletions google-native-ts-k8s-ruby-on-rails-postgresql/infra/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,10 @@ import * as pulumi from "@pulumi/pulumi";
import * as random from "@pulumi/random";
import { dbPassword, dbUsername, project } from "./config";

const randomSuffix = new random.RandomString("name", {
upper: false,
number: false,
special: false,
length: 8,
});

// Provision a database for our Rails app.
const instanceName = pulumi.interpolate `pgdb-${randomSuffix.result}`;
export const instance = new gcloud.sqladmin.v1beta4.Instance("web-db", {
databaseVersion: "POSTGRES_9_6",
project: project,
name: instanceName,
instance: instanceName,
settings: {
tier: "db-f1-micro",
ipConfiguration: {
Expand All @@ -31,15 +21,13 @@ export const instance = new gcloud.sqladmin.v1beta4.Instance("web-db", {
const dbName = "app_development";
export const db = new gcloud.sqladmin.v1beta4.Database("db", {
name: dbName,
database: dbName,
instance: instance.name,
project: project,
});

const testDbName = "app_test";
export const testDb = new gcloud.sqladmin.v1beta4.Database("testdb", {
name: testDbName,
database: testDbName,
instance: instance.name,
project: project,
}, {dependsOn: [db]}); // only create one db at a time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"@types/node": "^8.0.0"
},
"dependencies": {
"@pulumi/docker": "^2.0.0",
"@pulumi/docker": "^3.0.0",
"@pulumi/gcp": "^4.21.0",
"@pulumi/google-native": "^0.1.0",
"@pulumi/kubernetes": "^2.0.0",
"@pulumi/google-native": "^0.7.0",
"@pulumi/kubernetes": "^3.0.0",
"@pulumi/pulumi": "^3.0.0",
"@pulumi/random": "^3.2.0"
"@pulumi/random": "^4.0.0"
}
}

0 comments on commit 830494c

Please sign in to comment.