UNPKG

@pulumi/gcp

Version:

A Pulumi package for creating and managing Google Cloud Platform resources.

198 lines • 8.16 kB
"use strict"; // *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Document = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * In Cloud Firestore, the unit of storage is the document. A document is a lightweight record * that contains fields, which map to values. Each document is identified by a name. * * To get more information about Document, see: * * * [API documentation](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) * * How-to Guides * * [Official Documentation](https://cloud.google.com/firestore/docs/manage-data/add-data) * * > **Warning:** This resource creates a Firestore Document on a project that already has * a Firestore database. If you haven't already created it, you may * create a `gcp.firestore.Database` resource with `type` set to * `"FIRESTORE_NATIVE"` and `locationId` set to your chosen location. * If you wish to use App Engine, you may instead create a * `gcp.appengine.Application` resource with `databaseType` set to * `"CLOUD_FIRESTORE"`. Your Firestore location will be the same as * the App Engine location specified. * * ## Example Usage * * ### Firestore Document Basic * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as time from "@pulumi/time"; * * const project = new gcp.organizations.Project("project", { * projectId: "project-id", * name: "project-id", * orgId: "123456789", * deletionPolicy: "DELETE", * }); * const wait60Seconds = new time.index.Sleep("wait_60_seconds", {createDuration: "60s"}, { * dependsOn: [project], * }); * const firestore = new gcp.projects.Service("firestore", { * project: project.projectId, * service: "firestore.googleapis.com", * }, { * dependsOn: [wait60Seconds], * }); * const database = new gcp.firestore.Database("database", { * project: project.projectId, * name: "(default)", * locationId: "nam5", * type: "FIRESTORE_NATIVE", * }, { * dependsOn: [firestore], * }); * const mydoc = new gcp.firestore.Document("mydoc", { * project: project.projectId, * database: database.name, * collection: "somenewcollection", * documentId: "my-doc-id", * fields: "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}", * }); * ``` * ### Firestore Document Nested Document * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as time from "@pulumi/time"; * * const project = new gcp.organizations.Project("project", { * projectId: "project-id", * name: "project-id", * orgId: "123456789", * deletionPolicy: "DELETE", * }); * const wait60Seconds = new time.index.Sleep("wait_60_seconds", {createDuration: "60s"}, { * dependsOn: [project], * }); * const firestore = new gcp.projects.Service("firestore", { * project: project.projectId, * service: "firestore.googleapis.com", * }, { * dependsOn: [wait60Seconds], * }); * const database = new gcp.firestore.Database("database", { * project: project.projectId, * name: "(default)", * locationId: "nam5", * type: "FIRESTORE_NATIVE", * }, { * dependsOn: [firestore], * }); * const mydoc = new gcp.firestore.Document("mydoc", { * project: project.projectId, * database: database.name, * collection: "somenewcollection", * documentId: "my-doc-id", * fields: "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}", * }); * const subDocument = new gcp.firestore.Document("sub_document", { * project: project.projectId, * database: database.name, * collection: pulumi.interpolate`${mydoc.path}/subdocs`, * documentId: "bitcoinkey", * fields: "{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}", * }); * const subSubDocument = new gcp.firestore.Document("sub_sub_document", { * project: project.projectId, * database: database.name, * collection: pulumi.interpolate`${subDocument.path}/subsubdocs`, * documentId: "asecret", * fields: "{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}", * }); * ``` * * ## Import * * Document can be imported using any of these accepted formats: * * * `{{name}}` * * When using the `pulumi import` command, Document can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:firestore/document:Document default {{name}} * ``` */ class Document extends pulumi.CustomResource { /** * Get an existing Document 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 Document(name, state, Object.assign(Object.assign({}, opts), { id: id })); } /** * Returns true if the given object is an instance of Document. 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'] === Document.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["collection"] = state ? state.collection : undefined; resourceInputs["createTime"] = state ? state.createTime : undefined; resourceInputs["database"] = state ? state.database : undefined; resourceInputs["documentId"] = state ? state.documentId : undefined; resourceInputs["fields"] = state ? state.fields : undefined; resourceInputs["name"] = state ? state.name : undefined; resourceInputs["path"] = state ? state.path : undefined; resourceInputs["project"] = state ? state.project : undefined; resourceInputs["updateTime"] = state ? state.updateTime : undefined; } else { const args = argsOrState; if ((!args || args.collection === undefined) && !opts.urn) { throw new Error("Missing required property 'collection'"); } if ((!args || args.documentId === undefined) && !opts.urn) { throw new Error("Missing required property 'documentId'"); } if ((!args || args.fields === undefined) && !opts.urn) { throw new Error("Missing required property 'fields'"); } resourceInputs["collection"] = args ? args.collection : undefined; resourceInputs["database"] = args ? args.database : undefined; resourceInputs["documentId"] = args ? args.documentId : undefined; resourceInputs["fields"] = args ? args.fields : undefined; resourceInputs["project"] = args ? args.project : undefined; resourceInputs["createTime"] = undefined /*out*/; resourceInputs["name"] = undefined /*out*/; resourceInputs["path"] = undefined /*out*/; resourceInputs["updateTime"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(Document.__pulumiType, name, resourceInputs, opts); } } exports.Document = Document; /** @internal */ Document.__pulumiType = 'gcp:firestore/document:Document'; //# sourceMappingURL=document.js.map