-
Notifications
You must be signed in to change notification settings - Fork 263
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 private ip (incorporating previous PR feedback) #145
Changes from 6 commits
1128c81
cdcb897
4c60d9b
88651dc
fc1e236
7c79fe0
5a974d7
af7b4f6
2f69d29
ee16a16
cfa9ff0
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 |
---|---|---|
|
@@ -594,6 +594,30 @@ func TestAccSqlDatabaseInstance_basic_with_user_labels(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccSqlDatabaseInstance_with_private_network(t *testing.T) { | ||
t.Parallel() | ||
|
||
databaseName := "tf-test-" + acctest.RandString(10) | ||
networkName := "tf-test-" + acctest.RandString(10) | ||
addressName := "tf-test-" + acctest.RandString(10) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccSqlDatabaseInstanceDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccSqlDatabaseInstance_with_private_network(databaseName, networkName, addressName), | ||
}, | ||
resource.TestStep{ | ||
ResourceName: "google_sql_database_instance.instance", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccSqlDatabaseInstanceDestroy(s *terraform.State) error { | ||
for _, rs := range s.RootModule().Resources { | ||
config := testAccProvider.Meta().(*Config) | ||
|
@@ -714,6 +738,42 @@ resource "google_sql_database_instance" "instance-failover" { | |
`, instanceName, failoverName) | ||
} | ||
|
||
func testAccSqlDatabaseInstance_with_private_network(databaseName, networkName, addressRangeName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_network" "foobar" { | ||
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. FYI I think the test will run faster if you do 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. Done. |
||
name = "%s" | ||
} | ||
|
||
resource "google_compute_global_address" "foobar" { | ||
name = "%s" | ||
purpose = "VPC_PEERING" | ||
address_type = "INTERNAL" | ||
prefix_length = 16 | ||
network = "${google_compute_network.foobar.self_link}" | ||
} | ||
|
||
resource "google_service_networking_connection" "foobar" { | ||
network = "${google_compute_network.foobar.self_link}" | ||
service = "servicenetworking.googleapis.com" | ||
reserved_peering_ranges = ["${google_compute_global_address.foobar.name}"] | ||
} | ||
|
||
# TODO figure out a way to specify the dependency to the connection resource | ||
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. do you still need this TODO? 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. Removed. |
||
resource "google_sql_database_instance" "instance" { | ||
depends_on = ["google_service_networking_connection.foobar"] | ||
name = "%s" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
ipv4_enabled = "false" | ||
private_network = "${google_compute_network.foobar.self_link}" | ||
} | ||
} | ||
} | ||
`, networkName, addressRangeName, databaseName) | ||
} | ||
|
||
var testGoogleSqlDatabaseInstance_settings = ` | ||
resource "google_sql_database_instance" "instance" { | ||
name = "tf-lw-%d" | ||
|
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.
nit: could it be called
TestAccSqlDatabaseInstance_withPrivateNetwork
?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.
Done.