Skip to content

Commit

Permalink
Merge pull request #217 from nitrictech/feature/gcp-secret-access
Browse files Browse the repository at this point in the history
GCP: update cloud run account permissions.
  • Loading branch information
tjholm authored Oct 18, 2021
2 parents 191582f + 004bd32 commit 836f9ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/plugins/gcp/src/resources/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class NitricComputeCloudRun extends pulumi.ComponentResource {
public readonly name: string;
public readonly cloudrun: gcp.cloudrun.Service;
public readonly url: pulumi.Output<string>;
public readonly account: gcp.serviceaccount.Account;

constructor(name: string, args: NitricComputeCloudRunArgs, opts?: pulumi.ComponentResourceOptions) {
super('nitric:func:CloudRun', name, {}, opts);
Expand All @@ -42,6 +43,26 @@ export class NitricComputeCloudRun extends pulumi.ComponentResource {

this.name = source.getName();

// Create a service account for this cloud run instance
this.account = new gcp.serviceaccount.Account(`${name}-acct`, {
accountId: `${name}-acct`.substring(0, 30),
});

// Give project editor permissions
// FIXME: Trim this down
new gcp.projects.IAMMember(`${name}-editor`, {
role: 'roles/editor',
// Get the cloudrun service account email
member: pulumi.interpolate`serviceAccount:${this.account.email}`,
});

// Give secret accessor permissions
new gcp.projects.IAMMember(`${name}-secret-access`, {
role: 'roles/secretmanager.secretAccessor',
// Get the cloudrun service account email
member: pulumi.interpolate`serviceAccount:${this.account.email}`,
});

// Deploy the func
this.cloudrun = new gcp.cloudrun.Service(
source.getName(),
Expand All @@ -55,6 +76,7 @@ export class NitricComputeCloudRun extends pulumi.ComponentResource {
},
},
spec: {
serviceAccountName: this.account.email,
containers: [
{
image: image.imageUri,
Expand Down
6 changes: 5 additions & 1 deletion packages/plugins/gcp/src/tasks/down/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export class Down extends Task<void> {
.filter((resource) => !nonTargets.includes(resource.type))
.map((resource) => resource.urn);
if (targets.length > 0) {
res = await pulumiStack.destroy({ onOutput: this.update.bind(this), target: targets });
res = await pulumiStack.destroy({
onOutput: this.update.bind(this),
target: targets,
targetDependents: true,
});
}
}
console.log(res);
Expand Down

0 comments on commit 836f9ed

Please sign in to comment.