@pulumi/gcp
Version:
A Pulumi package for creating and managing Google Cloud Platform resources.
241 lines • 8.36 kB
JavaScript
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.Policy = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Defines an organization policy which is used to specify constraints for configurations of Google Cloud resources.
*
* To get more information about Policy, see:
*
* * [API documentation](https://cloud.google.com/resource-manager/docs/reference/orgpolicy/rest/v2/organizations.policies)
* * How-to Guides
* * [Official Documentation](https://cloud.google.com/resource-manager/docs/organization-policy/creating-managing-custom-constraints)
* * [Supported Services](https://cloud.google.com/resource-manager/docs/organization-policy/custom-constraint-supported-services)
*
* ## Example Usage
*
* ### Org Policy Policy Enforce
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const basic = new gcp.organizations.Project("basic", {
* projectId: "id",
* name: "id",
* orgId: "123456789",
* deletionPolicy: "DELETE",
* });
* const primary = new gcp.orgpolicy.Policy("primary", {
* name: pulumi.interpolate`projects/${basic.projectId}/policies/iam.disableServiceAccountKeyUpload`,
* parent: pulumi.interpolate`projects/${basic.projectId}`,
* spec: {
* rules: [{
* enforce: "FALSE",
* }],
* },
* });
* ```
* ### Org Policy Policy Folder
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const basic = new gcp.organizations.Folder("basic", {
* parent: "organizations/123456789",
* displayName: "folder",
* deletionProtection: false,
* });
* const primary = new gcp.orgpolicy.Policy("primary", {
* name: pulumi.interpolate`${basic.name}/policies/gcp.resourceLocations`,
* parent: basic.name,
* spec: {
* inheritFromParent: true,
* rules: [{
* denyAll: "TRUE",
* }],
* },
* });
* ```
* ### Org Policy Policy Organization
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const primary = new gcp.orgpolicy.Policy("primary", {
* name: "organizations/123456789/policies/gcp.detailedAuditLoggingMode",
* parent: "organizations/123456789",
* spec: {
* reset: true,
* },
* });
* ```
* ### Org Policy Policy Project
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const basic = new gcp.organizations.Project("basic", {
* projectId: "id",
* name: "id",
* orgId: "123456789",
* deletionPolicy: "DELETE",
* });
* const primary = new gcp.orgpolicy.Policy("primary", {
* name: pulumi.interpolate`projects/${basic.projectId}/policies/gcp.resourceLocations`,
* parent: pulumi.interpolate`projects/${basic.projectId}`,
* spec: {
* rules: [
* {
* condition: {
* description: "A sample condition for the policy",
* expression: "resource.matchTagId('tagKeys/123', 'tagValues/345')",
* location: "sample-location.log",
* title: "sample-condition",
* },
* values: {
* allowedValues: ["projects/allowed-project"],
* deniedValues: ["projects/denied-project"],
* },
* },
* {
* allowAll: "TRUE",
* },
* ],
* },
* });
* ```
* ### Org Policy Policy Dry Run Spec
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const constraint = new gcp.orgpolicy.CustomConstraint("constraint", {
* name: "custom.disableGkeAutoUpgrade_8647",
* parent: "organizations/123456789",
* displayName: "Disable GKE auto upgrade",
* description: "Only allow GKE NodePool resource to be created or updated if AutoUpgrade is not enabled where this custom constraint is enforced.",
* actionType: "ALLOW",
* condition: "resource.management.autoUpgrade == false",
* methodTypes: ["CREATE"],
* resourceTypes: ["container.googleapis.com/NodePool"],
* });
* const primary = new gcp.orgpolicy.Policy("primary", {
* name: pulumi.interpolate`organizations/123456789/policies/${constraint.name}`,
* parent: "organizations/123456789",
* spec: {
* rules: [{
* enforce: "FALSE",
* }],
* },
* dryRunSpec: {
* inheritFromParent: false,
* reset: false,
* rules: [{
* enforce: "FALSE",
* }],
* },
* });
* ```
* ### Org Policy Policy Parameters Enforce
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const basic = new gcp.organizations.Project("basic", {
* projectId: "id",
* name: "id",
* orgId: "123456789",
* deletionPolicy: "DELETE",
* });
* const primary = new gcp.orgpolicy.Policy("primary", {
* name: pulumi.interpolate`projects/${basic.name}/policies/compute.managed.restrictDiskCreation`,
* parent: pulumi.interpolate`projects/${basic.name}`,
* spec: {
* rules: [{
* enforce: "TRUE",
* parameters: JSON.stringify({
* isSizeLimitCheck: true,
* allowedDiskTypes: [
* "pd-ssd",
* "pd-standard",
* ],
* }),
* }],
* },
* });
* ```
*
* ## Import
*
* Policy can be imported using any of these accepted formats:
*
* * `{{parent}}/policies/{{name}}`
*
* When using the `pulumi import` command, Policy can be imported using one of the formats above. For example:
*
* ```sh
* $ pulumi import gcp:orgpolicy/policy:Policy default {{parent}}/policies/{{name}}
* ```
*/
class Policy extends pulumi.CustomResource {
/**
* Get an existing Policy resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new Policy(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of Policy. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === Policy.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["dryRunSpec"] = state?.dryRunSpec;
resourceInputs["etag"] = state?.etag;
resourceInputs["name"] = state?.name;
resourceInputs["parent"] = state?.parent;
resourceInputs["spec"] = state?.spec;
}
else {
const args = argsOrState;
if (args?.parent === undefined && !opts.urn) {
throw new Error("Missing required property 'parent'");
}
resourceInputs["dryRunSpec"] = args?.dryRunSpec;
resourceInputs["name"] = args?.name;
resourceInputs["parent"] = args?.parent;
resourceInputs["spec"] = args?.spec;
resourceInputs["etag"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(Policy.__pulumiType, name, resourceInputs, opts);
}
}
exports.Policy = Policy;
/** @internal */
Policy.__pulumiType = 'gcp:orgpolicy/policy:Policy';
//# sourceMappingURL=policy.js.map
;