diff --git a/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb b/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb index 0ced6b51d12e..7007df19d3c2 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb +++ b/mmv1/third_party/terraform/resources/resource_sql_database_instance.go.erb @@ -55,6 +55,7 @@ var ( "settings.0.ip_configuration.0.require_ssl", "settings.0.ip_configuration.0.private_network", "settings.0.ip_configuration.0.allocated_ip_range", + "settings.0.ip_configuration.0.enable_private_path_for_google_cloud_services", } maintenanceWindowKeys = []string{ @@ -180,14 +181,14 @@ func resourceSqlDatabaseInstance() *schema.Resource { "start_date": { Type: schema.TypeString, Required: true, - Description: `Start date after which maintenance will not take place. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01`, - }, - "time": { + Description: `Start date after which maintenance will not take place. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01`, + }, + "time": { Type: schema.TypeString, Required: true, Description: `Time in UTC when the "deny maintenance period" starts on start_date and ends on end_date. The time is in format: HH:mm:SS, i.e., 00:00:00`, - }, - + }, + }, }, }, @@ -398,6 +399,12 @@ is set to true. Defaults to ZONAL.`, AtLeastOneOf: ipConfigurationKeys, Description: `The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the instance ip will be created in the allocated range. The range name must comply with RFC 1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.`, }, + "enable_private_path_for_google_cloud_services": { + Type: schema.TypeBool, + Optional: true, + AtLeastOneOf: ipConfigurationKeys, + Description: `Whether Google Cloud services such as BigQuery are allowed to access data in this Cloud SQL instance over a private IP connection. SQLSERVER database type is not supported.`, + }, }, }, }, @@ -607,7 +614,6 @@ is set to true. Defaults to ZONAL.`, ForceNew: true, }, - "root_password": { Type: schema.TypeString, Optional: true, @@ -938,7 +944,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) if err := d.Set("name", name); err != nil { return fmt.Errorf("Error setting name: %s", err) } - + // SQL Instances that fail to create are expensive- see https://github.com/hashicorp/terraform-provider-google/issues/7154 // We can fail fast to stop instance names from getting reserved. network := d.Get("settings.0.ip_configuration.0.private_network").(string) @@ -1232,14 +1238,16 @@ func expandIpConfiguration(configured []interface{}) *sqladmin.IpConfiguration { _ipConfiguration := configured[0].(map[string]interface{}) return &sqladmin.IpConfiguration{ - Ipv4Enabled: _ipConfiguration["ipv4_enabled"].(bool), - RequireSsl: _ipConfiguration["require_ssl"].(bool), - PrivateNetwork: _ipConfiguration["private_network"].(string), - AllocatedIpRange: _ipConfiguration["allocated_ip_range"].(string), - AuthorizedNetworks: expandAuthorizedNetworks(_ipConfiguration["authorized_networks"].(*schema.Set).List()), - ForceSendFields: []string{"Ipv4Enabled", "RequireSsl"}, + Ipv4Enabled: _ipConfiguration["ipv4_enabled"].(bool), + RequireSsl: _ipConfiguration["require_ssl"].(bool), + PrivateNetwork: _ipConfiguration["private_network"].(string), + AllocatedIpRange: _ipConfiguration["allocated_ip_range"].(string), + AuthorizedNetworks: expandAuthorizedNetworks(_ipConfiguration["authorized_networks"].(*schema.Set).List()), + EnablePrivatePathForGoogleCloudServices: _ipConfiguration["enable_private_path_for_google_cloud_services"].(bool), + ForceSendFields: []string{"Ipv4Enabled", "RequireSsl"}, } } + func expandAuthorizedNetworks(configured []interface{}) []*sqladmin.AclEntry { an := make([]*sqladmin.AclEntry, 0, len(configured)) for _, _acl := range configured { @@ -1501,7 +1509,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) desiredSetting := d.Get("settings") var op *sqladmin.Operation var instance *sqladmin.DatabaseInstance - + // Check if the database version is being updated, because patching database version is an atomic operation and can not be // performed with other fields, we first patch database version before updating the rest of the fields. if v, ok := d.GetOk("database_version"); ok { @@ -1881,10 +1889,11 @@ func flattenDatabaseFlags(databaseFlags []*sqladmin.DatabaseFlags) []map[string] func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration) interface{} { data := map[string]interface{}{ - "ipv4_enabled": ipConfiguration.Ipv4Enabled, - "private_network": ipConfiguration.PrivateNetwork, - "allocated_ip_range": ipConfiguration.AllocatedIpRange, - "require_ssl": ipConfiguration.RequireSsl, + "ipv4_enabled": ipConfiguration.Ipv4Enabled, + "private_network": ipConfiguration.PrivateNetwork, + "allocated_ip_range": ipConfiguration.AllocatedIpRange, + "require_ssl": ipConfiguration.RequireSsl, + "enable_private_path_for_google_cloud_services": ipConfiguration.EnablePrivatePathForGoogleCloudServices, } if ipConfiguration.AuthorizedNetworks != nil { diff --git a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb index f9f69d1b4b33..2279785e680b 100644 --- a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go.erb @@ -222,7 +222,7 @@ func TestAccSqlDatabaseInstance_deleteDefaultUserBeforeSubsequentApiCalls(t *tes CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, false, false), }, { PreConfig: func() { @@ -776,7 +776,25 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName), + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, false, false), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + { + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, false), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + { + Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, true), }, { ResourceName: "google_sql_database_instance.instance", @@ -1825,7 +1843,12 @@ resource "google_sql_database_instance" "instance-failover" { `, instanceName, failoverName) } -func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressRangeName string) string { +func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressRangeName string, specifyPrivatePathOption bool, enablePrivatePath bool) string { + privatePathOption := "" + if specifyPrivatePathOption { + privatePathOption = fmt.Sprintf("enable_private_path_for_google_cloud_services = %t", enablePrivatePath) + } + return fmt.Sprintf(` data "google_compute_network" "servicenet" { name = "%s" @@ -1856,10 +1879,11 @@ resource "google_sql_database_instance" "instance" { ip_configuration { ipv4_enabled = "false" private_network = data.google_compute_network.servicenet.self_link + %s } } } -`, networkName, addressRangeName, databaseName) +`, networkName, addressRangeName, databaseName, privatePathOption) } func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(databaseName, networkName, addressRangeName string) string { @@ -2126,7 +2150,7 @@ resource "google_sql_database_instance" "instance" { tier = "db-f1-micro" location_preference { zone = "us-central1-f" - secondary_zone = "us-central1-a" + secondary_zone = "us-central1-a" } ip_configuration { @@ -2794,7 +2818,7 @@ func checkInstanceTypeIsPresent(resourceName string) func(*terraform.State) erro return fmt.Errorf("can't find %s in state", resourceName) } rsAttr := rs.Primary.Attributes - _, ok = rsAttr["instance_type"]; + _, ok = rsAttr["instance_type"]; if !ok { return fmt.Errorf("Instance type is not computed for %s", resourceName) } @@ -2956,4 +2980,4 @@ resource "google_sql_database_instance" "main" { tier = "db-custom-2-13312" } }`, instance, databaseVersion, rootPassword) -} \ No newline at end of file +} diff --git a/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown b/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown index a37df9f37be1..99330c41ca35 100644 --- a/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown @@ -144,8 +144,9 @@ resource "google_sql_database_instance" "instance" { settings { tier = "db-f1-micro" ip_configuration { - ipv4_enabled = false - private_network = google_compute_network.private_network.id + ipv4_enabled = false + private_network = google_compute_network.private_network.id + enable_private_path_for_google_cloud_services = true } } } @@ -209,7 +210,7 @@ includes an up-to-date reference of supported versions. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a `terraform destroy` or `terraform apply` command that deletes the instance will fail. Defaults to `true`. - + ~> **NOTE:** This flag only protects instances from deletion within Terraform. To protect your instances from accidental deletion across all surfaces (API, gcloud, Cloud Console and Terraform), use the API flag `settings.deletion_protection_enabled`. * `restore_backup_context` - (optional) The context needed to restore the database to a backup run. This field will @@ -280,7 +281,7 @@ The optional `settings.sql_server_audit_config` subblock supports: * `upload_interval` - (Optional) How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s". -* `retention_interval` - (Optional) How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s". +* `retention_interval` - (Optional) How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s". * `time_zone` - (Optional) The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format. @@ -324,6 +325,8 @@ This setting can be updated, but it cannot be removed after it is set. * `allocated_ip_range` - (Optional) The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the instance ip will be created in the allocated range. The range name must comply with [RFC 1035](https://datatracker.ietf.org/doc/html/rfc1035). Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?. +* `enable_private_path_for_google_cloud_services` - (Optional) Whether Google Cloud services such as BigQuery are allowed to access data in this Cloud SQL instance over a private IP connection. SQLSERVER database type is not supported. + The optional `settings.ip_configuration.authorized_networks[]` sublist supports: * `expiration_time` - (Optional) The [RFC 3339](https://tools.ietf.org/html/rfc3339)