provider/google: add test case for GH-4222

Reproduces a non-empty plan that is now fixed after the bugfix for that
issue landed.
This commit is contained in:
Paul Hinze 2016-08-18 11:25:42 -04:00
parent 49490f5fe2
commit ee71068018
2 changed files with 64 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
@ -486,6 +487,7 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
instance.MasterInstanceName = v.(string)
}
log.Printf("[PAUL] INSERT: %s", spew.Sdump(project, instance))
op, err := config.clientSqlAdmin.Instances.Insert(project, instance).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 409 {
@ -994,6 +996,7 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
d.Partial(false)
log.Printf("[PAUL] UPDATE: %s", spew.Sdump(project, instance.Name, instance))
op, err := config.clientSqlAdmin.Instances.Update(project, instance.Name, instance).Do()
if err != nil {
return fmt.Errorf("Error, failed to update instance %s: %s", instance.Name, err)

View File

@ -152,6 +152,32 @@ func TestAccGoogleSqlDatabaseInstance_settings_downgrade(t *testing.T) {
})
}
// GH-4222
func TestAccGoogleSqlDatabaseInstance_authNets(t *testing.T) {
// var instance sqladmin.DatabaseInstance
databaseID := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_authNets_step1, databaseID),
},
resource.TestStep{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_authNets_step2, databaseID),
},
resource.TestStep{
Config: fmt.Sprintf(
testGoogleSqlDatabaseInstance_authNets_step1, databaseID),
},
},
})
}
func testAccCheckGoogleSqlDatabaseInstanceEquals(n string,
instance *sqladmin.DatabaseInstance) resource.TestCheckFunc {
return func(s *terraform.State) error {
@ -447,3 +473,38 @@ resource "google_sql_database_instance" "instance" {
}
}
`
var testGoogleSqlDatabaseInstance_authNets_step1 = `
resource "google_sql_database_instance" "instance" {
name = "tf-lw-%d"
region = "us-central"
settings {
tier = "D0"
crash_safe_replication = false
ip_configuration {
ipv4_enabled = "true"
authorized_networks {
value = "108.12.12.12"
name = "misc"
expiration_time = "2017-11-15T16:19:00.094Z"
}
}
}
}
`
var testGoogleSqlDatabaseInstance_authNets_step2 = `
resource "google_sql_database_instance" "instance" {
name = "tf-lw-%d"
region = "us-central"
settings {
tier = "D0"
crash_safe_replication = false
ip_configuration {
ipv4_enabled = "true"
}
}
}
`