UNPKG

@pulumi/gcp

Version:

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

425 lines • 16.3 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.ConnectionProfile = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * A set of reusable connection configurations to be used as a source or destination for a stream. * * To get more information about ConnectionProfile, see: * * * [API documentation](https://cloud.google.com/datastream/docs/reference/rest/v1/projects.locations.connectionProfiles) * * How-to Guides * * [Official Documentation](https://cloud.google.com/datastream/docs/create-connection-profiles) * * ## Example Usage * * ### Datastream Connection Profile Basic * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.datastream.ConnectionProfile("default", { * displayName: "Connection profile", * location: "us-central1", * connectionProfileId: "my-profile", * gcsProfile: { * bucket: "my-bucket", * rootPath: "/path", * }, * }); * ``` * ### Datastream Connection Profile Postgresql Private Connection * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as random from "@pulumi/random"; * * const _default = new gcp.compute.Network("default", { * name: "my-network", * autoCreateSubnetworks: false, * }); * const defaultSubnetwork = new gcp.compute.Subnetwork("default", { * name: "my-subnetwork", * ipCidrRange: "10.1.0.0/16", * region: "us-central1", * network: _default.id, * }); * const privateConnection = new gcp.datastream.PrivateConnection("private_connection", { * displayName: "Private connection", * location: "us-central1", * privateConnectionId: "my-connection", * vpcPeeringConfig: { * vpc: _default.id, * subnet: "10.0.0.0/29", * }, * }); * const natVmIp = new gcp.compute.Address("nat_vm_ip", {name: "nat-vm-ip"}); * const instance = new gcp.sql.DatabaseInstance("instance", { * name: "my-instance", * databaseVersion: "POSTGRES_14", * region: "us-central1", * settings: { * tier: "db-f1-micro", * ipConfiguration: { * authorizedNetworks: [{ * value: natVmIp.address, * }], * }, * }, * deletionProtection: true, * }); * const db = new gcp.sql.Database("db", { * instance: instance.name, * name: "db", * }); * const pwd = new random.RandomPassword("pwd", { * length: 16, * special: false, * }); * const user = new gcp.sql.User("user", { * name: "user", * instance: instance.name, * password: pwd.result, * }); * const natVm = new gcp.compute.Instance("nat_vm", { * name: "nat-vm", * machineType: "e2-medium", * zone: "us-central1-a", * desiredStatus: "RUNNING", * bootDisk: { * initializeParams: { * image: "debian-cloud/debian-12", * }, * }, * networkInterfaces: [{ * network: privateConnection.vpcPeeringConfig.apply(vpcPeeringConfig => vpcPeeringConfig.vpc), * subnetwork: defaultSubnetwork.selfLink, * accessConfigs: [{ * natIp: natVmIp.address, * }], * }], * metadataStartupScript: pulumi.interpolate`#! /bin/bash * # See https://cloud.google.com/datastream/docs/private-connectivity#set-up-reverse-proxy * export DB_ADDR=${instance.publicIpAddress} * export DB_PORT=5432 * echo 1 > /proc/sys/net/ipv4/ip_forward * md_url_prefix="http://169.254.169.254/computeMetadata/v1/instance" * vm_nic_ip="$(curl -H "Metadata-Flavor: Google" ${md_url_prefix}/network-interfaces/0/ip)" * iptables -t nat -F * iptables -t nat -A PREROUTING \ * -p tcp --dport $DB_PORT \ * -j DNAT \ * --to-destination $DB_ADDR * iptables -t nat -A POSTROUTING \ * -p tcp --dport $DB_PORT \ * -j SNAT \ * --to-source $vm_nic_ip * iptables-save * `, * }); * const rules = new gcp.compute.Firewall("rules", { * name: "ingress-rule", * network: privateConnection.vpcPeeringConfig.apply(vpcPeeringConfig => vpcPeeringConfig.vpc), * description: "Allow traffic into NAT VM", * direction: "INGRESS", * allows: [{ * protocol: "tcp", * ports: ["5432"], * }], * sourceRanges: [privateConnection.vpcPeeringConfig.apply(vpcPeeringConfig => vpcPeeringConfig.subnet)], * }); * const defaultConnectionProfile = new gcp.datastream.ConnectionProfile("default", { * displayName: "Connection profile", * location: "us-central1", * connectionProfileId: "my-profile", * postgresqlProfile: { * hostname: natVm.networkInterfaces.apply(networkInterfaces => networkInterfaces[0].networkIp), * username: user.name, * password: user.password, * database: db.name, * port: 5432, * }, * privateConnectivity: { * privateConnection: privateConnection.id, * }, * }); * ``` * ### Datastream Connection Profile Full * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.datastream.ConnectionProfile("default", { * displayName: "Connection profile", * location: "us-central1", * connectionProfileId: "my-profile", * gcsProfile: { * bucket: "my-bucket", * rootPath: "/path", * }, * forwardSshConnectivity: { * hostname: "google.com", * username: "my-user", * port: 8022, * password: "swordfish", * }, * labels: { * key: "value", * }, * }); * ``` * ### Datastream Connection Profile Postgres * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as random from "@pulumi/random"; * * const instance = new gcp.sql.DatabaseInstance("instance", { * name: "my-instance", * databaseVersion: "POSTGRES_14", * region: "us-central1", * settings: { * tier: "db-f1-micro", * ipConfiguration: { * authorizedNetworks: [ * { * value: "34.71.242.81", * }, * { * value: "34.72.28.29", * }, * { * value: "34.67.6.157", * }, * { * value: "34.67.234.134", * }, * { * value: "34.72.239.218", * }, * ], * }, * }, * deletionProtection: true, * }); * const db = new gcp.sql.Database("db", { * instance: instance.name, * name: "db", * }); * const pwd = new random.RandomPassword("pwd", { * length: 16, * special: false, * }); * const user = new gcp.sql.User("user", { * name: "user", * instance: instance.name, * password: pwd.result, * }); * const _default = new gcp.datastream.ConnectionProfile("default", { * displayName: "Connection profile", * location: "us-central1", * connectionProfileId: "my-profile", * postgresqlProfile: { * hostname: instance.publicIpAddress, * username: user.name, * password: user.password, * database: db.name, * }, * }); * ``` * ### Datastream Connection Profile Sql Server * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const instance = new gcp.sql.DatabaseInstance("instance", { * name: "sql-server", * databaseVersion: "SQLSERVER_2019_STANDARD", * region: "us-central1", * rootPassword: "root-password", * deletionProtection: true, * settings: { * tier: "db-custom-2-4096", * ipConfiguration: { * authorizedNetworks: [ * { * value: "34.71.242.81", * }, * { * value: "34.72.28.29", * }, * { * value: "34.67.6.157", * }, * { * value: "34.67.234.134", * }, * { * value: "34.72.239.218", * }, * ], * }, * }, * }); * const db = new gcp.sql.Database("db", { * name: "db", * instance: instance.name, * }); * const user = new gcp.sql.User("user", { * name: "user", * instance: instance.name, * password: "password", * }); * const _default = new gcp.datastream.ConnectionProfile("default", { * displayName: "SQL Server Source", * location: "us-central1", * connectionProfileId: "source-profile", * sqlServerProfile: { * hostname: instance.publicIpAddress, * port: 1433, * username: user.name, * password: user.password, * database: db.name, * }, * }); * ``` * ### Datastream Connection Profile Postgres Secret Manager * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.datastream.ConnectionProfile("default", { * displayName: "Postgres Source With Secret Manager", * location: "us-central1", * connectionProfileId: "source-profile", * createWithoutValidation: true, * postgresqlProfile: { * hostname: "fake-hostname", * port: 3306, * username: "fake-username", * secretManagerStoredPassword: "projects/fake-project/secrets/fake-secret/versions/1", * database: "fake-database", * }, * }); * ``` * * ## Import * * ConnectionProfile can be imported using any of these accepted formats: * * * `projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}` * * * `{{project}}/{{location}}/{{connection_profile_id}}` * * * `{{location}}/{{connection_profile_id}}` * * When using the `pulumi import` command, ConnectionProfile can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:datastream/connectionProfile:ConnectionProfile default projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}} * ``` * * ```sh * $ pulumi import gcp:datastream/connectionProfile:ConnectionProfile default {{project}}/{{location}}/{{connection_profile_id}} * ``` * * ```sh * $ pulumi import gcp:datastream/connectionProfile:ConnectionProfile default {{location}}/{{connection_profile_id}} * ``` */ class ConnectionProfile extends pulumi.CustomResource { /** * Get an existing ConnectionProfile 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 ConnectionProfile(name, state, Object.assign(Object.assign({}, opts), { id: id })); } /** * Returns true if the given object is an instance of ConnectionProfile. 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'] === ConnectionProfile.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["bigqueryProfile"] = state ? state.bigqueryProfile : undefined; resourceInputs["connectionProfileId"] = state ? state.connectionProfileId : undefined; resourceInputs["createWithoutValidation"] = state ? state.createWithoutValidation : undefined; resourceInputs["displayName"] = state ? state.displayName : undefined; resourceInputs["effectiveLabels"] = state ? state.effectiveLabels : undefined; resourceInputs["forwardSshConnectivity"] = state ? state.forwardSshConnectivity : undefined; resourceInputs["gcsProfile"] = state ? state.gcsProfile : undefined; resourceInputs["labels"] = state ? state.labels : undefined; resourceInputs["location"] = state ? state.location : undefined; resourceInputs["mysqlProfile"] = state ? state.mysqlProfile : undefined; resourceInputs["name"] = state ? state.name : undefined; resourceInputs["oracleProfile"] = state ? state.oracleProfile : undefined; resourceInputs["postgresqlProfile"] = state ? state.postgresqlProfile : undefined; resourceInputs["privateConnectivity"] = state ? state.privateConnectivity : undefined; resourceInputs["project"] = state ? state.project : undefined; resourceInputs["pulumiLabels"] = state ? state.pulumiLabels : undefined; resourceInputs["salesforceProfile"] = state ? state.salesforceProfile : undefined; resourceInputs["sqlServerProfile"] = state ? state.sqlServerProfile : undefined; } else { const args = argsOrState; if ((!args || args.connectionProfileId === undefined) && !opts.urn) { throw new Error("Missing required property 'connectionProfileId'"); } if ((!args || args.displayName === undefined) && !opts.urn) { throw new Error("Missing required property 'displayName'"); } if ((!args || args.location === undefined) && !opts.urn) { throw new Error("Missing required property 'location'"); } resourceInputs["bigqueryProfile"] = args ? args.bigqueryProfile : undefined; resourceInputs["connectionProfileId"] = args ? args.connectionProfileId : undefined; resourceInputs["createWithoutValidation"] = args ? args.createWithoutValidation : undefined; resourceInputs["displayName"] = args ? args.displayName : undefined; resourceInputs["forwardSshConnectivity"] = args ? args.forwardSshConnectivity : undefined; resourceInputs["gcsProfile"] = args ? args.gcsProfile : undefined; resourceInputs["labels"] = args ? args.labels : undefined; resourceInputs["location"] = args ? args.location : undefined; resourceInputs["mysqlProfile"] = args ? args.mysqlProfile : undefined; resourceInputs["oracleProfile"] = args ? args.oracleProfile : undefined; resourceInputs["postgresqlProfile"] = args ? args.postgresqlProfile : undefined; resourceInputs["privateConnectivity"] = args ? args.privateConnectivity : undefined; resourceInputs["project"] = args ? args.project : undefined; resourceInputs["salesforceProfile"] = args ? args.salesforceProfile : undefined; resourceInputs["sqlServerProfile"] = args ? args.sqlServerProfile : undefined; resourceInputs["effectiveLabels"] = undefined /*out*/; resourceInputs["name"] = undefined /*out*/; resourceInputs["pulumiLabels"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const secretOpts = { additionalSecretOutputs: ["effectiveLabels", "pulumiLabels"] }; opts = pulumi.mergeOptions(opts, secretOpts); super(ConnectionProfile.__pulumiType, name, resourceInputs, opts); } } exports.ConnectionProfile = ConnectionProfile; /** @internal */ ConnectionProfile.__pulumiType = 'gcp:datastream/connectionProfile:ConnectionProfile'; //# sourceMappingURL=connectionProfile.js.map