-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Cloud SQL Address Range Picker for Clones and Read replicas #5664
Changes from all commits
7499e7a
fa66f4c
79f4257
df65e2d
35c3f06
2260e35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -697,6 +697,8 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(t *testi | |
databaseName := "tf-test-" + randString(t, 10) | ||
addressName := "tf-test-" + randString(t, 10) | ||
networkName := BootstrapSharedTestNetwork(t, "sql-instance-private-allocated-ip-range") | ||
addressName_update := "tf-test-" + randString(t, 10) + "update" | ||
networkName_update := BootstrapSharedTestNetwork(t, "sql-instance-private-allocated-ip-range-update") | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
|
@@ -712,10 +714,80 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(t *testi | |
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"deletion_protection"}, | ||
}, | ||
{ | ||
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(databaseName, networkName_update, addressName_update), | ||
}, | ||
{ | ||
ResourceName: "google_sql_database_instance.instance", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"deletion_protection"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(t *testing.T) { | ||
t.Parallel() | ||
|
||
databaseName := "tf-test-" + randString(t, 10) | ||
addressName := "tf-test-" + randString(t, 10) | ||
networkName := BootstrapSharedTestNetwork(t, "sql-instance-private-replica") | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(databaseName, networkName, addressName), | ||
}, | ||
{ | ||
ResourceName: "google_sql_database_instance.instance", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"deletion_protection"}, | ||
}, | ||
{ | ||
ResourceName: "google_sql_database_instance.replica1", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: ignoredReplicaConfigurationFields, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(t *testing.T) { | ||
t.Parallel() | ||
|
||
databaseName := "tf-test-" + randString(t, 10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting here that we cannot use the bootstrap db instance since this uses a private network. If more than one private network clone/backup test is needed, we should create a new bootstrap instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree! Looks like this is the only one now. We will probably need to create a bootstrap instance with private networks if more tests need it. |
||
addressName := "tf-test-" + randString(t, 10) | ||
networkName := BootstrapSharedTestNetwork(t, "sql-instance-private-clone") | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(databaseName, networkName, addressName), | ||
}, | ||
{ | ||
ResourceName: "google_sql_database_instance.instance", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"deletion_protection"}, | ||
}, | ||
{ | ||
ResourceName: "google_sql_database_instance.clone1", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"deletion_protection", "clone"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccSqlDatabaseInstance_createFromBackup(t *testing.T) { | ||
// Sqladmin client | ||
|
@@ -1097,7 +1169,7 @@ resource "google_compute_global_address" "foobar" { | |
name = "%s" | ||
purpose = "VPC_PEERING" | ||
address_type = "INTERNAL" | ||
prefix_length = 24 | ||
prefix_length = 16 | ||
network = data.google_compute_network.servicenet.self_link | ||
} | ||
|
||
|
@@ -1125,6 +1197,130 @@ resource "google_sql_database_instance" "instance" { | |
`, networkName, addressRangeName, databaseName) | ||
} | ||
|
||
|
||
func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeReplica(databaseName, networkName, addressRangeName string) string { | ||
return fmt.Sprintf(` | ||
data "google_compute_network" "servicenet" { | ||
name = "%s" | ||
} | ||
|
||
resource "google_compute_global_address" "foobar" { | ||
name = "%s" | ||
purpose = "VPC_PEERING" | ||
address_type = "INTERNAL" | ||
prefix_length = 16 | ||
network = data.google_compute_network.servicenet.self_link | ||
} | ||
|
||
resource "google_service_networking_connection" "foobar" { | ||
network = data.google_compute_network.servicenet.self_link | ||
service = "servicenetworking.googleapis.com" | ||
reserved_peering_ranges = [google_compute_global_address.foobar.name] | ||
} | ||
|
||
resource "google_sql_database_instance" "instance" { | ||
depends_on = [google_service_networking_connection.foobar] | ||
name = "%s" | ||
region = "us-central1" | ||
database_version = "MYSQL_5_7" | ||
deletion_protection = false | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
ipv4_enabled = "false" | ||
private_network = data.google_compute_network.servicenet.self_link | ||
} | ||
backup_configuration { | ||
enabled = true | ||
start_time = "00:00" | ||
binary_log_enabled = true | ||
} | ||
} | ||
} | ||
resource "google_sql_database_instance" "replica1" { | ||
depends_on = [google_service_networking_connection.foobar] | ||
name = "%s-replica1" | ||
region = "us-central1" | ||
database_version = "MYSQL_5_7" | ||
deletion_protection = false | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
ipv4_enabled = "false" | ||
private_network = data.google_compute_network.servicenet.self_link | ||
allocated_ip_range = google_compute_global_address.foobar.name | ||
} | ||
} | ||
|
||
master_instance_name = google_sql_database_instance.instance.name | ||
|
||
replica_configuration { | ||
connect_retry_interval = 100 | ||
master_heartbeat_period = 10000 | ||
password = "password" | ||
username = "username" | ||
ssl_cipher = "ALL" | ||
verify_server_certificate = false | ||
} | ||
} | ||
`, networkName, addressRangeName, databaseName, databaseName) | ||
} | ||
|
||
func testAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRangeClone(databaseName, networkName, addressRangeName string) string { | ||
return fmt.Sprintf(` | ||
data "google_compute_network" "servicenet" { | ||
name = "%s" | ||
} | ||
|
||
resource "google_compute_global_address" "foobar" { | ||
name = "%s" | ||
purpose = "VPC_PEERING" | ||
address_type = "INTERNAL" | ||
prefix_length = 16 | ||
network = data.google_compute_network.servicenet.self_link | ||
} | ||
|
||
resource "google_service_networking_connection" "foobar" { | ||
network = data.google_compute_network.servicenet.self_link | ||
service = "servicenetworking.googleapis.com" | ||
reserved_peering_ranges = [google_compute_global_address.foobar.name] | ||
} | ||
|
||
resource "google_sql_database_instance" "instance" { | ||
depends_on = [google_service_networking_connection.foobar] | ||
name = "%s" | ||
region = "us-central1" | ||
database_version = "MYSQL_5_7" | ||
deletion_protection = false | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
ipv4_enabled = "false" | ||
private_network = data.google_compute_network.servicenet.self_link | ||
} | ||
backup_configuration { | ||
enabled = true | ||
start_time = "00:00" | ||
binary_log_enabled = true | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "clone1" { | ||
name = "%s-clone1" | ||
region = "us-central1" | ||
database_version = "MYSQL_5_7" | ||
deletion_protection = false | ||
|
||
clone { | ||
source_instance_name = google_sql_database_instance.instance.name | ||
allocated_ip_range = google_compute_global_address.foobar.name | ||
} | ||
|
||
} | ||
`, networkName, addressRangeName, databaseName, databaseName) | ||
} | ||
|
||
var testGoogleSqlDatabaseInstance_settings = ` | ||
resource "google_sql_database_instance" "instance" { | ||
name = "%s" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the update case for this field something we can add a test for, or is it too hard to orchestrate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create a test on updating this field with a new private network, as I mentioned in the PR description, but just not within the same VPC. I will add one on this.