diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8c8c09258..f8a315b5387 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ IMPROVEMENTS: +- *New Resource*: _alicloud_db_database_ ([#68](https://github.com/terraform-providers/terraform-provider-alicloud/pull/68)) +- *New Resource*: _alicloud_db_backup_policy_ ([#68](https://github.com/terraform-providers/terraform-provider-alicloud/pull/68)) - *New Resource*: _alicloud_db_connection_ ([#67](https://github.com/terraform-providers/terraform-provider-alicloud/pull/67)) - *New Resource*: _alicloud_db_account_ ([#66](https://github.com/terraform-providers/terraform-provider-alicloud/pull/66)) - *New Resource*: _alicloud_db_account_privilege_ ([#66](https://github.com/terraform-providers/terraform-provider-alicloud/pull/66)) diff --git a/alicloud/import_alicloud_db_backup_policy_test.go b/alicloud/import_alicloud_db_backup_policy_test.go new file mode 100644 index 00000000000..a02ed5bb9b5 --- /dev/null +++ b/alicloud/import_alicloud_db_backup_policy_test.go @@ -0,0 +1,29 @@ +package alicloud + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAlicloudDBBackupPolicy_import(t *testing.T) { + resourceName := "alicloud_db_backup_policy.policy" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDBBackupPolicy_basic, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"log_retention_period"}, + }, + }, + }) +} diff --git a/alicloud/import_alicloud_db_database_test.go b/alicloud/import_alicloud_db_database_test.go new file mode 100644 index 00000000000..a6f2d84376b --- /dev/null +++ b/alicloud/import_alicloud_db_database_test.go @@ -0,0 +1,28 @@ +package alicloud + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAlicloudDBDatabase_import(t *testing.T) { + resourceName := "alicloud_db_database.db" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDBDatabase_basic, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/alicloud/provider.go b/alicloud/provider.go index e5094de40f3..8abcbad1f55 100644 --- a/alicloud/provider.go +++ b/alicloud/provider.go @@ -66,8 +66,10 @@ func Provider() terraform.ResourceProvider { "alicloud_disk_attachment": resourceAliyunDiskAttachment(), "alicloud_security_group": resourceAliyunSecurityGroup(), "alicloud_security_group_rule": resourceAliyunSecurityGroupRule(), + "alicloud_db_database": resourceAlicloudDBDatabase(), "alicloud_db_account": resourceAlicloudDBAccount(), "alicloud_db_account_privilege": resourceAlicloudDBAccountPrivilege(), + "alicloud_db_backup_policy": resourceAlicloudDBBackupPolicy(), "alicloud_db_connection": resourceAlicloudDBConnection(), "alicloud_db_instance": resourceAlicloudDBInstance(), "alicloud_ess_scaling_group": resourceAlicloudEssScalingGroup(), diff --git a/alicloud/resource_alicloud_db_backup_policy.go b/alicloud/resource_alicloud_db_backup_policy.go new file mode 100644 index 00000000000..4b0c53c0f95 --- /dev/null +++ b/alicloud/resource_alicloud_db_backup_policy.go @@ -0,0 +1,186 @@ +package alicloud + +import ( + "fmt" + "github.com/denverdino/aliyungo/rds" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "strconv" + "strings" + "time" +) + +func resourceAlicloudDBBackupPolicy() *schema.Resource { + return &schema.Resource{ + Create: resourceAlicloudDBBackupPolicyCreate, + Read: resourceAlicloudDBBackupPolicyRead, + Update: resourceAlicloudDBBackupPolicyUpdate, + Delete: resourceAlicloudDBBackupPolicyDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + + "backup_period": &schema.Schema{ + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + // terraform does not support ValidateFunc of TypeList attr + // ValidateFunc: validateAllowedStringValue([]string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}), + Optional: true, + Computed: true, + }, + + "backup_time": &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validateAllowedStringValue(rds.BACKUP_TIME), + Optional: true, + Default: "02:00Z-03:00Z", + }, + + "retention_period": &schema.Schema{ + Type: schema.TypeInt, + ValidateFunc: validateIntegerInRange(7, 730), + Optional: true, + Default: 7, + }, + + "log_backup": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + + "log_retention_period": &schema.Schema{ + Type: schema.TypeInt, + ValidateFunc: validateIntegerInRange(7, 730), + Optional: true, + Default: 7, + DiffSuppressFunc: logRetentionPeriodDiffSuppressFunc, + }, + }, + } +} + +func resourceAlicloudDBBackupPolicyCreate(d *schema.ResourceData, meta interface{}) error { + + d.SetId(d.Get("instance_id").(string)) + + return resourceAlicloudDBBackupPolicyUpdate(d, meta) +} + +func resourceAlicloudDBBackupPolicyRead(d *schema.ResourceData, meta interface{}) error { + + resp, err := meta.(*AliyunClient).rdsconn.DescribeBackupPolicy(&rds.DescribeBackupPolicyArgs{ + DBInstanceId: d.Id(), + }) + if err != nil { + if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceNameNotFound) { + d.SetId("") + return nil + } + return fmt.Errorf("Error Describe DB backup policy: %#v", err) + } + + d.Set("instance_id", d.Id()) + d.Set("backup_time", resp.PreferredBackupTime) + d.Set("backup_period", strings.Split(resp.PreferredBackupPeriod, ",")) + d.Set("retention_period", resp.BackupRetentionPeriod) + d.Set("log_backup", resp.BackupLog == "Enable") + d.Set("log_retention_period", resp.LogBackupRetentionPeriod) + + return nil +} + +func resourceAlicloudDBBackupPolicyUpdate(d *schema.ResourceData, meta interface{}) error { + + d.Partial(true) + + update := false + args := rds.ModifyBackupPolicyArgs{ + DBInstanceId: d.Id(), + } + periodList := expandStringList(d.Get("backup_period").(*schema.Set).List()) + args.PreferredBackupPeriod = fmt.Sprintf("%s", strings.Join(periodList[:], COMMA_SEPARATED)) + args.PreferredBackupTime = d.Get("backup_time").(string) + args.BackupRetentionPeriod = d.Get("retention_period").(int) + args.BackupLog = "Enable" + args.LogBackupRetentionPeriod = strconv.Itoa(d.Get("log_retention_period").(int)) + + if d.HasChange("backup_period") { + update = true + d.SetPartial("backup_period") + } + + if d.HasChange("backup_time") { + update = true + d.SetPartial("backup_time") + } + + if d.HasChange("retention_period") { + update = true + d.SetPartial("retention_period") + } + + if d.HasChange("log_backup") { + if !d.Get("log_backup").(bool) { + args.BackupLog = "Disabled" + } + update = true + d.SetPartial("retention_period") + } + + if d.HasChange("log_retention_period") { + if d.Get("log_retention_period").(int) > args.BackupRetentionPeriod { + args.LogBackupRetentionPeriod = strconv.Itoa(args.BackupRetentionPeriod) + } + update = true + d.SetPartial("log_retention_period") + } + + if update { + err := resource.Retry(3*time.Minute, func() *resource.RetryError { + ag := args + if _, err := meta.(*AliyunClient).rdsconn.ModifyBackupPolicy(&ag); err != nil { + if IsExceptedError(err, OperationDeniedDBInstanceStatus) { + return resource.RetryableError(fmt.Errorf("ModifyBackupPolicy got an error: %#v.", err)) + } + return resource.NonRetryableError(fmt.Errorf("ModifyBackupPolicy got an error: %#v.", err)) + } + + return nil + }) + + if err != nil { + return err + } + } + + d.Partial(false) + return resourceAlicloudDBBackupPolicyRead(d, meta) +} + +func resourceAlicloudDBBackupPolicyDelete(d *schema.ResourceData, meta interface{}) error { + + args := &rds.ModifyBackupPolicyArgs{ + DBInstanceId: d.Id(), + } + args.PreferredBackupTime = "02:00Z-03:00Z" + args.PreferredBackupPeriod = "Tuesday,Thursday,Saturday" + args.BackupRetentionPeriod = 7 + args.BackupLog = "Enable" + args.LogBackupRetentionPeriod = "7" + + return resource.Retry(5*time.Minute, func() *resource.RetryError { + if _, err := meta.(*AliyunClient).rdsconn.ModifyBackupPolicy(args); err != nil { + return resource.RetryableError(fmt.Errorf("ModifyBackupPolicy got an error: %#v", err)) + } + + return nil + }) +} diff --git a/alicloud/resource_alicloud_db_backup_policy_test.go b/alicloud/resource_alicloud_db_backup_policy_test.go new file mode 100644 index 00000000000..40bd24f9ad5 --- /dev/null +++ b/alicloud/resource_alicloud_db_backup_policy_test.go @@ -0,0 +1,119 @@ +package alicloud + +import ( + "fmt" + "github.com/denverdino/aliyungo/rds" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "testing" +) + +func TestAccAlicloudDBBackupPolicy_basic(t *testing.T) { + var policy rds.DescribeBackupPolicyResponse + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + + // module name + IDRefreshName: "alicloud_db_backup_policy.policy", + + Providers: testAccProviders, + CheckDestroy: testAccCheckDBBackupPolicyDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDBBackupPolicy_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckDBBackupPolicyExists( + "alicloud_db_backup_policy.policy", &policy), + resource.TestCheckResourceAttr("alicloud_db_backup_policy.policy", "backup_time", "10:00Z-11:00Z"), + ), + }, + }, + }) + +} + +func testAccCheckDBBackupPolicyExists(n string, d *rds.DescribeBackupPolicyResponse) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No DB account ID is set") + } + + client := testAccProvider.Meta().(*AliyunClient) + + resp, err := client.rdsconn.DescribeBackupPolicy(&rds.DescribeBackupPolicyArgs{ + DBInstanceId: rs.Primary.ID, + }) + if err != nil { + + return fmt.Errorf("Error Describe DB backup policy: %#v", err) + } + + if resp == nil { + return fmt.Errorf("Backup policy is not found in the instance %s.", rs.Primary.ID) + } + + *d = *resp + return nil + } +} + +func testAccCheckDBBackupPolicyDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*AliyunClient) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "alicloud_db_account" { + continue + } + + _, err := client.rdsconn.DescribeBackupPolicy(&rds.DescribeBackupPolicyArgs{ + DBInstanceId: rs.Primary.ID, + }) + if err != nil { + if NotFoundError(err) || IsExceptedError(err, InvalidDBInstanceNameNotFound) { + continue + } + return fmt.Errorf("Error Describe DB backup policy: %#v", err) + } + } + + return nil +} + +const testAccDBBackupPolicy_basic = ` +data "alicloud_zones" "default" { + "available_resource_creation"= "VSwitch" +} + +resource "alicloud_vpc" "foo" { + name = "tf_test_foo" + cidr_block = "172.16.0.0/12" +} + +resource "alicloud_vswitch" "foo" { + vpc_id = "${alicloud_vpc.foo.id}" + cidr_block = "172.16.0.0/21" + availability_zone = "${data.alicloud_zones.default.zones.0.id}" +} + +resource "alicloud_db_instance" "instance" { + engine = "MySQL" + engine_version = "5.6" + instance_type = "rds.mysql.t1.small" + instance_storage = "10" + vswitch_id = "${alicloud_vswitch.foo.id}" +} + +resource "alicloud_db_backup_policy" "policy" { + instance_id = "${alicloud_db_instance.instance.id}" + backup_period = ["Tuesday", "Wednesday"] + backup_time = "10:00Z-11:00Z" +} +` diff --git a/alicloud/resource_alicloud_db_database.go b/alicloud/resource_alicloud_db_database.go new file mode 100644 index 00000000000..87ba0a84c53 --- /dev/null +++ b/alicloud/resource_alicloud_db_database.go @@ -0,0 +1,148 @@ +package alicloud + +import ( + "fmt" + "github.com/denverdino/aliyungo/rds" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" + "strings" + "time" +) + +func resourceAlicloudDBDatabase() *schema.Resource { + return &schema.Resource{ + Create: resourceAlicloudDBDatabaseCreate, + Read: resourceAlicloudDBDatabaseRead, + Update: resourceAlicloudDBDatabaseUpdate, + Delete: resourceAlicloudDBDatabaseDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + + "name": &schema.Schema{ + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + + "character_set": &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validateAllowedStringValue(rds.CHARACTER_SET_NAME), + Optional: true, + Default: "utf8", + ForceNew: true, + }, + + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, + }, + } +} + +func resourceAlicloudDBDatabaseCreate(d *schema.ResourceData, meta interface{}) error { + + args := rds.CreateDatabaseArgs{ + DBInstanceId: d.Get("instance_id").(string), + DBName: d.Get("name").(string), + CharacterSetName: d.Get("character_set").(string), + } + if v, ok := d.GetOk("description"); ok && v.(string) != "" { + args.DBDescription = v.(string) + } + + err := resource.Retry(3*time.Minute, func() *resource.RetryError { + ag := args + if _, err := meta.(*AliyunClient).rdsconn.CreateDatabase(&ag); err != nil { + if IsExceptedError(err, OperationDeniedDBInstanceStatus) { + return resource.RetryableError(fmt.Errorf("Create database got an error: %#v.", err)) + } + return resource.NonRetryableError(fmt.Errorf("Create database got an error: %#v.", err)) + } + + return nil + }) + + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("%s%s%s", args.DBInstanceId, COLON_SEPARATED, args.DBName)) + + return resourceAlicloudDBDatabaseUpdate(d, meta) +} + +func resourceAlicloudDBDatabaseRead(d *schema.ResourceData, meta interface{}) error { + parts := strings.Split(d.Id(), COLON_SEPARATED) + db, err := meta.(*AliyunClient).DescribeDatabaseByName(parts[0], parts[1]) + if err != nil { + if NotFoundError(err) || IsExceptedError(err, InvalidDBNameNotFound) { + d.SetId("") + return nil + } + return fmt.Errorf("Error Describe DB InstanceAttribute: %#v", err) + } + + d.Set("instance_id", db.DBInstanceId) + d.Set("name", db.DBName) + d.Set("character_set", db.CharacterSetName) + d.Set("description", db.DBDescription) + + return nil +} + +func resourceAlicloudDBDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { + + d.Partial(true) + + if d.HasChange("description") && !d.IsNewResource() { + parts := strings.Split(d.Id(), COLON_SEPARATED) + if err := meta.(*AliyunClient).rdsconn.ModifyDatabaseDescription(&rds.ModifyDatabaseDescriptionArgs{ + DBInstanceId: parts[0], + DBName: parts[1], + DBDescription: d.Get("description").(string), + }); err != nil { + return fmt.Errorf("ModifyDatabaseDescription got an error: %#v", err) + } + d.SetPartial("description") + } + + d.Partial(false) + return resourceAlicloudDBDatabaseRead(d, meta) +} + +func resourceAlicloudDBDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AliyunClient).rdsconn + parts := strings.Split(d.Id(), COLON_SEPARATED) + return resource.Retry(5*time.Minute, func() *resource.RetryError { + err := conn.DeleteDatabase(parts[0], parts[1]) + + if err != nil { + if NotFoundError(err) || IsExceptedError(err, InvalidDBNameNotFound) { + return nil + } + return resource.RetryableError(fmt.Errorf("Delete database %s timeout and got an error: %#v.", parts[1], err)) + } + + db, err := meta.(*AliyunClient).DescribeDatabaseByName(parts[0], parts[1]) + if err != nil { + if NotFoundError(err) || IsExceptedError(err, InvalidDBNameNotFound) { + return nil + } + return resource.NonRetryableError(fmt.Errorf("Error Describe DB InstanceAttribute: %#v", err)) + } + if db == nil { + return nil + } + + return resource.RetryableError(fmt.Errorf("Delete database %s timeout and got an error: %#v.", parts[1], err)) + }) +} diff --git a/alicloud/resource_alicloud_db_database_test.go b/alicloud/resource_alicloud_db_database_test.go new file mode 100644 index 00000000000..956c15ee40b --- /dev/null +++ b/alicloud/resource_alicloud_db_database_test.go @@ -0,0 +1,125 @@ +package alicloud + +import ( + "fmt" + "github.com/denverdino/aliyungo/rds" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "strings" + "testing" +) + +func TestAccAlicloudDBDatabase_basic(t *testing.T) { + var database rds.Database + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + + // module name + IDRefreshName: "alicloud_db_database.db", + + Providers: testAccProviders, + CheckDestroy: testAccCheckDBDatabaseDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDBDatabase_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckDBDatabaseExists( + "alicloud_db_database.db", &database), + resource.TestCheckResourceAttr("alicloud_db_database.db", "character_set", "utf8"), + ), + }, + }, + }) + +} + +func testAccCheckDBDatabaseExists(n string, d *rds.Database) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No DB ID is set") + } + + client := testAccProvider.Meta().(*AliyunClient) + parts := strings.Split(rs.Primary.ID, COLON_SEPARATED) + db, err := client.DescribeDatabaseByName(parts[0], parts[1]) + + if err != nil { + return err + } + + if db == nil { + return fmt.Errorf("DB is not found in the instance %s.", parts[0]) + } + + *d = *db + return nil + } +} + +func testAccCheckDBDatabaseDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*AliyunClient) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "alicloud_db_database" { + continue + } + + parts := strings.Split(rs.Primary.ID, COLON_SEPARATED) + + db, err := client.DescribeDatabaseByName(parts[0], parts[1]) + + // Verify the error is what we want + if err != nil { + // Verify the error is what we want + if NotFoundError(err) || IsExceptedError(err, InvalidDBNameNotFound) { + continue + } + return err + } + + if db != nil { + return fmt.Errorf("Error database %s is still existing.", parts[1]) + } + } + + return nil +} + +const testAccDBDatabase_basic = ` +data "alicloud_zones" "default" { + "available_resource_creation"= "VSwitch" +} + +resource "alicloud_vpc" "foo" { + name = "tf_test_foo" + cidr_block = "172.16.0.0/12" +} + +resource "alicloud_vswitch" "foo" { + vpc_id = "${alicloud_vpc.foo.id}" + cidr_block = "172.16.0.0/21" + availability_zone = "${data.alicloud_zones.default.zones.0.id}" +} + +resource "alicloud_db_instance" "instance" { + engine = "MySQL" + engine_version = "5.6" + instance_type = "rds.mysql.t1.small" + instance_storage = "10" + vswitch_id = "${alicloud_vswitch.foo.id}" +} + +resource "alicloud_db_database" "db" { + instance_id = "${alicloud_db_instance.instance.id}" + name = "tf_db" + description = "from terraform" +} +` diff --git a/website/docs/r/cdn_domain.html.markdown b/website/docs/r/cdn_domain.html.markdown index f39c770d7ba..5da5faabc51 100644 --- a/website/docs/r/cdn_domain.html.markdown +++ b/website/docs/r/cdn_domain.html.markdown @@ -128,6 +128,7 @@ The config supports the following: ## Attributes Reference The following attributes are exported: + * `domain_name` - The accelerated domain name. * `sources` - The accelerated domain sources. * `cdn_type` - The cdn type of the accelerated domain. diff --git a/website/docs/r/db_backup_policy.html.markdown b/website/docs/r/db_backup_policy.html.markdown new file mode 100644 index 00000000000..a9bba6ec783 --- /dev/null +++ b/website/docs/r/db_backup_policy.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "alicloud" +page_title: "Alicloud: alicloud_db_backup_policy" +sidebar_current: "docs-alicloud-resource-db-backup-policy" +description: |- + Provides an RDS backup policy resource. +--- + +# alicloud\_db\_backup\_policy + +Provides an RDS instance backup policy resource and used to configure instance backup policy. + +~> **NOTE:** Each DB instance has a backup policy and it will be set default values when destroying the resource. + +## Example Usage + +``` +resource "alicloud_db_backup_policy" "default" { + instance_id = "rm-2eps..." + backup_period = ["Monday", "Wednesday"] + backup_time = "02:00Z-03:00Z" + retention_period = 7 + log_backup = true +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required) The Id of instance that can run database. +* `backup_period` - (Optional) DB Instance backup period. Valid values: [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]. Default to ["Tuesday", "Thursday", "Saturday"]. +* `backup_time` - (Optional) DB instance backup time, in the format of HH:mmZ- HH:mmZ. Time setting interval is one hour. Default to "02:00Z-03:00Z". China time is 8 hours behind it. +* `retention_period` - (Optional) Instance backup retention days. Valid values: [7-730]. Default to 7. +* `log_backup` - (Optional) Whether to backup instance log. Default to true. +* `log_retention_period` - (Optional) Instance log backup retention days. Valid values: [7-730]. Default to 7. It can be larger than 'retention_period'. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The current backup policy resource ID. It is same as 'instance_id'. +* `instance_id` - The Id of DB instance. +* `backup_period` - DB Instance backup period. +* `backup_time` - DB instance backup time. +* `retention_period` - Instance backup retention days. +* `log_backup` - Whether to backup instance log. +* `log_retention_period` - Instance log backup retention days. + + diff --git a/website/docs/r/db_database.html.markdown b/website/docs/r/db_database.html.markdown new file mode 100644 index 00000000000..4124ae2683d --- /dev/null +++ b/website/docs/r/db_database.html.markdown @@ -0,0 +1,46 @@ +--- +layout: "alicloud" +page_title: "Alicloud: alicloud_db_database" +sidebar_current: "docs-alicloud-resource-db-database" +description: |- + Provides an RDS database resource. +--- + +# alicloud\_db\_database + +Provides an RDS database resource. A DB database deployed in a DB instance. A DB instance can own multiple databases. + +## Example Usage + +``` +resource "alicloud_db_database" "default" { + instance_id = "rm-2eps..." + name = "tf_database" + character_set = "utf8" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `instance_id` - (Required) The Id of instance that can run database. +* `name` - (Required) Name of the database requiring a uniqueness check. It may consist of lower case letters, numbers, and underlines, and must start with a letter + and have no more than 64 characters. +* `character_set` - (Required) Character set. The value range is limited to the following: + - MySQL: [ utf8, gbk, latin1, utf8mb4 ] (included in versions 5.5 and 5.6). + - SQLServer: [ Chinese_PRC_CI_AS, Chinese_PRC_CS_AS, SQL_Latin1_General_CP1_CI_AS, SQL_Latin1_General_CP1_CS_AS, Chinese_PRC_BIN ] + +* `description` - (Optional) Database description. It cannot begin with https://. It must start with a Chinese character or English letter. It can include Chinese and English characters, underlines (_), hyphens (-), and numbers. The length may be 2-256 characters. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The current database resource ID. Composed of instance ID and database name with format ":". +* `instance_id` - The Id of DB instance. +* `name` - The name of DB database. +* `character_set` - Character set that database used. +* `description` - The database description. + diff --git a/website/docs/r/dns.html.markdown b/website/docs/r/dns.html.markdown index 2a726ac8dcf..247e5bb9d51 100644 --- a/website/docs/r/dns.html.markdown +++ b/website/docs/r/dns.html.markdown @@ -24,6 +24,7 @@ resource "alicloud_dns" "dns" { ## Argument Reference The following arguments are supported: + * `name` - (Required) Name of the domain. This name without suffix can have a string of 1 to 63 characters, must contain only alphanumeric characters or "-", and must not begin or end with "-", and "-" must not in the 3th and 4th character positions at the same time. Suffix `.sh` and `.tel` are not supported. * `group_id` - (Optional) Id of the group in which the domain will add. If not supplied, then use default group. @@ -31,7 +32,7 @@ The following arguments are supported: ## Attributes Reference The following attributes are exported: -###### resource alicloud_dns + * `id` - The domain id. * `name` - The domain name. * `group_id` - The group id of domain. diff --git a/website/docs/r/dns_group.html.markdown b/website/docs/r/dns_group.html.markdown index 633bddea569..e3714641a25 100644 --- a/website/docs/r/dns_group.html.markdown +++ b/website/docs/r/dns_group.html.markdown @@ -27,5 +27,6 @@ The following arguments are supported: ## Attributes Reference The following attributes are exported: + * `id` - The group id. * `name` - The group name. \ No newline at end of file diff --git a/website/docs/r/dns_record.html.markdown b/website/docs/r/dns_record.html.markdown index 1b39dc2058b..d72cbf47720 100644 --- a/website/docs/r/dns_record.html.markdown +++ b/website/docs/r/dns_record.html.markdown @@ -25,6 +25,7 @@ resource "alicloud_dns_record" "record" { ## Argument Reference The following arguments are supported: + * `name` - (Required) Name of the domain. This name without suffix can have a string of 1 to 63 characters, must contain only alphanumeric characters or "-", and must not begin or end with "-", and "-" must not in the 3th and 4th character positions at the same time. Suffix `.sh` and `.tel` are not supported. * `host_record` - (Required) Host record for the domain record. This host_record can have at most 253 characters, and each part split with "." can have at most 63 characters, and must contain only alphanumeric characters or hyphens, such as "-",".","*","@", and must not begin or end with "-". * `type` - (Required) The type of domain record. Valid values are `A`,`NS`,`MX`,`TXT`,`CNAME`,`SRV`,`AAAA`,`REDIRECT_URL` and `FORWORD_URL`. @@ -36,6 +37,7 @@ The following arguments are supported: ## Attributes Reference The following attributes are exported: + * `id` - The record id. * `name` - (Required) The record domain name. * `type` - (Required) The record type. diff --git a/website/docs/r/instance.html.markdown b/website/docs/r/instance.html.markdown index caaef1c8de6..462624a7bb0 100644 --- a/website/docs/r/instance.html.markdown +++ b/website/docs/r/instance.html.markdown @@ -67,7 +67,7 @@ The following arguments are supported: * `io_optimized` - (Deprecated) It has been deprecated on instance resource. All the launched alicloud instances will be I/O optimized. * `is_outdated` - (Optional) Whether to use outdated instance type. Default to false. * `security_groups` - (Required) A list of security group ids to associate with. -* `availability_zone` - (Optional) The Zone to start the instance in. +* `availability_zone` - (Optional) The Zone to start the instance in. It is ignored and will be computed when set `vswitch_id`. * `instance_name` - (Optional) The name of the ECS. This instance_name can have a string of 2 to 128 characters, must contain only alphanumeric characters or hyphens, such as "-",".","_", and must not begin or end with a hyphen, and must not begin with http:// or https://. If not specified, Terraform will autogenerate a default name is `ECS-Instance`. * `allocate_public_ip` - (Optional) Associate a public ip address with an instance in a VPC or Classic. Boolean value, Default is false. @@ -82,14 +82,27 @@ On other OSs such as Linux, the host name can contain a maximum of 30 characters * `password` - (Optional) Password to an instance is a string of 8 to 30 characters. It must contain uppercase/lowercase letters and numerals, but cannot contain special symbols. In order to take effect new password, the instance will be restarted after modifying the password. * `vswitch_id` - (Optional) The virtual switch ID to launch in VPC. If you want to create instances in VPC network, this parameter must be set. * `instance_charge_type` - (Optional) Valid values are `PrePaid`, `PostPaid`, The default is `PostPaid`. -* `period` - (Optional) The time that you have bought the resource, in month. Only valid when instance_charge_type is set as `PrePaid`. Value range [1, 12]. +* `period_unit` - (Optional) The duration unit that you will buy the resource. It is valid when `instance_charge_type` is 'PrePaid'. Valid value: ["Week", "Month"]. Default to "Month". +* `period` - (Optional) The duration that you will buy the resource, in month. It is valid when instance_charge_type is set as `PrePaid`. Default to 1. Valid values: + - [1-9, 12, 24, 36, 48, 60] when `period_unit` in "Month" + - [1-3] when `period_unit` in "Week" + * `tags` - (Optional) A mapping of tags to assign to the resource. * `user_data` - (Optional) User-defined data to customize the startup behaviors of an ECS instance and to pass data into an ECS instance. * `key_name` - (Optional, Force new resource) The name of key pair that can login ECS instance successfully without password. If it is specified, the password would be invalid. * `role_name` - (Optional, Force new resource) Instance RAM role name. The name is provided and maintained by RAM. You can use `alicloud_ram_role` to create a new one. +* `include_data_disks` - (Optional) Whether to change instance disks charge type when changing instance charge type. +* `dry_run` - (Optional) Whether to pre-detection. When it is true, only pre-detection and not actually modify the payment type operation. It is valid when `instance_charge_type` is 'PrePaid'. Default to false. +* `private_ip` - (Optional) Instance private IP address can be specified when you creating new instance. It is valid when `vswitch_id` is specified. ~> **NOTE:** System disk category `cloud` has been outdated and it only can be used none I/O Optimized ECS instances. Recommend `cloud_efficiency` and `cloud_ssd` disk. +~> **NOTE:** From version 1.5.0, instance's charge type can be changed to "PrePaid" by specifying `period` and `period_unit`, but it is irreversible. + +~> **NOTE:** From version 1.5.0, instance's private IP address can be specified when creating VPC network instance. + +~> **NOTE:** From version 1.5.0, instance's vswitch and private IP can be changed in the same availability zone. + ## Attributes Reference The following attributes are exported: @@ -108,4 +121,7 @@ The following attributes are exported: * `tags` - The instance tags, use jsonencode(item) to display the value. * `key_name` - The name of key pair that has been bound in ECS instance. * `role_name` - The name of RAM role that has been bound in ECS instance. -* `user_data` - The hash value of the user data. \ No newline at end of file +* `user_data` - The hash value of the user data. +* `period` - The ECS instance using duration. +* `period_unit` - The ECS instance using duration unit. +* `dry_run` - Whether to pre-detection. diff --git a/website/docs/r/ram_alias.html.markdown b/website/docs/r/ram_alias.html.markdown new file mode 100644 index 00000000000..991959f258b --- /dev/null +++ b/website/docs/r/ram_alias.html.markdown @@ -0,0 +1,11 @@ +--- +layout: "alicloud" +page_title: "Alicloud: alicloud_ram_alias" +sidebar_current: "docs-alicloud-resource-ram-alias" +description: |- + Provides a RAM cloud account alias. +--- + +# alicloud\_ram\_alias + +~> **NOTE:** This resource has been deprecated from [v1.3.2](https://github.com/alibaba/terraform-provider/releases/tag/V1.3.2). New resource `alicloud_ram_account_alias` will replace.