github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/builtin/providers/google/resource_sql_database_instance_test.go (about)

     1  package google
     2  
     3  /**
     4   * Note! You must run these tests once at a time. Google Cloud SQL does
     5   * not allow you to reuse a database for a short time after you reserved it,
     6   * and for this reason the tests will fail if the same config is used serveral
     7   * times in short succession.
     8   */
     9  
    10  import (
    11  	"fmt"
    12  	"strconv"
    13  	"strings"
    14  	"testing"
    15  
    16  	"github.com/hashicorp/terraform/helper/acctest"
    17  	"github.com/hashicorp/terraform/helper/resource"
    18  	"github.com/hashicorp/terraform/terraform"
    19  
    20  	"google.golang.org/api/sqladmin/v1beta4"
    21  )
    22  
    23  func TestAccGoogleSqlDatabaseInstance_basic(t *testing.T) {
    24  	var instance sqladmin.DatabaseInstance
    25  	databaseID := acctest.RandInt()
    26  
    27  	resource.Test(t, resource.TestCase{
    28  		PreCheck:     func() { testAccPreCheck(t) },
    29  		Providers:    testAccProviders,
    30  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
    31  		Steps: []resource.TestStep{
    32  			resource.TestStep{
    33  				Config: fmt.Sprintf(
    34  					testGoogleSqlDatabaseInstance_basic, databaseID),
    35  				Check: resource.ComposeTestCheckFunc(
    36  					testAccCheckGoogleSqlDatabaseInstanceExists(
    37  						"google_sql_database_instance.instance", &instance),
    38  					testAccCheckGoogleSqlDatabaseInstanceEquals(
    39  						"google_sql_database_instance.instance", &instance),
    40  				),
    41  			},
    42  		},
    43  	})
    44  }
    45  
    46  func TestAccGoogleSqlDatabaseInstance_basic2(t *testing.T) {
    47  	var instance sqladmin.DatabaseInstance
    48  
    49  	resource.Test(t, resource.TestCase{
    50  		PreCheck:     func() { testAccPreCheck(t) },
    51  		Providers:    testAccProviders,
    52  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
    53  		Steps: []resource.TestStep{
    54  			resource.TestStep{
    55  				Config: testGoogleSqlDatabaseInstance_basic2,
    56  				Check: resource.ComposeTestCheckFunc(
    57  					testAccCheckGoogleSqlDatabaseInstanceExists(
    58  						"google_sql_database_instance.instance", &instance),
    59  					testAccCheckGoogleSqlDatabaseInstanceEquals(
    60  						"google_sql_database_instance.instance", &instance),
    61  				),
    62  			},
    63  		},
    64  	})
    65  }
    66  
    67  func TestAccGoogleSqlDatabaseInstance_basic3(t *testing.T) {
    68  	var instance sqladmin.DatabaseInstance
    69  	databaseID := acctest.RandInt()
    70  
    71  	resource.Test(t, resource.TestCase{
    72  		PreCheck:     func() { testAccPreCheck(t) },
    73  		Providers:    testAccProviders,
    74  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
    75  		Steps: []resource.TestStep{
    76  			resource.TestStep{
    77  				Config: fmt.Sprintf(
    78  					testGoogleSqlDatabaseInstance_basic3, databaseID),
    79  				Check: resource.ComposeTestCheckFunc(
    80  					testAccCheckGoogleSqlDatabaseInstanceExists(
    81  						"google_sql_database_instance.instance", &instance),
    82  					testAccCheckGoogleSqlDatabaseInstanceEquals(
    83  						"google_sql_database_instance.instance", &instance),
    84  					testAccCheckGoogleSqlDatabaseRootUserDoesNotExist(
    85  						&instance),
    86  				),
    87  			},
    88  		},
    89  	})
    90  }
    91  func TestAccGoogleSqlDatabaseInstance_settings_basic(t *testing.T) {
    92  	var instance sqladmin.DatabaseInstance
    93  	databaseID := acctest.RandInt()
    94  
    95  	resource.Test(t, resource.TestCase{
    96  		PreCheck:     func() { testAccPreCheck(t) },
    97  		Providers:    testAccProviders,
    98  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
    99  		Steps: []resource.TestStep{
   100  			resource.TestStep{
   101  				Config: fmt.Sprintf(
   102  					testGoogleSqlDatabaseInstance_settings, databaseID),
   103  				Check: resource.ComposeTestCheckFunc(
   104  					testAccCheckGoogleSqlDatabaseInstanceExists(
   105  						"google_sql_database_instance.instance", &instance),
   106  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   107  						"google_sql_database_instance.instance", &instance),
   108  				),
   109  			},
   110  		},
   111  	})
   112  }
   113  
   114  func TestAccGoogleSqlDatabaseInstance_slave(t *testing.T) {
   115  	var instance sqladmin.DatabaseInstance
   116  	masterID := acctest.RandInt()
   117  	slaveID := acctest.RandInt()
   118  
   119  	resource.Test(t, resource.TestCase{
   120  		PreCheck:     func() { testAccPreCheck(t) },
   121  		Providers:    testAccProviders,
   122  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
   123  		Steps: []resource.TestStep{
   124  			resource.TestStep{
   125  				Config: fmt.Sprintf(
   126  					testGoogleSqlDatabaseInstance_slave, masterID, slaveID),
   127  				Check: resource.ComposeTestCheckFunc(
   128  					testAccCheckGoogleSqlDatabaseInstanceExists(
   129  						"google_sql_database_instance.instance_master", &instance),
   130  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   131  						"google_sql_database_instance.instance_master", &instance),
   132  					testAccCheckGoogleSqlDatabaseInstanceExists(
   133  						"google_sql_database_instance.instance_slave", &instance),
   134  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   135  						"google_sql_database_instance.instance_slave", &instance),
   136  				),
   137  			},
   138  		},
   139  	})
   140  }
   141  
   142  func TestAccGoogleSqlDatabaseInstance_diskspecs(t *testing.T) {
   143  	var instance sqladmin.DatabaseInstance
   144  	masterID := acctest.RandInt()
   145  
   146  	resource.Test(t, resource.TestCase{
   147  		PreCheck:     func() { testAccPreCheck(t) },
   148  		Providers:    testAccProviders,
   149  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
   150  		Steps: []resource.TestStep{
   151  			resource.TestStep{
   152  				Config: fmt.Sprintf(
   153  					testGoogleSqlDatabaseInstance_diskspecs, masterID),
   154  				Check: resource.ComposeTestCheckFunc(
   155  					testAccCheckGoogleSqlDatabaseInstanceExists(
   156  						"google_sql_database_instance.instance", &instance),
   157  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   158  						"google_sql_database_instance.instance", &instance),
   159  				),
   160  			},
   161  		},
   162  	})
   163  }
   164  
   165  func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) {
   166  	var instance sqladmin.DatabaseInstance
   167  	databaseID := acctest.RandInt()
   168  
   169  	resource.Test(t, resource.TestCase{
   170  		PreCheck:     func() { testAccPreCheck(t) },
   171  		Providers:    testAccProviders,
   172  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
   173  		Steps: []resource.TestStep{
   174  			resource.TestStep{
   175  				Config: fmt.Sprintf(
   176  					testGoogleSqlDatabaseInstance_basic, databaseID),
   177  				Check: resource.ComposeTestCheckFunc(
   178  					testAccCheckGoogleSqlDatabaseInstanceExists(
   179  						"google_sql_database_instance.instance", &instance),
   180  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   181  						"google_sql_database_instance.instance", &instance),
   182  				),
   183  			},
   184  			resource.TestStep{
   185  				Config: fmt.Sprintf(
   186  					testGoogleSqlDatabaseInstance_settings, databaseID),
   187  				Check: resource.ComposeTestCheckFunc(
   188  					testAccCheckGoogleSqlDatabaseInstanceExists(
   189  						"google_sql_database_instance.instance", &instance),
   190  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   191  						"google_sql_database_instance.instance", &instance),
   192  				),
   193  			},
   194  		},
   195  	})
   196  }
   197  
   198  func TestAccGoogleSqlDatabaseInstance_settings_downgrade(t *testing.T) {
   199  	var instance sqladmin.DatabaseInstance
   200  	databaseID := acctest.RandInt()
   201  
   202  	resource.Test(t, resource.TestCase{
   203  		PreCheck:     func() { testAccPreCheck(t) },
   204  		Providers:    testAccProviders,
   205  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
   206  		Steps: []resource.TestStep{
   207  			resource.TestStep{
   208  				Config: fmt.Sprintf(
   209  					testGoogleSqlDatabaseInstance_settings, databaseID),
   210  				Check: resource.ComposeTestCheckFunc(
   211  					testAccCheckGoogleSqlDatabaseInstanceExists(
   212  						"google_sql_database_instance.instance", &instance),
   213  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   214  						"google_sql_database_instance.instance", &instance),
   215  				),
   216  			},
   217  			resource.TestStep{
   218  				Config: fmt.Sprintf(
   219  					testGoogleSqlDatabaseInstance_basic, databaseID),
   220  				Check: resource.ComposeTestCheckFunc(
   221  					testAccCheckGoogleSqlDatabaseInstanceExists(
   222  						"google_sql_database_instance.instance", &instance),
   223  					testAccCheckGoogleSqlDatabaseInstanceEquals(
   224  						"google_sql_database_instance.instance", &instance),
   225  				),
   226  			},
   227  		},
   228  	})
   229  }
   230  
   231  // GH-4222
   232  func TestAccGoogleSqlDatabaseInstance_authNets(t *testing.T) {
   233  	// var instance sqladmin.DatabaseInstance
   234  	databaseID := acctest.RandInt()
   235  
   236  	resource.Test(t, resource.TestCase{
   237  		PreCheck:     func() { testAccPreCheck(t) },
   238  		Providers:    testAccProviders,
   239  		CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
   240  		Steps: []resource.TestStep{
   241  			resource.TestStep{
   242  				Config: fmt.Sprintf(
   243  					testGoogleSqlDatabaseInstance_authNets_step1, databaseID),
   244  			},
   245  			resource.TestStep{
   246  				Config: fmt.Sprintf(
   247  					testGoogleSqlDatabaseInstance_authNets_step2, databaseID),
   248  			},
   249  			resource.TestStep{
   250  				Config: fmt.Sprintf(
   251  					testGoogleSqlDatabaseInstance_authNets_step1, databaseID),
   252  			},
   253  		},
   254  	})
   255  }
   256  
   257  func testAccCheckGoogleSqlDatabaseInstanceEquals(n string,
   258  	instance *sqladmin.DatabaseInstance) resource.TestCheckFunc {
   259  	return func(s *terraform.State) error {
   260  		rs, ok := s.RootModule().Resources[n]
   261  		if !ok {
   262  			return fmt.Errorf("Not found: %s", n)
   263  		}
   264  		attributes := rs.Primary.Attributes
   265  
   266  		server := instance.Name
   267  		local := attributes["name"]
   268  		if server != local {
   269  			return fmt.Errorf("Error name mismatch, (%s, %s)", server, local)
   270  		}
   271  
   272  		server = instance.Settings.Tier
   273  		local = attributes["settings.0.tier"]
   274  		if server != local {
   275  			return fmt.Errorf("Error settings.tier mismatch, (%s, %s)", server, local)
   276  		}
   277  
   278  		server = strings.TrimPrefix(instance.MasterInstanceName, instance.Project+":")
   279  		local = attributes["master_instance_name"]
   280  		if server != local && len(server) > 0 && len(local) > 0 {
   281  			return fmt.Errorf("Error master_instance_name mismatch, (%s, %s)", server, local)
   282  		}
   283  
   284  		server = instance.Settings.ActivationPolicy
   285  		local = attributes["settings.0.activation_policy"]
   286  		if server != local && len(server) > 0 && len(local) > 0 {
   287  			return fmt.Errorf("Error settings.activation_policy mismatch, (%s, %s)", server, local)
   288  		}
   289  
   290  		if instance.Settings.BackupConfiguration != nil {
   291  			server = strconv.FormatBool(instance.Settings.BackupConfiguration.BinaryLogEnabled)
   292  			local = attributes["settings.0.backup_configuration.0.binary_log_enabled"]
   293  			if server != local && len(server) > 0 && len(local) > 0 {
   294  				return fmt.Errorf("Error settings.backup_configuration.binary_log_enabled mismatch, (%s, %s)", server, local)
   295  			}
   296  
   297  			server = strconv.FormatBool(instance.Settings.BackupConfiguration.Enabled)
   298  			local = attributes["settings.0.backup_configuration.0.enabled"]
   299  			if server != local && len(server) > 0 && len(local) > 0 {
   300  				return fmt.Errorf("Error settings.backup_configuration.enabled mismatch, (%s, %s)", server, local)
   301  			}
   302  
   303  			server = instance.Settings.BackupConfiguration.StartTime
   304  			local = attributes["settings.0.backup_configuration.0.start_time"]
   305  			if server != local && len(server) > 0 && len(local) > 0 {
   306  				return fmt.Errorf("Error settings.backup_configuration.start_time mismatch, (%s, %s)", server, local)
   307  			}
   308  		}
   309  
   310  		server = strconv.FormatBool(instance.Settings.CrashSafeReplicationEnabled)
   311  		local = attributes["settings.0.crash_safe_replication"]
   312  		if server != local && len(server) > 0 && len(local) > 0 {
   313  			return fmt.Errorf("Error settings.crash_safe_replication mismatch, (%s, %s)", server, local)
   314  		}
   315  
   316  		server = strconv.FormatBool(instance.Settings.StorageAutoResize)
   317  		local = attributes["settings.0.disk_autoresize"]
   318  		if server != local && len(server) > 0 && len(local) > 0 {
   319  			return fmt.Errorf("Error settings.disk_autoresize mismatch, (%s, %s)", server, local)
   320  		}
   321  
   322  		server = strconv.FormatInt(instance.Settings.DataDiskSizeGb, 10)
   323  		local = attributes["settings.0.disk_size"]
   324  		if server != local && len(server) > 0 && len(local) > 0 && local != "0" {
   325  			return fmt.Errorf("Error settings.disk_size mismatch, (%s, %s)", server, local)
   326  		}
   327  
   328  		server = instance.Settings.DataDiskType
   329  		local = attributes["settings.0.disk_type"]
   330  		if server != local && len(server) > 0 && len(local) > 0 {
   331  			return fmt.Errorf("Error settings.disk_type mismatch, (%s, %s)", server, local)
   332  		}
   333  
   334  		if instance.Settings.IpConfiguration != nil {
   335  			server = strconv.FormatBool(instance.Settings.IpConfiguration.Ipv4Enabled)
   336  			local = attributes["settings.0.ip_configuration.0.ipv4_enabled"]
   337  			if server != local && len(server) > 0 && len(local) > 0 {
   338  				return fmt.Errorf("Error settings.ip_configuration.ipv4_enabled mismatch, (%s, %s)", server, local)
   339  			}
   340  
   341  			server = strconv.FormatBool(instance.Settings.IpConfiguration.RequireSsl)
   342  			local = attributes["settings.0.ip_configuration.0.require_ssl"]
   343  			if server != local && len(server) > 0 && len(local) > 0 {
   344  				return fmt.Errorf("Error settings.ip_configuration.require_ssl mismatch, (%s, %s)", server, local)
   345  			}
   346  		}
   347  
   348  		if instance.Settings.LocationPreference != nil {
   349  			server = instance.Settings.LocationPreference.FollowGaeApplication
   350  			local = attributes["settings.0.location_preference.0.follow_gae_application"]
   351  			if server != local && len(server) > 0 && len(local) > 0 {
   352  				return fmt.Errorf("Error settings.location_preference.follow_gae_application mismatch, (%s, %s)", server, local)
   353  			}
   354  
   355  			server = instance.Settings.LocationPreference.Zone
   356  			local = attributes["settings.0.location_preference.0.zone"]
   357  			if server != local && len(server) > 0 && len(local) > 0 {
   358  				return fmt.Errorf("Error settings.location_preference.zone mismatch, (%s, %s)", server, local)
   359  			}
   360  		}
   361  
   362  		server = instance.Settings.PricingPlan
   363  		local = attributes["settings.0.pricing_plan"]
   364  		if server != local && len(server) > 0 && len(local) > 0 {
   365  			return fmt.Errorf("Error settings.pricing_plan mismatch, (%s, %s)", server, local)
   366  		}
   367  
   368  		if instance.ReplicaConfiguration != nil &&
   369  			instance.ReplicaConfiguration.MysqlReplicaConfiguration != nil {
   370  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.CaCertificate
   371  			local = attributes["replica_configuration.0.ca_certificate"]
   372  			if server != local && len(server) > 0 && len(local) > 0 {
   373  				return fmt.Errorf("Error replica_configuration.ca_certificate mismatch, (%s, %s)", server, local)
   374  			}
   375  
   376  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.ClientCertificate
   377  			local = attributes["replica_configuration.0.client_certificate"]
   378  			if server != local && len(server) > 0 && len(local) > 0 {
   379  				return fmt.Errorf("Error replica_configuration.client_certificate mismatch, (%s, %s)", server, local)
   380  			}
   381  
   382  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.ClientKey
   383  			local = attributes["replica_configuration.0.client_key"]
   384  			if server != local && len(server) > 0 && len(local) > 0 {
   385  				return fmt.Errorf("Error replica_configuration.client_key mismatch, (%s, %s)", server, local)
   386  			}
   387  
   388  			server = strconv.FormatInt(instance.ReplicaConfiguration.MysqlReplicaConfiguration.ConnectRetryInterval, 10)
   389  			local = attributes["replica_configuration.0.connect_retry_interval"]
   390  			if server != local && len(server) > 0 && len(local) > 0 {
   391  				return fmt.Errorf("Error replica_configuration.connect_retry_interval mismatch, (%s, %s)", server, local)
   392  			}
   393  
   394  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.DumpFilePath
   395  			local = attributes["replica_configuration.0.dump_file_path"]
   396  			if server != local && len(server) > 0 && len(local) > 0 {
   397  				return fmt.Errorf("Error replica_configuration.dump_file_path mismatch, (%s, %s)", server, local)
   398  			}
   399  
   400  			server = strconv.FormatInt(instance.ReplicaConfiguration.MysqlReplicaConfiguration.MasterHeartbeatPeriod, 10)
   401  			local = attributes["replica_configuration.0.master_heartbeat_period"]
   402  			if server != local && len(server) > 0 && len(local) > 0 {
   403  				return fmt.Errorf("Error replica_configuration.master_heartbeat_period mismatch, (%s, %s)", server, local)
   404  			}
   405  
   406  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.Password
   407  			local = attributes["replica_configuration.0.password"]
   408  			if server != local && len(server) > 0 && len(local) > 0 {
   409  				return fmt.Errorf("Error replica_configuration.password mismatch, (%s, %s)", server, local)
   410  			}
   411  
   412  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.SslCipher
   413  			local = attributes["replica_configuration.0.ssl_cipher"]
   414  			if server != local && len(server) > 0 && len(local) > 0 {
   415  				return fmt.Errorf("Error replica_configuration.ssl_cipher mismatch, (%s, %s)", server, local)
   416  			}
   417  
   418  			server = instance.ReplicaConfiguration.MysqlReplicaConfiguration.Username
   419  			local = attributes["replica_configuration.0.username"]
   420  			if server != local && len(server) > 0 && len(local) > 0 {
   421  				return fmt.Errorf("Error replica_configuration.username mismatch, (%s, %s)", server, local)
   422  			}
   423  
   424  			server = strconv.FormatBool(instance.ReplicaConfiguration.MysqlReplicaConfiguration.VerifyServerCertificate)
   425  			local = attributes["replica_configuration.0.verify_server_certificate"]
   426  			if server != local && len(server) > 0 && len(local) > 0 {
   427  				return fmt.Errorf("Error replica_configuration.verify_server_certificate mismatch, (%s, %s)", server, local)
   428  			}
   429  		}
   430  
   431  		return nil
   432  	}
   433  }
   434  
   435  func testAccCheckGoogleSqlDatabaseInstanceExists(n string,
   436  	instance *sqladmin.DatabaseInstance) resource.TestCheckFunc {
   437  	return func(s *terraform.State) error {
   438  		config := testAccProvider.Meta().(*Config)
   439  		rs, ok := s.RootModule().Resources[n]
   440  		if !ok {
   441  			return fmt.Errorf("Not found: %s", n)
   442  		}
   443  
   444  		found, err := config.clientSqlAdmin.Instances.Get(config.Project,
   445  			rs.Primary.Attributes["name"]).Do()
   446  
   447  		*instance = *found
   448  
   449  		if err != nil {
   450  			return fmt.Errorf("Not found: %s", n)
   451  		}
   452  
   453  		return nil
   454  	}
   455  }
   456  
   457  func testAccGoogleSqlDatabaseInstanceDestroy(s *terraform.State) error {
   458  	for _, rs := range s.RootModule().Resources {
   459  		config := testAccProvider.Meta().(*Config)
   460  		if rs.Type != "google_sql_database_instance" {
   461  			continue
   462  		}
   463  
   464  		_, err := config.clientSqlAdmin.Instances.Get(config.Project,
   465  			rs.Primary.Attributes["name"]).Do()
   466  		if err == nil {
   467  			return fmt.Errorf("Database Instance still exists")
   468  		}
   469  	}
   470  
   471  	return nil
   472  }
   473  
   474  func testAccCheckGoogleSqlDatabaseRootUserDoesNotExist(
   475  	instance *sqladmin.DatabaseInstance) resource.TestCheckFunc {
   476  	return func(s *terraform.State) error {
   477  		config := testAccProvider.Meta().(*Config)
   478  
   479  		users, err := config.clientSqlAdmin.Users.List(config.Project, instance.Name).Do()
   480  
   481  		if err != nil {
   482  			return fmt.Errorf("Could not list database users for %q: %s", instance.Name, err)
   483  		}
   484  
   485  		for _, u := range users.Items {
   486  			if u.Name == "root" && u.Host == "%" {
   487  				return fmt.Errorf("%v@%v user still exists", u.Name, u.Host)
   488  			}
   489  		}
   490  
   491  		return nil
   492  	}
   493  }
   494  
   495  var testGoogleSqlDatabaseInstance_basic = `
   496  resource "google_sql_database_instance" "instance" {
   497  	name = "tf-lw-%d"
   498  	region = "us-central"
   499  	settings {
   500  		tier = "D0"
   501  		crash_safe_replication = false
   502  	}
   503  }
   504  `
   505  
   506  var testGoogleSqlDatabaseInstance_basic2 = `
   507  resource "google_sql_database_instance" "instance" {
   508  	region = "us-central"
   509  	settings {
   510  		tier = "D0"
   511  		crash_safe_replication = false
   512  	}
   513  }
   514  `
   515  var testGoogleSqlDatabaseInstance_basic3 = `
   516  resource "google_sql_database_instance" "instance" {
   517  	name = "tf-lw-%d"
   518  	region = "us-central"
   519  	settings {
   520  		tier = "db-f1-micro"
   521  	}
   522  }
   523  `
   524  
   525  var testGoogleSqlDatabaseInstance_settings = `
   526  resource "google_sql_database_instance" "instance" {
   527  	name = "tf-lw-%d"
   528  	region = "us-central"
   529  	settings {
   530  		tier = "D0"
   531  		crash_safe_replication = false
   532  		replication_type = "ASYNCHRONOUS"
   533  		location_preference {
   534  			zone = "us-central1-f"
   535  		}
   536  
   537  		ip_configuration {
   538  			ipv4_enabled = "true"
   539  			authorized_networks {
   540  				value = "108.12.12.12"
   541  				name = "misc"
   542  				expiration_time = "2017-11-15T16:19:00.094Z"
   543  			}
   544  		}
   545  
   546  		backup_configuration {
   547  			enabled = "true"
   548  			start_time = "19:19"
   549  		}
   550  
   551  		activation_policy = "ON_DEMAND"
   552  	}
   553  }
   554  `
   555  
   556  // Note - this test is not feasible to run unless we generate
   557  // backups first.
   558  var testGoogleSqlDatabaseInstance_replica = `
   559  resource "google_sql_database_instance" "instance_master" {
   560  	name = "tf-lw-%d"
   561  	database_version = "MYSQL_5_6"
   562  	region = "us-east1"
   563  
   564  	settings {
   565  		tier = "D0"
   566  		crash_safe_replication = true
   567  
   568  		backup_configuration {
   569  			enabled = true
   570  			start_time = "00:00"
   571  			binary_log_enabled = true
   572  		}
   573  	}
   574  }
   575  
   576  resource "google_sql_database_instance" "instance" {
   577  	name = "tf-lw-%d"
   578  	database_version = "MYSQL_5_6"
   579  	region = "us-central"
   580  
   581  	settings {
   582  		tier = "D0"
   583  	}
   584  
   585  	master_instance_name = "${google_sql_database_instance.instance_master.name}"
   586  
   587  	replica_configuration {
   588  		ca_certificate = "${file("~/tmp/fake.pem")}"
   589  		client_certificate = "${file("~/tmp/fake.pem")}"
   590  		client_key = "${file("~/tmp/fake.pem")}"
   591  		connect_retry_interval = 100
   592  		master_heartbeat_period = 10000
   593  		password = "password"
   594  		username = "username"
   595  		ssl_cipher = "ALL"
   596  		verify_server_certificate = false
   597  	}
   598  }
   599  `
   600  
   601  var testGoogleSqlDatabaseInstance_slave = `
   602  resource "google_sql_database_instance" "instance_master" {
   603  	name = "tf-lw-%d"
   604  	region = "us-central1"
   605  
   606  	settings {
   607  		tier = "db-f1-micro"
   608  
   609  		backup_configuration {
   610  			enabled = true
   611  			binary_log_enabled = true
   612  		}
   613  	}
   614  }
   615  
   616  resource "google_sql_database_instance" "instance_slave" {
   617  	name = "tf-lw-%d"
   618  	region = "us-central1"
   619  
   620  	master_instance_name = "${google_sql_database_instance.instance_master.name}"
   621  
   622  	settings {
   623  		tier = "db-f1-micro"
   624  	}
   625  }
   626  `
   627  
   628  var testGoogleSqlDatabaseInstance_diskspecs = `
   629  resource "google_sql_database_instance" "instance" {
   630  	name = "tf-lw-%d"
   631  	region = "us-central1"
   632  
   633  	settings {
   634  		tier = "db-f1-micro"
   635  		disk_autoresize = true
   636  		disk_size = 15
   637  		disk_type = "PD_HDD"
   638  	}
   639  }
   640  `
   641  
   642  var testGoogleSqlDatabaseInstance_authNets_step1 = `
   643  resource "google_sql_database_instance" "instance" {
   644  	name = "tf-lw-%d"
   645  	region = "us-central"
   646  	settings {
   647  		tier = "D0"
   648  		crash_safe_replication = false
   649  
   650  		ip_configuration {
   651  			ipv4_enabled = "true"
   652  			authorized_networks {
   653  				value = "108.12.12.12"
   654  				name = "misc"
   655  				expiration_time = "2017-11-15T16:19:00.094Z"
   656  			}
   657  		}
   658  	}
   659  }
   660  `
   661  
   662  var testGoogleSqlDatabaseInstance_authNets_step2 = `
   663  resource "google_sql_database_instance" "instance" {
   664  	name = "tf-lw-%d"
   665  	region = "us-central"
   666  	settings {
   667  		tier = "D0"
   668  		crash_safe_replication = false
   669  
   670  		ip_configuration {
   671  			ipv4_enabled = "true"
   672  		}
   673  	}
   674  }
   675  `