UNPKG

@pulumi/gcp

Version:

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

198 lines 9.57 kB
import * as pulumi from "@pulumi/pulumi"; /** * Executes a SQL script to provision in-database resources on a Cloud SQL Instance. For more information, see the [Cloud SQL official documentation](https://cloud.google.com/sql/docs/postgres/executesql-instance), or the [JSON API](https://cloud.google.com/sql/docs/admin-api/v1beta4/instances/executeSql). * * > **Warning:** The SQL script and its execution response might transit through intermediate locations between your client and the location of the target instance. * * > **Note:** Terraform connects to the instance via [IAM database authentication](https://cloud.google.com/sql/docs/mysql/authentication) to execute the script, so the identity account used to apply your Terraform config must exist as an IAM user or IAM service account in the instance. You also need to grant roles or privileges to this IAM user or IAM service account so it has permission to execute statements in your provision scripts. See the example below. * * ## Example Usage * * Example managing a Cloud SQL Postgres instance with a provision script. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const instance = new gcp.sql.DatabaseInstance("instance", { * name: "my-instance", * databaseVersion: "POSTGRES_17", * settings: { * tier: "db-perf-optimized-N-2", * dataApiAccess: "ALLOW_DATA_API", * databaseFlags: [{ * name: "cloudsql.iam_authentication", * value: "on", * }], * }, * }); * // Create a database user for your account and grant roles so it has privilege to access the database. * // Set the type to "CLOUD_IAM_USER" for huamn account or "CLOUD_IAM_SERVICE_ACCOUNT" for service account. * // If a service account is used and the instance is Postgres, please trim the ".gserviceaccount.com" suffix * // to avoid exceeding the username length limit. * const iamUser = new gcp.sql.User("iam_user", { * name: "account-used-to-apply-this-config@example.com", * instance: instance.name, * type: "CLOUD_IAM_USER", * databaseRoles: ["cloudsqlsuperuser"], * }); * const database = new gcp.sql.Database("database", { * name: "my-database", * instance: instance.name, * }); * const table = new gcp.sql.ProvisionScript("table", { * script: "CREATE TABLE IF NOT EXISTS table1 ( col VARCHAR(16) NOT NULL );", * instance: instance.name, * database: database.name, * description: "sql script to create tables", * }, { * dependsOn: [iamUser], * }); * ``` * * Example managing a Cloud SQL MySQL instance with a provision script. */ export declare class ProvisionScript extends pulumi.CustomResource { /** * Get an existing ProvisionScript 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: string, id: pulumi.Input<pulumi.ID>, state?: ProvisionScriptState, opts?: pulumi.CustomResourceOptions): ProvisionScript; /** * Returns true if the given object is an instance of ProvisionScript. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj: any): obj is ProvisionScript; /** * The name of the database to which Terraform connects. Changing * this forces Terraform to connect to the new database and run the script. This argument is * required for Postgres instances. It's optional for MySQL, but some of your queries may require * a database. You can create and use a database in the script or explicitly reference a * google_sql_database. */ readonly database: pulumi.Output<string | undefined>; /** * The deletion policy for the resources created by the script. The * default is "ABANDON". It must be "ABANDON" to allow Terraform to abandon the resources. If you * want to delete resources, add statements in the script such as `drop … if exists`. */ readonly deletionPolicy: pulumi.Output<string | undefined>; /** * The description of the provision script. */ readonly description: pulumi.Output<string | undefined>; /** * The name of the Cloud SQL instance. Changing this forces the script to * be run on the new instance. */ readonly instance: pulumi.Output<string>; /** * The ID of the project in which the resource belongs. If it is not provided, * the provider project is used. */ readonly project: pulumi.Output<string>; /** * The SQL script to provision database resources. Its execution time limit * is 30 s and it will be canceled if it takes longer than 30 s. You can use patterns like * `create if not exists …` or `if not exists (select …) then … end if` to avoid existence-related * errors. If it's not possible to make a statement idempotent, you can run it once and then remove * it from this script. */ readonly script: pulumi.Output<string>; /** * Create a ProvisionScript resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name: string, args: ProvisionScriptArgs, opts?: pulumi.CustomResourceOptions); } /** * Input properties used for looking up and filtering ProvisionScript resources. */ export interface ProvisionScriptState { /** * The name of the database to which Terraform connects. Changing * this forces Terraform to connect to the new database and run the script. This argument is * required for Postgres instances. It's optional for MySQL, but some of your queries may require * a database. You can create and use a database in the script or explicitly reference a * google_sql_database. */ database?: pulumi.Input<string | undefined>; /** * The deletion policy for the resources created by the script. The * default is "ABANDON". It must be "ABANDON" to allow Terraform to abandon the resources. If you * want to delete resources, add statements in the script such as `drop … if exists`. */ deletionPolicy?: pulumi.Input<string | undefined>; /** * The description of the provision script. */ description?: pulumi.Input<string | undefined>; /** * The name of the Cloud SQL instance. Changing this forces the script to * be run on the new instance. */ instance?: pulumi.Input<string | undefined>; /** * The ID of the project in which the resource belongs. If it is not provided, * the provider project is used. */ project?: pulumi.Input<string | undefined>; /** * The SQL script to provision database resources. Its execution time limit * is 30 s and it will be canceled if it takes longer than 30 s. You can use patterns like * `create if not exists …` or `if not exists (select …) then … end if` to avoid existence-related * errors. If it's not possible to make a statement idempotent, you can run it once and then remove * it from this script. */ script?: pulumi.Input<string | undefined>; } /** * The set of arguments for constructing a ProvisionScript resource. */ export interface ProvisionScriptArgs { /** * The name of the database to which Terraform connects. Changing * this forces Terraform to connect to the new database and run the script. This argument is * required for Postgres instances. It's optional for MySQL, but some of your queries may require * a database. You can create and use a database in the script or explicitly reference a * google_sql_database. */ database?: pulumi.Input<string | undefined>; /** * The deletion policy for the resources created by the script. The * default is "ABANDON". It must be "ABANDON" to allow Terraform to abandon the resources. If you * want to delete resources, add statements in the script such as `drop … if exists`. */ deletionPolicy?: pulumi.Input<string | undefined>; /** * The description of the provision script. */ description?: pulumi.Input<string | undefined>; /** * The name of the Cloud SQL instance. Changing this forces the script to * be run on the new instance. */ instance: pulumi.Input<string>; /** * The ID of the project in which the resource belongs. If it is not provided, * the provider project is used. */ project?: pulumi.Input<string | undefined>; /** * The SQL script to provision database resources. Its execution time limit * is 30 s and it will be canceled if it takes longer than 30 s. You can use patterns like * `create if not exists …` or `if not exists (select …) then … end if` to avoid existence-related * errors. If it's not possible to make a statement idempotent, you can run it once and then remove * it from this script. */ script: pulumi.Input<string>; } //# sourceMappingURL=provisionScript.d.ts.map