The Simplest Way to Make Cloud Functions and Pulumi Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair cloud functions and pulumi to deploy event-driven code with standard programming languages. Pulumi packages your source code, sets up cloud roles, and manages the function lifecycle. This workflow keeps your app logic and cloud rules in one repo. Your team reviews one pull request to update both code and cloud resources. You avoid manual clicks in web consoles and keep every test setup matching production. How cloud functions and pulumi handle roles and data Two distinct roles exist

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You pair cloud functions and pulumi to deploy event-driven code with standard programming languages. Pulumi packages your source code, sets up cloud roles, and manages the function lifecycle.

This workflow keeps your app logic and cloud rules in one repo. Your team reviews one pull request to update both code and cloud resources. You avoid manual clicks in web consoles and keep every test setup matching production.

How cloud functions and pulumi handle roles and data

Two distinct roles exist when you run cloud functions and pulumi in production. First, the deploy tool needs a role to build and update the function. Second, the function needs its own runtime role to read databases or queues.

During a deploy, Pulumi reads your local code and compresses it into an archive. It uploads that archive to a cloud storage bucket that it also manages. Then it tells the cloud provider API to point the function to that file.

Data flows through state files during this step. Pulumi tracks the bucket name, the archive hash, and the function URL. If you change a line of app code, the archive hash changes too. Pulumi sees this change and updates the live function on the next run.

At runtime, the deploy tool is no longer in the picture. An HTTP request or a queue message wakes up the cloud function. The function uses its assigned runtime role to talk to other cloud services. It reads secrets or writes data based on the rules Pulumi set up.

Common failure modes and how to scope access

Teams often mix up deploy roles and runtime roles when they move fast. They might give the deploy tool a broad admin key that never expires. Worse, they might attach the default compute service account to the running function. If an attacker exploits that function, they gain broad rights across your cloud project.

Another common bug happens when secret keys leak into the Pulumi state file. If you pass raw database passwords as plain text variables, they sit in state. Anyone who can read the state backend can read those production keys.

Cloud Functions IAM + Pulumi Policy as Code: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix role bloat by creating one dedicated service account per function. Use Pulumi to create the account and bind it to the single function. Grant that account rights to read only the exact storage bucket or table needed.

For deploy tasks, drop static keys and use workload identity federation instead. Your CI runner trades a short token from your git host for cloud rights. You should also wrap every secret value in the built-in secret helper function. This encrypts the value inside the state file and hides it in build logs.

Managing network paths and database connections

Cloud functions run on shared networks by default and cannot reach private databases. Teams sometimes open database ports to the public internet to make tests pass. This exposes internal data stores to external brute force attacks and network scans.

Instead, define a virtual network connector inside your Pulumi stack. Attach the function to that connector and route only private traffic through it. Then set firewall rules so the database accepts traffic only from that connector subnet.

When functions scale up fast, they can also exhaust database connection pools. Each new function instance opens its own network socket to the database server. You can cap the maximum instance count in your Pulumi code to protect downstream systems. You should also log every database query and role check for security audits. Masking rewrites matched fields in results, like emails, phone numbers, card numbers, or national IDs.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should I keep function code and Pulumi code in the same repository?

Yes, keeping both in one repo works best for most engineering teams. It lets you update a function and its cloud permissions in a single commit.

How do I stop Pulumi from redeploying functions when nothing changed?

Make sure your build script outputs deterministic zip files without changing file timestamps. Exclude local dependency folders and temp files from the archive folder path.

How should cloud functions read database passwords at runtime?

Store the password in a cloud secret manager using a Pulumi secret resource. Grant the function runtime role permission to read only that specific secret entry.

The query runs. The emails stay hidden.