Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ca9cfa
Add `enable_private_path_for_google_cloud_services` property to `goog…
Dec 18, 2022
b7a602a
Add a test case for third-party tests
Dec 18, 2022
ebbc808
Add usage examples
Dec 18, 2022
d067fe0
Connect with the VCR test
Dec 18, 2022
cecb9b6
Merge branch 'GoogleCloudPlatform:main' into cloud-sql-private-route-…
mmizutani Jan 3, 2023
2ec23fe
Merge branch 'GoogleCloudPlatform:main' into cloud-sql-private-route-…
mmizutani Jan 4, 2023
3f740ec
Merge branch 'GoogleCloudPlatform:main' into cloud-sql-private-route-…
mmizutani Jan 7, 2023
e0adf14
Fix test
mmizutani Jan 7, 2023
3c801d0
Add note
mmizutani Jan 7, 2023
a86ce99
Make fail-safe
mmizutani Jan 8, 2023
fa99805
format
mmizutani Jan 14, 2023
52e8a4a
Upgrade the tier of POSTGRES instances for faster instance creation
mmizutani Jan 14, 2023
53f14d3
Fix type error
mmizutani Jan 14, 2023
fc21d69
Merge branch 'main' into cloud-sql-private-route-for-google-services
mmizutani Jan 14, 2023
9c2cb79
Also upgrade mysql tier to non shared core in another tiimeout sensit…
mmizutani Jan 15, 2023
5cdb911
Merge branch 'main' into cloud-sql-private-route-for-google-services
mmizutani Jan 25, 2023
fc399be
Revert "Also upgrade mysql tier to non shared core in another timeout…
mmizutani Jan 25, 2023
c454b9e
Revert "Upgrade the tier of POSTGRES instances for faster instance cr…
mmizutani Jan 25, 2023
1ca5131
Merge branch 'main' into cloud-sql-private-route-for-google-services
mmizutani Jan 25, 2023
f49f05a
Merge branch 'GoogleCloudPlatform:main' into cloud-sql-private-route-…
mmizutani Jan 26, 2023
c025e9f
Merge branch 'GoogleCloudPlatform:main' into cloud-sql-private-route-…
mmizutani Feb 2, 2023
9499f5b
Merge TestAccSqlDatabaseInstance_withPrivateNetwork_withEnablePrivate…
mmizutani Feb 3, 2023
db73c43
Remove the custom pre-apply validation logic and let users face the b…
mmizutani Feb 3, 2023
790cb32
Remove an extra blank line
mmizutani Feb 3, 2023
8c33c63
Revert unnecessary edit to the no-longer-used go template file
mmizutani Feb 3, 2023
9caf12d
Fix indent
mmizutani Feb 3, 2023
3fd6f1d
Revert unnecessary edit to mmv1/products/sql/api.yaml
mmizutani Feb 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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`,
},
},

},
},
},
Expand Down Expand Up @@ -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.`,
},
},
},
},
Expand Down Expand Up @@ -607,7 +614,6 @@ is set to true. Defaults to ZONAL.`,
ForceNew: true,
},


"root_password": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -2956,4 +2980,4 @@ resource "google_sql_database_instance" "main" {
tier = "db-custom-2-13312"
}
}`, instance, databaseVersion, rootPassword)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down