UNPKG

@pulumi/gcp

Version:

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

476 lines • 18 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Environment = void 0; const pulumi = __importStar(require("@pulumi/pulumi")); const utilities = __importStar(require("../utilities")); /** * An environment for running orchestration tasks. * * Environments run Apache Airflow software on Google infrastructure. * * To get more information about Environments, see: * * * [Managed Service for Apache Airflow documentation](https://docs.cloud.google.com/composer/docs) * * [Managed Airflow API documentation](https://docs.cloud.google.com/composer/docs/reference/rest/v1beta1/projects.locations.environments) * * How-to Guides for Managed Airflow (Gen 3) * * [Creating environments](https://docs.cloud.google.com/composer/docs/composer-3/create-environments) * * [Scaling environments](https://docs.cloud.google.com/composer/docs/composer-3/scale-environments) * * [Change environment networking type (Private or Public IP)](https://docs.cloud.google.com/composer/docs/composer-3/change-networking-type) * * [Connect an environment to a VPC network](https://docs.cloud.google.com/composer/docs/composer-3/connect-vpc-network) * * How-to Guides for Managed Airflow (Gen 2) * * [Creating environments](https://docs.cloud.google.com/composer/docs/composer-2/create-environments) * * [Scaling environments](https://docs.cloud.google.com/composer/docs/composer-2/scale-environments) * * [Configuring Shared VPC](https://docs.cloud.google.com/composer/docs/composer-2/configure-shared-vpc) * * [Apache Airflow Documentation](http://airflow.apache.org/) * * > **Note** * Managed Airflow (Legacy Gen 1) is in the post-maintenance mode. Google * doesn't release any further updates to Managed Service for * Managed Airflow (Legacy Gen 1), including new versions of Airflow, bugfixes, * and security updates. We recommend using Managed Airflow (Gen 3) or * Managed Airflow (Gen 2) instead. * * Several special considerations apply to using Terraform with * Managed Service for Apache Airflow: * * * The Environment resource is based on several layers of Google Cloud * infrastructure. Terraform doesn't manage these underlying resources. For * example, in Managed Airflow (Gen 2), this includes a Google Kubernetes * Engine cluster, Cloud Storage, and Compute networking resources. * * Creating or updating an environment usually takes around 25 minutes. * * In some cases, errors in the configuration are detected and reported only * during the process of environment creation. If you encounter such * errors, please verify that your configuration is valid for the Managed * Airflow environment you are creating before filing bugs for the Terraform * provider. * * **Environments have Google Cloud Storage buckets that are not automatically * deleted** with the environment. * See [Delete environments](https://docs.cloud.google.com/composer/docs/composer-3/delete-environments) * for more information. * * See * [Troubleshooting pages](https://docs.cloud.google.com/composer/docs/composer-3/troubleshooting-environment-creation) * if you encounter problems. * * ## Example Usage * * ### Basic usage in Managed Airflow (Gen 3) * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const test = new gcp.composer.Environment("test", { * name: "example-composer-env", * region: "us-central1", * config: { * softwareConfig: { * imageVersion: "composer-3-airflow-2", * }, * }, * }); * ``` * * ### Basic usage in Managed Airflow (Gen 2) * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const test = new gcp.composer.Environment("test", { * name: "example-composer-env", * region: "us-central1", * config: { * softwareConfig: { * imageVersion: "composer-2-airflow-2", * }, * }, * }); * ``` * * ### Basic Usage in Managed Airflow (Legacy Gen 1) * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const test = new gcp.composer.Environment("test", { * name: "example-composer-env", * region: "us-central1", * config: { * softwareConfig: { * imageVersion: "composer-1-airflow-2", * }, * }, * }); * ``` * * ### With environment resources configuration * * > **Note** * To use custom service accounts, you must give at least the * `role/composer.worker` role to the service account of the Managed Airflow * environment. For more information, see the * [Access Control](https://docs.cloud.google.com/composer/docs/composer-3/access-control) * page in the Managed Airflow documentation. * You might need to assign additional roles depending on specific workflows * that the Airflow DAGs will be running. * * ### Environment resources configuration in Managed Airflow (Gen 3) * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const testAccount = new gcp.serviceaccount.Account("test", { * accountId: "composer-env-account", * displayName: "Test Service Account for Managed Airflow Environment", * }); * const test = new gcp.composer.Environment("test", { * name: "example-composer-env-tf-c3", * region: "us-central1", * config: { * softwareConfig: { * imageVersion: "composer-3-airflow-2", * }, * workloadsConfig: { * scheduler: { * cpu: 0.5, * memoryGb: 2, * storageGb: 1, * count: 1, * }, * triggerer: { * cpu: 0.5, * memoryGb: 1, * count: 1, * }, * dagProcessor: { * cpu: 1, * memoryGb: 2, * storageGb: 1, * count: 1, * }, * webServer: { * cpu: 0.5, * memoryGb: 2, * storageGb: 1, * }, * worker: { * cpu: 0.5, * memoryGb: 2, * storageGb: 1, * minCount: 1, * maxCount: 3, * }, * }, * environmentSize: "ENVIRONMENT_SIZE_SMALL", * nodeConfig: { * serviceAccount: testAccount.name, * }, * }, * }); * const composer_worker = new gcp.projects.IAMMember("composer-worker", { * project: "your-project-id", * role: "roles/composer.worker", * member: pulumi.interpolate`serviceAccount:${testAccount.email}`, * }); * ``` * * ### Environment resources configuration in Managed Airflow (Gen 2) * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const testNetwork = new gcp.compute.Network("test", { * name: "composer-test-network3", * autoCreateSubnetworks: false, * }); * const testSubnetwork = new gcp.compute.Subnetwork("test", { * name: "composer-test-subnetwork", * ipCidrRange: "10.2.0.0/16", * region: "us-central1", * network: testNetwork.id, * }); * const testAccount = new gcp.serviceaccount.Account("test", { * accountId: "composer-env-account", * displayName: "Test Service Account for Managed Airflow", * }); * const test = new gcp.composer.Environment("test", { * name: "example-composer-env-tf-c2", * region: "us-central1", * config: { * softwareConfig: { * imageVersion: "composer-2-airflow-2", * }, * workloadsConfig: { * scheduler: { * cpu: 0.5, * memoryGb: 1.875, * storageGb: 1, * count: 1, * }, * webServer: { * cpu: 0.5, * memoryGb: 1.875, * storageGb: 1, * }, * worker: { * cpu: 0.5, * memoryGb: 1.875, * storageGb: 1, * minCount: 1, * maxCount: 3, * }, * }, * environmentSize: "ENVIRONMENT_SIZE_SMALL", * nodeConfig: { * network: testNetwork.id, * subnetwork: testSubnetwork.id, * serviceAccount: testAccount.name, * }, * }, * }); * const composer_worker = new gcp.projects.IAMMember("composer-worker", { * project: "your-project-id", * role: "roles/composer.worker", * member: pulumi.interpolate`serviceAccount:${testAccount.email}`, * }); * ``` * * ### Environment resources configuration in Managed Airflow (Legacy Gen 1) * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const testNetwork = new gcp.compute.Network("test", { * name: "composer-test-network", * autoCreateSubnetworks: false, * }); * const testSubnetwork = new gcp.compute.Subnetwork("test", { * name: "composer-test-subnetwork", * ipCidrRange: "10.2.0.0/16", * region: "us-central1", * network: testNetwork.id, * }); * const testAccount = new gcp.serviceaccount.Account("test", { * accountId: "composer-env-account", * displayName: "Test Service Account for Managed Airflow", * }); * const test = new gcp.composer.Environment("test", { * name: "example-composer-env", * region: "us-central1", * config: { * softwareConfig: { * imageVersion: "composer-1-airflow-2", * }, * nodeCount: 4, * nodeConfig: { * zone: "us-central1-a", * machineType: "n1-standard-1", * network: testNetwork.id, * subnetwork: testSubnetwork.id, * serviceAccount: testAccount.name, * }, * databaseConfig: { * machineType: "db-n1-standard-2", * }, * webServerConfig: { * machineType: "composer-n1-webserver-2", * }, * }, * }); * const composer_worker = new gcp.projects.IAMMember("composer-worker", { * role: "roles/composer.worker", * member: pulumi.interpolate`serviceAccount:${testAccount.email}`, * }); * ``` * * ### Networking configuration in Managed Airflow (Gen 3) * * In Managed Airflow (Gen 3), networking configuration is simplified compared to * previous versions. You don't need to specify network ranges, and can attach * custom VPC networks to your environment. * * > **Note** * It's not possible to detach a VPC network using Terraform. Instead, you can * attach a different VPC network in its place, or detach the network using * other tools like Google Cloud CLI. * * Use Private IP networking: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.composer.Environment("example", { * name: "example-environment", * region: "us-central1", * config: { * enablePrivateEnvironment: true, * }, * }); * ``` * * Attach a custom VPC network (Managed Airflow creates a new network attachment): * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.composer.Environment("example", { * name: "example-environment", * region: "us-central1", * config: { * nodeConfig: { * network: "projects/example-project/global/networks/example-network", * subnetwork: "projects/example-project/regions/us-central1/subnetworks/example-subnetwork", * }, * }, * }); * ``` * * Attach a custom VPC network (use an existing network attachment): * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.composer.Environment("example", { * name: "example-environment", * region: "us-central1", * config: { * nodeConfig: { * composerNetworkAttachment: String(Number(projects) / Number(example_project) / Number(regions) / Number(us_central1) / Number(networkAttachments) / Number(example_network_attachment)), * }, * }, * }); * ``` * * If you specify an existing network attachment that you also manage in * Terraform, then Terraform will revert changes to the attachment that were done * by Managed Airflow when you apply configuration changes. As a result, the * environment will no longer use the attachment. To address this, make sure that * Terraform ignores changes to the `producerAcceptLists` parameter of the * attachment, as follows: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const example = new gcp.compute.NetworkAttachment("example", {}); * const exampleEnvironment = new gcp.composer.Environment("example", { * name: "example-environment", * region: "us-central1", * config: { * nodeConfig: { * composerNetworkAttachment: example.id, * }, * }, * }); * ``` * * ## Import * * Environment can be imported using any of these accepted formats: * * * `projects/{{project}}/locations/{{region}}/environments/{{name}}` * * `{{project}}/{{region}}/{{name}}` * * `{{name}}` * * When using the * `pulumi import` command, * Environment can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:composer/environment:Environment default projects/{{project}}/locations/{{region}}/environments/{{name}} * $ pulumi import gcp:composer/environment:Environment default {{project}}/{{region}}/{{name}} * $ pulumi import gcp:composer/environment:Environment default {{name}} * ``` */ class Environment extends pulumi.CustomResource { /** * Get an existing Environment 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 Environment(name, state, { ...opts, id: id }); } /** @internal */ static __pulumiType = 'gcp:composer/environment:Environment'; /** * Returns true if the given object is an instance of Environment. 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'] === Environment.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["config"] = state?.config; resourceInputs["deletionPolicy"] = state?.deletionPolicy; resourceInputs["effectiveLabels"] = state?.effectiveLabels; resourceInputs["labels"] = state?.labels; resourceInputs["name"] = state?.name; resourceInputs["project"] = state?.project; resourceInputs["pulumiLabels"] = state?.pulumiLabels; resourceInputs["region"] = state?.region; resourceInputs["storageConfig"] = state?.storageConfig; } else { const args = argsOrState; resourceInputs["config"] = args?.config; resourceInputs["deletionPolicy"] = args?.deletionPolicy; resourceInputs["labels"] = args?.labels; resourceInputs["name"] = args?.name; resourceInputs["project"] = args?.project; resourceInputs["region"] = args?.region; resourceInputs["storageConfig"] = args?.storageConfig; resourceInputs["effectiveLabels"] = undefined /*out*/; resourceInputs["pulumiLabels"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const secretOpts = { additionalSecretOutputs: ["effectiveLabels", "pulumiLabels"] }; opts = pulumi.mergeOptions(opts, secretOpts); super(Environment.__pulumiType, name, resourceInputs, opts); } } exports.Environment = Environment; //# sourceMappingURL=environment.js.map