Skip to content

Commit e188411

Browse files
Add enable_private_path_for_google_cloud_services field to google_sql_database_instance resource (#5177)
1 parent c3c62aa commit e188411

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

.changelog/6986.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
sql: added `enable_private_path_for_google_cloud_services` field to `google_sql_database_instance` resource
3+
```

google-beta/resource_sql_database_instance.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var (
5454
"settings.0.ip_configuration.0.require_ssl",
5555
"settings.0.ip_configuration.0.private_network",
5656
"settings.0.ip_configuration.0.allocated_ip_range",
57+
"settings.0.ip_configuration.0.enable_private_path_for_google_cloud_services",
5758
}
5859

5960
maintenanceWindowKeys = []string{
@@ -396,6 +397,12 @@ is set to true. Defaults to ZONAL.`,
396397
AtLeastOneOf: ipConfigurationKeys,
397398
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])?.`,
398399
},
400+
"enable_private_path_for_google_cloud_services": {
401+
Type: schema.TypeBool,
402+
Optional: true,
403+
AtLeastOneOf: ipConfigurationKeys,
404+
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.`,
405+
},
399406
},
400407
},
401408
},
@@ -1229,14 +1236,16 @@ func expandIpConfiguration(configured []interface{}) *sqladmin.IpConfiguration {
12291236
_ipConfiguration := configured[0].(map[string]interface{})
12301237

12311238
return &sqladmin.IpConfiguration{
1232-
Ipv4Enabled: _ipConfiguration["ipv4_enabled"].(bool),
1233-
RequireSsl: _ipConfiguration["require_ssl"].(bool),
1234-
PrivateNetwork: _ipConfiguration["private_network"].(string),
1235-
AllocatedIpRange: _ipConfiguration["allocated_ip_range"].(string),
1236-
AuthorizedNetworks: expandAuthorizedNetworks(_ipConfiguration["authorized_networks"].(*schema.Set).List()),
1237-
ForceSendFields: []string{"Ipv4Enabled", "RequireSsl"},
1239+
Ipv4Enabled: _ipConfiguration["ipv4_enabled"].(bool),
1240+
RequireSsl: _ipConfiguration["require_ssl"].(bool),
1241+
PrivateNetwork: _ipConfiguration["private_network"].(string),
1242+
AllocatedIpRange: _ipConfiguration["allocated_ip_range"].(string),
1243+
AuthorizedNetworks: expandAuthorizedNetworks(_ipConfiguration["authorized_networks"].(*schema.Set).List()),
1244+
EnablePrivatePathForGoogleCloudServices: _ipConfiguration["enable_private_path_for_google_cloud_services"].(bool),
1245+
ForceSendFields: []string{"Ipv4Enabled", "RequireSsl"},
12381246
}
12391247
}
1248+
12401249
func expandAuthorizedNetworks(configured []interface{}) []*sqladmin.AclEntry {
12411250
an := make([]*sqladmin.AclEntry, 0, len(configured))
12421251
for _, _acl := range configured {
@@ -1881,6 +1890,7 @@ func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration) interface
18811890
"private_network": ipConfiguration.PrivateNetwork,
18821891
"allocated_ip_range": ipConfiguration.AllocatedIpRange,
18831892
"require_ssl": ipConfiguration.RequireSsl,
1893+
"enable_private_path_for_google_cloud_services": ipConfiguration.EnablePrivatePathForGoogleCloudServices,
18841894
}
18851895

18861896
if ipConfiguration.AuthorizedNetworks != nil {

google-beta/resource_sql_database_instance_test.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func TestAccSqlDatabaseInstance_deleteDefaultUserBeforeSubsequentApiCalls(t *tes
221221
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
222222
Steps: []resource.TestStep{
223223
{
224-
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName),
224+
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, false, false),
225225
},
226226
{
227227
PreConfig: func() {
@@ -775,7 +775,25 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te
775775
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
776776
Steps: []resource.TestStep{
777777
{
778-
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName),
778+
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, false, false),
779+
},
780+
{
781+
ResourceName: "google_sql_database_instance.instance",
782+
ImportState: true,
783+
ImportStateVerify: true,
784+
ImportStateVerifyIgnore: []string{"deletion_protection"},
785+
},
786+
{
787+
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, false),
788+
},
789+
{
790+
ResourceName: "google_sql_database_instance.instance",
791+
ImportState: true,
792+
ImportStateVerify: true,
793+
ImportStateVerifyIgnore: []string{"deletion_protection"},
794+
},
795+
{
796+
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressName, true, true),
779797
},
780798
{
781799
ResourceName: "google_sql_database_instance.instance",
@@ -1819,7 +1837,12 @@ resource "google_sql_database_instance" "instance-failover" {
18191837
`, instanceName, failoverName)
18201838
}
18211839

1822-
func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressRangeName string) string {
1840+
func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressRangeName string, specifyPrivatePathOption bool, enablePrivatePath bool) string {
1841+
privatePathOption := ""
1842+
if specifyPrivatePathOption {
1843+
privatePathOption = fmt.Sprintf("enable_private_path_for_google_cloud_services = %t", enablePrivatePath)
1844+
}
1845+
18231846
return fmt.Sprintf(`
18241847
data "google_compute_network" "servicenet" {
18251848
name = "%s"
@@ -1850,10 +1873,11 @@ resource "google_sql_database_instance" "instance" {
18501873
ip_configuration {
18511874
ipv4_enabled = "false"
18521875
private_network = data.google_compute_network.servicenet.self_link
1876+
%s
18531877
}
18541878
}
18551879
}
1856-
`, networkName, addressRangeName, databaseName)
1880+
`, networkName, addressRangeName, databaseName, privatePathOption)
18571881
}
18581882

18591883
func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(databaseName, networkName, addressRangeName string) string {
@@ -2119,7 +2143,7 @@ resource "google_sql_database_instance" "instance" {
21192143
tier = "db-f1-micro"
21202144
location_preference {
21212145
zone = "us-central1-f"
2122-
secondary_zone = "us-central1-a"
2146+
secondary_zone = "us-central1-a"
21232147
}
21242148
21252149
ip_configuration {

website/docs/r/sql_database_instance.html.markdown

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ resource "google_sql_database_instance" "instance" {
144144
settings {
145145
tier = "db-f1-micro"
146146
ip_configuration {
147-
ipv4_enabled = false
148-
private_network = google_compute_network.private_network.id
147+
ipv4_enabled = false
148+
private_network = google_compute_network.private_network.id
149+
enable_private_path_for_google_cloud_services = true
149150
}
150151
}
151152
}
@@ -209,7 +210,7 @@ includes an up-to-date reference of supported versions.
209210

210211
* `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false
211212
in Terraform state, a `terraform destroy` or `terraform apply` command that deletes the instance will fail. Defaults to `true`.
212-
213+
213214
~> **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`.
214215

215216
* `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:
280281

281282
* `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".
282283

283-
* `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".
284+
* `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".
284285

285286
* `time_zone` - (Optional) The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format.
286287

@@ -324,6 +325,8 @@ This setting can be updated, but it cannot be removed after it is set.
324325

325326
* `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])?.
326327

328+
* `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.
329+
327330
The optional `settings.ip_configuration.authorized_networks[]` sublist supports:
328331

329332
* `expiration_time` - (Optional) The [RFC 3339](https://tools.ietf.org/html/rfc3339)

0 commit comments

Comments
 (0)