github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/alicloud/resource_alicloud_db_instance_test.go (about)

     1  package alicloud
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/denverdino/aliyungo/common"
     6  	"github.com/denverdino/aliyungo/rds"
     7  	"github.com/hashicorp/terraform/helper/resource"
     8  	"github.com/hashicorp/terraform/terraform"
     9  	"log"
    10  	"strings"
    11  	"testing"
    12  )
    13  
    14  func TestAccAlicloudDBInstance_basic(t *testing.T) {
    15  	var instance rds.DBInstanceAttribute
    16  
    17  	resource.Test(t, resource.TestCase{
    18  		PreCheck: func() {
    19  			testAccPreCheck(t)
    20  		},
    21  
    22  		// module name
    23  		IDRefreshName: "alicloud_db_instance.foo",
    24  
    25  		Providers:    testAccProviders,
    26  		CheckDestroy: testAccCheckDBInstanceDestroy,
    27  		Steps: []resource.TestStep{
    28  			resource.TestStep{
    29  				Config: testAccDBInstanceConfig,
    30  				Check: resource.ComposeTestCheckFunc(
    31  					testAccCheckDBInstanceExists(
    32  						"alicloud_db_instance.foo", &instance),
    33  					resource.TestCheckResourceAttr(
    34  						"alicloud_db_instance.foo",
    35  						"port",
    36  						"3306"),
    37  					resource.TestCheckResourceAttr(
    38  						"alicloud_db_instance.foo",
    39  						"db_instance_storage",
    40  						"10"),
    41  					resource.TestCheckResourceAttr(
    42  						"alicloud_db_instance.foo",
    43  						"instance_network_type",
    44  						"Classic"),
    45  					resource.TestCheckResourceAttr(
    46  						"alicloud_db_instance.foo",
    47  						"db_instance_net_type",
    48  						"Intranet"),
    49  					resource.TestCheckResourceAttr(
    50  						"alicloud_db_instance.foo",
    51  						"engine_version",
    52  						"5.6"),
    53  					resource.TestCheckResourceAttr(
    54  						"alicloud_db_instance.foo",
    55  						"engine",
    56  						"MySQL"),
    57  				),
    58  			},
    59  		},
    60  	})
    61  
    62  }
    63  
    64  func TestAccAlicloudDBInstance_vpc(t *testing.T) {
    65  	var instance rds.DBInstanceAttribute
    66  
    67  	resource.Test(t, resource.TestCase{
    68  		PreCheck: func() {
    69  			testAccPreCheck(t)
    70  		},
    71  
    72  		// module name
    73  		IDRefreshName: "alicloud_db_instance.foo",
    74  
    75  		Providers:    testAccProviders,
    76  		CheckDestroy: testAccCheckDBInstanceDestroy,
    77  		Steps: []resource.TestStep{
    78  			resource.TestStep{
    79  				Config: testAccDBInstance_vpc,
    80  				Check: resource.ComposeTestCheckFunc(
    81  					testAccCheckDBInstanceExists(
    82  						"alicloud_db_instance.foo", &instance),
    83  					resource.TestCheckResourceAttr(
    84  						"alicloud_db_instance.foo",
    85  						"port",
    86  						"3306"),
    87  					resource.TestCheckResourceAttr(
    88  						"alicloud_db_instance.foo",
    89  						"db_instance_storage",
    90  						"10"),
    91  					resource.TestCheckResourceAttr(
    92  						"alicloud_db_instance.foo",
    93  						"instance_network_type",
    94  						"VPC"),
    95  					resource.TestCheckResourceAttr(
    96  						"alicloud_db_instance.foo",
    97  						"db_instance_net_type",
    98  						"Intranet"),
    99  					resource.TestCheckResourceAttr(
   100  						"alicloud_db_instance.foo",
   101  						"engine_version",
   102  						"5.6"),
   103  					resource.TestCheckResourceAttr(
   104  						"alicloud_db_instance.foo",
   105  						"engine",
   106  						"MySQL"),
   107  				),
   108  			},
   109  		},
   110  	})
   111  
   112  }
   113  
   114  func TestC2CAlicloudDBInstance_prepaid_order(t *testing.T) {
   115  	var instance rds.DBInstanceAttribute
   116  
   117  	resource.Test(t, resource.TestCase{
   118  		PreCheck: func() {
   119  			testAccPreCheck(t)
   120  		},
   121  
   122  		// module name
   123  		IDRefreshName: "alicloud_db_instance.foo",
   124  
   125  		Providers:    testAccProviders,
   126  		CheckDestroy: testAccCheckDBInstanceDestroy,
   127  		Steps: []resource.TestStep{
   128  			resource.TestStep{
   129  				Config: testAccDBInstance_prepaid_order,
   130  				Check: resource.ComposeTestCheckFunc(
   131  					testAccCheckDBInstanceExists(
   132  						"alicloud_db_instance.foo", &instance),
   133  					resource.TestCheckResourceAttr(
   134  						"alicloud_db_instance.foo",
   135  						"port",
   136  						"3306"),
   137  					resource.TestCheckResourceAttr(
   138  						"alicloud_db_instance.foo",
   139  						"db_instance_storage",
   140  						"10"),
   141  					resource.TestCheckResourceAttr(
   142  						"alicloud_db_instance.foo",
   143  						"instance_network_type",
   144  						"VPC"),
   145  					resource.TestCheckResourceAttr(
   146  						"alicloud_db_instance.foo",
   147  						"db_instance_net_type",
   148  						"Intranet"),
   149  					resource.TestCheckResourceAttr(
   150  						"alicloud_db_instance.foo",
   151  						"engine_version",
   152  						"5.6"),
   153  					resource.TestCheckResourceAttr(
   154  						"alicloud_db_instance.foo",
   155  						"engine",
   156  						"MySQL"),
   157  				),
   158  			},
   159  		},
   160  	})
   161  
   162  }
   163  
   164  func TestAccAlicloudDBInstance_multiIZ(t *testing.T) {
   165  	var instance rds.DBInstanceAttribute
   166  
   167  	resource.Test(t, resource.TestCase{
   168  		PreCheck: func() {
   169  			testAccPreCheck(t)
   170  		},
   171  
   172  		// module name
   173  		IDRefreshName: "alicloud_db_instance.foo",
   174  
   175  		Providers:    testAccProviders,
   176  		CheckDestroy: testAccCheckDBInstanceDestroy,
   177  		Steps: []resource.TestStep{
   178  			resource.TestStep{
   179  				Config: testAccDBInstance_multiIZ,
   180  				Check: resource.ComposeTestCheckFunc(
   181  					testAccCheckDBInstanceExists(
   182  						"alicloud_db_instance.foo", &instance),
   183  					testAccCheckDBInstanceMultiIZ(&instance),
   184  				),
   185  			},
   186  		},
   187  	})
   188  
   189  }
   190  
   191  func TestAccAlicloudDBInstance_database(t *testing.T) {
   192  	var instance rds.DBInstanceAttribute
   193  
   194  	resource.Test(t, resource.TestCase{
   195  		PreCheck: func() {
   196  			testAccPreCheck(t)
   197  		},
   198  
   199  		// module name
   200  		IDRefreshName: "alicloud_db_instance.foo",
   201  
   202  		Providers:    testAccProviders,
   203  		CheckDestroy: testAccCheckDBInstanceDestroy,
   204  		Steps: []resource.TestStep{
   205  			resource.TestStep{
   206  				Config: testAccDBInstance_database,
   207  				Check: resource.ComposeTestCheckFunc(
   208  					testAccCheckDBInstanceExists(
   209  						"alicloud_db_instance.foo", &instance),
   210  					resource.TestCheckResourceAttr("alicloud_db_instance.foo", "db_mappings.#", "2"),
   211  				),
   212  			},
   213  
   214  			resource.TestStep{
   215  				Config: testAccDBInstance_database_update,
   216  				Check: resource.ComposeTestCheckFunc(
   217  					testAccCheckDBInstanceExists(
   218  						"alicloud_db_instance.foo", &instance),
   219  					resource.TestCheckResourceAttr("alicloud_db_instance.foo", "db_mappings.#", "3"),
   220  				),
   221  			},
   222  		},
   223  	})
   224  
   225  }
   226  
   227  func TestAccAlicloudDBInstance_account(t *testing.T) {
   228  	var instance rds.DBInstanceAttribute
   229  
   230  	resource.Test(t, resource.TestCase{
   231  		PreCheck: func() {
   232  			testAccPreCheck(t)
   233  		},
   234  
   235  		// module name
   236  		IDRefreshName: "alicloud_db_instance.foo",
   237  
   238  		Providers:    testAccProviders,
   239  		CheckDestroy: testAccCheckDBInstanceDestroy,
   240  		Steps: []resource.TestStep{
   241  			resource.TestStep{
   242  				Config: testAccDBInstance_grantDatabasePrivilege2Account,
   243  				Check: resource.ComposeTestCheckFunc(
   244  					testAccCheckDBInstanceExists(
   245  						"alicloud_db_instance.foo", &instance),
   246  					resource.TestCheckResourceAttr("alicloud_db_instance.foo", "db_mappings.#", "2"),
   247  					testAccCheckAccountHasPrivilege2Database("alicloud_db_instance.foo", "tester", "foo", "ReadWrite"),
   248  				),
   249  			},
   250  		},
   251  	})
   252  
   253  }
   254  
   255  func TestAccAlicloudDBInstance_allocatePublicConnection(t *testing.T) {
   256  	var instance rds.DBInstanceAttribute
   257  
   258  	resource.Test(t, resource.TestCase{
   259  		PreCheck: func() {
   260  			testAccPreCheck(t)
   261  		},
   262  
   263  		// module name
   264  		IDRefreshName: "alicloud_db_instance.foo",
   265  
   266  		Providers:    testAccProviders,
   267  		CheckDestroy: testAccCheckDBInstanceDestroy,
   268  		Steps: []resource.TestStep{
   269  			resource.TestStep{
   270  				Config: testAccDBInstance_allocatePublicConnection,
   271  				Check: resource.ComposeTestCheckFunc(
   272  					testAccCheckDBInstanceExists(
   273  						"alicloud_db_instance.foo", &instance),
   274  					resource.TestCheckResourceAttr("alicloud_db_instance.foo", "connections.#", "2"),
   275  					testAccCheckHasPublicConnection("alicloud_db_instance.foo"),
   276  				),
   277  			},
   278  		},
   279  	})
   280  
   281  }
   282  
   283  func TestAccAlicloudDBInstance_backupPolicy(t *testing.T) {
   284  	var policies []map[string]interface{}
   285  
   286  	resource.Test(t, resource.TestCase{
   287  		PreCheck: func() {
   288  			testAccPreCheck(t)
   289  		},
   290  
   291  		// module name
   292  		IDRefreshName: "alicloud_db_instance.foo",
   293  
   294  		Providers:    testAccProviders,
   295  		CheckDestroy: testAccCheckDBInstanceDestroy,
   296  		Steps: []resource.TestStep{
   297  			resource.TestStep{
   298  				Config: testAccDBInstance_backup,
   299  				Check: resource.ComposeTestCheckFunc(
   300  					testAccCheckBackupPolicyExists(
   301  						"alicloud_db_instance.foo", policies),
   302  					testAccCheckKeyValueInMaps(policies, "backup policy", "preferred_backup_period", "Wednesday,Thursday"),
   303  					testAccCheckKeyValueInMaps(policies, "backup policy", "preferred_backup_time", "00:00Z-01:00Z"),
   304  				),
   305  			},
   306  		},
   307  	})
   308  
   309  }
   310  
   311  func TestAccAlicloudDBInstance_securityIps(t *testing.T) {
   312  	var ips []map[string]interface{}
   313  
   314  	resource.Test(t, resource.TestCase{
   315  		PreCheck: func() {
   316  			testAccPreCheck(t)
   317  		},
   318  
   319  		// module name
   320  		IDRefreshName: "alicloud_db_instance.foo",
   321  
   322  		Providers:    testAccProviders,
   323  		CheckDestroy: testAccCheckDBInstanceDestroy,
   324  		Steps: []resource.TestStep{
   325  			resource.TestStep{
   326  				Config: testAccDBInstance_securityIps,
   327  				Check: resource.ComposeTestCheckFunc(
   328  					testAccCheckSecurityIpExists(
   329  						"alicloud_db_instance.foo", ips),
   330  					testAccCheckKeyValueInMaps(ips, "security ip", "security_ips", "127.0.0.1"),
   331  				),
   332  			},
   333  
   334  			resource.TestStep{
   335  				Config: testAccDBInstance_securityIpsConfig,
   336  				Check: resource.ComposeTestCheckFunc(
   337  					testAccCheckSecurityIpExists(
   338  						"alicloud_db_instance.foo", ips),
   339  					testAccCheckKeyValueInMaps(ips, "security ip", "security_ips", "10.168.1.12,100.69.7.112"),
   340  				),
   341  			},
   342  		},
   343  	})
   344  
   345  }
   346  
   347  func TestAccAlicloudDBInstance_upgradeClass(t *testing.T) {
   348  	var instance rds.DBInstanceAttribute
   349  
   350  	resource.Test(t, resource.TestCase{
   351  		PreCheck: func() {
   352  			testAccPreCheck(t)
   353  		},
   354  
   355  		// module name
   356  		IDRefreshName: "alicloud_db_instance.foo",
   357  
   358  		Providers:    testAccProviders,
   359  		CheckDestroy: testAccCheckDBInstanceDestroy,
   360  		Steps: []resource.TestStep{
   361  			resource.TestStep{
   362  				Config: testAccDBInstance_class,
   363  				Check: resource.ComposeTestCheckFunc(
   364  					testAccCheckDBInstanceExists(
   365  						"alicloud_db_instance.foo", &instance),
   366  					resource.TestCheckResourceAttr("alicloud_db_instance.foo", "db_instance_class", "rds.mysql.t1.small"),
   367  				),
   368  			},
   369  
   370  			resource.TestStep{
   371  				Config: testAccDBInstance_classUpgrade,
   372  				Check: resource.ComposeTestCheckFunc(
   373  					testAccCheckDBInstanceExists(
   374  						"alicloud_db_instance.foo", &instance),
   375  					resource.TestCheckResourceAttr("alicloud_db_instance.foo", "db_instance_class", "rds.mysql.s1.small"),
   376  				),
   377  			},
   378  		},
   379  	})
   380  
   381  }
   382  
   383  func testAccCheckSecurityIpExists(n string, ips []map[string]interface{}) resource.TestCheckFunc {
   384  	return func(s *terraform.State) error {
   385  		rs, ok := s.RootModule().Resources[n]
   386  		if !ok {
   387  			return fmt.Errorf("Not found: %s", n)
   388  		}
   389  
   390  		if rs.Primary.ID == "" {
   391  			return fmt.Errorf("No DB Instance ID is set")
   392  		}
   393  
   394  		conn := testAccProvider.Meta().(*AliyunClient).rdsconn
   395  		args := rds.DescribeDBInstanceIPsArgs{
   396  			DBInstanceId: rs.Primary.ID,
   397  		}
   398  
   399  		resp, err := conn.DescribeDBInstanceIPs(&args)
   400  		log.Printf("[DEBUG] check instance %s security ip %#v", rs.Primary.ID, resp)
   401  
   402  		if err != nil {
   403  			return err
   404  		}
   405  
   406  		p := resp.Items.DBInstanceIPArray
   407  
   408  		if len(p) < 1 {
   409  			return fmt.Errorf("DB security ip not found")
   410  		}
   411  
   412  		ips = flattenDBSecurityIPs(p)
   413  		return nil
   414  	}
   415  }
   416  
   417  func testAccCheckDBInstanceMultiIZ(i *rds.DBInstanceAttribute) resource.TestCheckFunc {
   418  	return func(s *terraform.State) error {
   419  		if !strings.Contains(i.ZoneId, MULTI_IZ_SYMBOL) {
   420  			return fmt.Errorf("Current region does not support multiIZ.")
   421  		}
   422  		return nil
   423  	}
   424  }
   425  
   426  func testAccCheckAccountHasPrivilege2Database(n, accountName, dbName, privilege string) resource.TestCheckFunc {
   427  	return func(s *terraform.State) error {
   428  		rs, ok := s.RootModule().Resources[n]
   429  		if !ok {
   430  			return fmt.Errorf("Not found: %s", n)
   431  		}
   432  
   433  		if rs.Primary.ID == "" {
   434  			return fmt.Errorf("No DB instance ID is set")
   435  		}
   436  
   437  		conn := testAccProvider.Meta().(*AliyunClient).rdsconn
   438  		if err := conn.WaitForAccountPrivilege(rs.Primary.ID, accountName, dbName, rds.AccountPrivilege(privilege), 50); err != nil {
   439  			return fmt.Errorf("Failed to grant database %s privilege to account %s: %v", dbName, accountName, err)
   440  		}
   441  		return nil
   442  	}
   443  }
   444  
   445  func testAccCheckHasPublicConnection(n string) resource.TestCheckFunc {
   446  	return func(s *terraform.State) error {
   447  		rs, ok := s.RootModule().Resources[n]
   448  		if !ok {
   449  			return fmt.Errorf("Not found: %s", n)
   450  		}
   451  
   452  		if rs.Primary.ID == "" {
   453  			return fmt.Errorf("No DB instance ID is set")
   454  		}
   455  
   456  		conn := testAccProvider.Meta().(*AliyunClient).rdsconn
   457  		if err := conn.WaitForPublicConnection(rs.Primary.ID, 50); err != nil {
   458  			return fmt.Errorf("Failed to allocate public connection: %v", err)
   459  		}
   460  		return nil
   461  	}
   462  }
   463  
   464  func testAccCheckDBInstanceExists(n string, d *rds.DBInstanceAttribute) resource.TestCheckFunc {
   465  	return func(s *terraform.State) error {
   466  		rs, ok := s.RootModule().Resources[n]
   467  		if !ok {
   468  			return fmt.Errorf("Not found: %s", n)
   469  		}
   470  
   471  		if rs.Primary.ID == "" {
   472  			return fmt.Errorf("No DB Instance ID is set")
   473  		}
   474  
   475  		client := testAccProvider.Meta().(*AliyunClient)
   476  		attr, err := client.DescribeDBInstanceById(rs.Primary.ID)
   477  		log.Printf("[DEBUG] check instance %s attribute %#v", rs.Primary.ID, attr)
   478  
   479  		if err != nil {
   480  			return err
   481  		}
   482  
   483  		if attr == nil {
   484  			return fmt.Errorf("DB Instance not found")
   485  		}
   486  
   487  		*d = *attr
   488  		return nil
   489  	}
   490  }
   491  
   492  func testAccCheckBackupPolicyExists(n string, ps []map[string]interface{}) resource.TestCheckFunc {
   493  	return func(s *terraform.State) error {
   494  		rs, ok := s.RootModule().Resources[n]
   495  		if !ok {
   496  			return fmt.Errorf("Backup policy not found: %s", n)
   497  		}
   498  
   499  		if rs.Primary.ID == "" {
   500  			return fmt.Errorf("No DB Instance ID is set")
   501  		}
   502  
   503  		conn := testAccProvider.Meta().(*AliyunClient).rdsconn
   504  
   505  		args := rds.DescribeBackupPolicyArgs{
   506  			DBInstanceId: rs.Primary.ID,
   507  		}
   508  		resp, err := conn.DescribeBackupPolicy(&args)
   509  		log.Printf("[DEBUG] check instance %s backup policy %#v", rs.Primary.ID, resp)
   510  
   511  		if err != nil {
   512  			return err
   513  		}
   514  
   515  		var bs []rds.BackupPolicy
   516  		bs = append(bs, resp.BackupPolicy)
   517  		ps = flattenDBBackup(bs)
   518  
   519  		return nil
   520  	}
   521  }
   522  
   523  func testAccCheckKeyValueInMaps(ps []map[string]interface{}, propName, key, value string) resource.TestCheckFunc {
   524  	return func(s *terraform.State) error {
   525  		for _, policy := range ps {
   526  			if policy[key].(string) != value {
   527  				return fmt.Errorf("DB %s attribute '%s' expected %#v, got %#v", propName, key, value, policy[key])
   528  			}
   529  		}
   530  		return nil
   531  	}
   532  }
   533  
   534  func testAccCheckDBInstanceDestroy(s *terraform.State) error {
   535  	client := testAccProvider.Meta().(*AliyunClient)
   536  
   537  	for _, rs := range s.RootModule().Resources {
   538  		if rs.Type != "alicloud_db_instance" {
   539  			continue
   540  		}
   541  
   542  		ins, err := client.DescribeDBInstanceById(rs.Primary.ID)
   543  
   544  		if ins != nil {
   545  			return fmt.Errorf("Error DB Instance still exist")
   546  		}
   547  
   548  		// Verify the error is what we want
   549  		if err != nil {
   550  			// Verify the error is what we want
   551  			e, _ := err.(*common.Error)
   552  			if e.ErrorResponse.Code == InstanceNotfound {
   553  				continue
   554  			}
   555  			return err
   556  		}
   557  	}
   558  
   559  	return nil
   560  }
   561  
   562  const testAccDBInstanceConfig = `
   563  resource "alicloud_db_instance" "foo" {
   564  	engine = "MySQL"
   565  	engine_version = "5.6"
   566  	db_instance_class = "rds.mysql.t1.small"
   567  	db_instance_storage = "10"
   568  	instance_charge_type = "Postpaid"
   569  	db_instance_net_type = "Intranet"
   570  }
   571  `
   572  
   573  const testAccDBInstance_vpc = `
   574  data "alicloud_zones" "default" {
   575  	"available_resource_creation"= "VSwitch"
   576  }
   577  
   578  resource "alicloud_vpc" "foo" {
   579  	name = "tf_test_foo"
   580  	cidr_block = "172.16.0.0/12"
   581  }
   582  
   583  resource "alicloud_vswitch" "foo" {
   584   	vpc_id = "${alicloud_vpc.foo.id}"
   585   	cidr_block = "172.16.0.0/21"
   586   	availability_zone = "${data.alicloud_zones.default.zones.0.id}"
   587  }
   588  
   589  resource "alicloud_db_instance" "foo" {
   590  	engine = "MySQL"
   591  	engine_version = "5.6"
   592  	db_instance_class = "rds.mysql.t1.small"
   593  	db_instance_storage = "10"
   594  	instance_charge_type = "Postpaid"
   595  	db_instance_net_type = "Intranet"
   596  
   597  	vswitch_id = "${alicloud_vswitch.foo.id}"
   598  }
   599  `
   600  const testAccDBInstance_multiIZ = `
   601  resource "alicloud_db_instance" "foo" {
   602  	engine = "MySQL"
   603  	engine_version = "5.6"
   604  	db_instance_class = "rds.mysql.t1.small"
   605  	db_instance_storage = "10"
   606  	db_instance_net_type = "Intranet"
   607  	multi_az = true
   608  }
   609  `
   610  
   611  const testAccDBInstance_prepaid_order = `
   612  resource "alicloud_db_instance" "foo" {
   613  	engine = "MySQL"
   614  	engine_version = "5.6"
   615  	db_instance_class = "rds.mysql.t1.small"
   616  	db_instance_storage = "10"
   617  	instance_charge_type = "Prepaid"
   618  	db_instance_net_type = "Intranet"
   619  }
   620  `
   621  
   622  const testAccDBInstance_database = `
   623  resource "alicloud_db_instance" "foo" {
   624  	engine = "MySQL"
   625  	engine_version = "5.6"
   626  	db_instance_class = "rds.mysql.t1.small"
   627  	db_instance_storage = "10"
   628  	instance_charge_type = "Postpaid"
   629  	db_instance_net_type = "Intranet"
   630  
   631  	db_mappings = [
   632  	    {
   633  	      "db_name" = "foo"
   634  	      "character_set_name" = "utf8"
   635  	      "db_description" = "tf"
   636  	    },{
   637  	      "db_name" = "bar"
   638  	      "character_set_name" = "utf8"
   639  	      "db_description" = "tf"
   640  	    }]
   641  }
   642  `
   643  const testAccDBInstance_database_update = `
   644  resource "alicloud_db_instance" "foo" {
   645  	engine = "MySQL"
   646  	engine_version = "5.6"
   647  	db_instance_class = "rds.mysql.t1.small"
   648  	db_instance_storage = "10"
   649  	instance_charge_type = "Postpaid"
   650  	db_instance_net_type = "Intranet"
   651  
   652  	db_mappings = [
   653  	    {
   654  	      "db_name" = "foo"
   655  	      "character_set_name" = "utf8"
   656  	      "db_description" = "tf"
   657  	    },{
   658  	      "db_name" = "bar"
   659  	      "character_set_name" = "utf8"
   660  	      "db_description" = "tf"
   661  	    },{
   662  	      "db_name" = "zzz"
   663  	      "character_set_name" = "utf8"
   664  	      "db_description" = "tf"
   665  	    }]
   666  }
   667  `
   668  
   669  const testAccDBInstance_grantDatabasePrivilege2Account = `
   670  resource "alicloud_db_instance" "foo" {
   671  	engine = "MySQL"
   672  	engine_version = "5.6"
   673  	db_instance_class = "rds.mysql.t1.small"
   674  	db_instance_storage = "10"
   675  	instance_charge_type = "Postpaid"
   676  	db_instance_net_type = "Intranet"
   677  
   678  	master_user_name = "tester"
   679  	master_user_password = "Test12345"
   680  
   681  	db_mappings = [
   682  	    {
   683  	      "db_name" = "foo"
   684  	      "character_set_name" = "utf8"
   685  	      "db_description" = "tf"
   686  	    },{
   687  	      "db_name" = "bar"
   688  	      "character_set_name" = "utf8"
   689  	      "db_description" = "tf"
   690  	    }]
   691  }
   692  `
   693  
   694  const testAccDBInstance_allocatePublicConnection = `
   695  resource "alicloud_db_instance" "foo" {
   696  	engine = "MySQL"
   697  	engine_version = "5.6"
   698  	db_instance_class = "rds.mysql.t1.small"
   699  	db_instance_storage = "10"
   700  	instance_charge_type = "Postpaid"
   701  	db_instance_net_type = "Intranet"
   702  
   703  	master_user_name = "tester"
   704  	master_user_password = "Test12345"
   705  
   706  	allocate_public_connection = true
   707  }
   708  `
   709  
   710  const testAccDBInstance_backup = `
   711  resource "alicloud_db_instance" "foo" {
   712  	engine = "MySQL"
   713  	engine_version = "5.6"
   714  	db_instance_class = "rds.mysql.t1.small"
   715  	db_instance_storage = "10"
   716  	instance_charge_type = "Postpaid"
   717  	db_instance_net_type = "Intranet"
   718  
   719  	preferred_backup_period = ["Wednesday","Thursday"]
   720  	preferred_backup_time = "00:00Z-01:00Z"
   721  	backup_retention_period = 9
   722  }
   723  `
   724  
   725  const testAccDBInstance_securityIps = `
   726  resource "alicloud_db_instance" "foo" {
   727  	engine = "MySQL"
   728  	engine_version = "5.6"
   729  	db_instance_class = "rds.mysql.t1.small"
   730  	db_instance_storage = "10"
   731  	instance_charge_type = "Postpaid"
   732  	db_instance_net_type = "Intranet"
   733  }
   734  `
   735  const testAccDBInstance_securityIpsConfig = `
   736  resource "alicloud_db_instance" "foo" {
   737  	engine = "MySQL"
   738  	engine_version = "5.6"
   739  	db_instance_class = "rds.mysql.t1.small"
   740  	db_instance_storage = "10"
   741  	instance_charge_type = "Postpaid"
   742  	db_instance_net_type = "Intranet"
   743  
   744  	security_ips = ["10.168.1.12", "100.69.7.112"]
   745  }
   746  `
   747  
   748  const testAccDBInstance_class = `
   749  resource "alicloud_db_instance" "foo" {
   750  	engine = "MySQL"
   751  	engine_version = "5.6"
   752  	db_instance_class = "rds.mysql.t1.small"
   753  	db_instance_storage = "10"
   754  	db_instance_net_type = "Intranet"
   755  }
   756  `
   757  const testAccDBInstance_classUpgrade = `
   758  resource "alicloud_db_instance" "foo" {
   759  	engine = "MySQL"
   760  	engine_version = "5.6"
   761  	db_instance_class = "rds.mysql.s1.small"
   762  	db_instance_storage = "10"
   763  	db_instance_net_type = "Intranet"
   764  }
   765  `