Pulumi's Policy as Code SDK, CrossGuard. Define infrastructure checks in code to enforce security, compliance, cost, and other practices, enforced at deployment time.
import * as docker from "@pulumi/docker";
const resolve = require('path').resolve;
const addDockerfileAbsPath = (args: any) => {
// TODO: Could we move this function to an export in the Policy Pack if we
// were to publish it as an npm package like compliance ready policies?
// That way, we could do:
// transformations: [snykPolicy.addDockerfilePath]
if (args.props["build"]?.dockerfile === undefined) {
// There's no path to a Dockerfile, so there's nothing to verify
return args;
}
const context = args.props["build"]?.context as string ?? ".";
const dockerfile = args.props["build"].dockerfile as string;
const localPath = `${context}/${dockerfile}`;
const absPath = resolve(localPath);
args.props["snyk"] = {};
args.props["snyk"]["dockerfileAbsPath"] = absPath;
return args;
};
new docker.Image("good-image", {
imageName: "docker.io/joshkodroff/snyk-policy-good-image",
buildOnPreview: true,
build: {
dockerfile: "GoodDockerfile",
platform: "linux/arm64",
},
}, {
transformations: [addDockerfileAbsPath]
});
CLI
Version 3.109.0
Go Version go1.22.1
Go Compiler gc
Plugins
NAME VERSION
docker 4.5.1
nodejs unknown
Host
OS darwin
Version 14.3.1
Arch arm64
This project is written in nodejs: executable='/opt/homebrew/bin/node' version='v21.2.0'
Current Stack: jkodrofftest/demo-pulumi-policy-snyk/dev
Found no resources associated with dev
Found no pending operations associated with dev
Backend
Name pulumi.com
URL https://app.pulumi.com/josh-pulumi-corp
User josh-pulumi-corp
Organizations josh-pulumi-corp, pulumi-gitlab-demo2, jkodrofftest, zephyr, pulumi
Token type personal
Dependencies:
NAME VERSION
@pulumi/docker 4.5.1
@pulumi/pulumi 3.105.0
@types/node 18.19.15
Pulumi locates its logs in /var/folders/5m/4n1x3f8151s35wc80w06z5k80000gn/T/ by default
Additional context
No response
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
What happened?
I have a transform which adds an arbitrary property to a resource. The added property is available in a resource policy, but not a stack policy:
Stack policy:
Resource policy:
Example
Pulumi program:
Policy:
Output of
pulumi about
Additional context
No response
Contributing
Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).