diff --git a/baiducloud/resource_baiducloud_appblb.go b/baiducloud/resource_baiducloud_appblb.go index 39e81f4..e900434 100644 --- a/baiducloud/resource_baiducloud_appblb.go +++ b/baiducloud/resource_baiducloud_appblb.go @@ -70,28 +70,20 @@ func resourceBaiduCloudAppBLB() *schema.Resource { Description: "eip of the LoadBalance", Optional: true, }, - "billing": { - Type: schema.TypeMap, - Description: "Billing information of the APPBLB.", - Required: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "payment_timing": { - Type: schema.TypeString, - Description: "Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid.", - Required: true, - Default: PaymentTimingPostpaid, - ValidateFunc: validatePaymentTiming(), - }, - }, - }, + "payment_timing": { + Type: schema.TypeString, + Description: "Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid." + + "Do not support modify.", + Optional: true, + ForceNew: true, + Default: PaymentTimingPostpaid, + ValidateFunc: validatePaymentTiming(), }, "reservation": { Type: schema.TypeMap, Description: "Reservation of the APPBLB.", Optional: true, - DiffSuppressFunc: postPaidBillingDiffSuppressFunc, + DiffSuppressFunc: postPaidDiffSuppressFunc, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "reservation_length": { @@ -102,7 +94,7 @@ func resourceBaiduCloudAppBLB() *schema.Resource { Required: true, Default: 1, ValidateFunc: validateReservationLength(), - DiffSuppressFunc: postPaidBillingDiffSuppressFunc, + DiffSuppressFunc: postPaidDiffSuppressFunc, }, "reservation_time_unit": { Type: schema.TypeString, @@ -112,7 +104,7 @@ func resourceBaiduCloudAppBLB() *schema.Resource { Required: true, Default: "month", ValidateFunc: validateReservationUnit(), - DiffSuppressFunc: postPaidBillingDiffSuppressFunc, + DiffSuppressFunc: postPaidDiffSuppressFunc, }, }, }, @@ -147,10 +139,10 @@ func resourceBaiduCloudAppBLB() *schema.Resource { }, }, "performance_level": { - Type: schema.TypeString, - Description: "performance level, available values are small1, small2, medium1, medium2, large1, large2, large3", - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Description: "performance level, available values are small1, small2, medium1, medium2, large1, large2, large3", + Optional: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"small1", "small2", "medium1", "medium2", "large1", "large2", "large3",}, false), }, "description": { @@ -244,9 +236,8 @@ func resourceBaiduCloudAppBLB() *schema.Resource { "allow_delete": { Type: schema.TypeBool, Default: true, - Description: "Whether to allow deletion, default value is true, do not support modify", + Description: "Whether to allow deletion, default value is true. ", Optional: true, - ForceNew: true, }, "allocate_ipv6": { Type: schema.TypeBool, @@ -351,6 +342,8 @@ func resourceBaiduCloudAppBLBRead(d *schema.ResourceData, meta interface{}) erro d.Set("release_time", blbDetail.ReleaseTime) d.Set("performance_level", blbDetail.PerformanceLevel) d.Set("listener", appblbService.FlattenListenerModelToMap(blbDetail.Listener)) + d.Set("payment_timing", blbDetail.PaymentTiming) + d.Set("allow_delete", blbModel.AllowDelete) if d.HasChange("tags") { if v, ok := d.GetOk("tags"); ok { if !slicesContainSameElements(blbDetail.Tags, tranceTagMapToModel(v.(map[string]interface{}))) { @@ -407,6 +400,12 @@ func resourceBaiduCloudAppBLBUpdate(d *schema.ResourceData, meta interface{}) er updateArgs.Description = d.Get("description").(string) } + if d.HasChange("allow_delete") { + update = true + allowDelete := d.Get("allow_delete").(bool) + updateArgs.AllowDelete = &allowDelete + } + stateConf := buildStateConf( APPBLBProcessingStatus, APPBLBAvailableStatus, @@ -509,15 +508,12 @@ func buildBaiduCloudCreateAppBlbArgs(d *schema.ResourceData) *appblb.CreateLoadB result.PerformanceLevel = v.(string) } - if v, ok := d.GetOk("billing"); ok { - billing := v.(map[string]interface{}) + if v, ok := d.GetOk("payment_timing"); ok { billingRequest := &appblb.Billing{ PaymentTiming: "", } - if p, ok := billing["payment_timing"]; ok { - paymentTiming := p.(string) - billingRequest.PaymentTiming = paymentTiming - } + paymentTiming := v.(string) + billingRequest.PaymentTiming = paymentTiming if billingRequest.PaymentTiming == PaymentTimingPrepaid { if r, ok := d.GetOk("reservation"); ok { reservation := r.(map[string]interface{}) diff --git a/baiducloud/resource_baiducloud_blb.go b/baiducloud/resource_baiducloud_blb.go index 588d334..b602be7 100644 --- a/baiducloud/resource_baiducloud_blb.go +++ b/baiducloud/resource_baiducloud_blb.go @@ -98,28 +98,19 @@ func resourceBaiduCloudBLB() *schema.Resource { Description: "eip of the LoadBalance", Optional: true, }, - "billing": { - Type: schema.TypeMap, - Description: "Billing information of the BLB.", - Required: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "payment_timing": { - Type: schema.TypeString, - Description: "Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid.", - Required: true, - Default: PaymentTimingPostpaid, - ValidateFunc: validatePaymentTiming(), - }, - }, - }, + "payment_timing": { + Type: schema.TypeString, + Description: "Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid.", + Optional: true, + ForceNew: true, + Default: PaymentTimingPostpaid, + ValidateFunc: validatePaymentTiming(), }, "reservation": { Type: schema.TypeMap, Description: "Reservation of the BLB.", Optional: true, - DiffSuppressFunc: postPaidBillingDiffSuppressFunc, + DiffSuppressFunc: postPaidDiffSuppressFunc, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "reservation_length": { @@ -130,7 +121,7 @@ func resourceBaiduCloudBLB() *schema.Resource { Required: true, Default: 1, ValidateFunc: validateReservationLength(), - DiffSuppressFunc: postPaidBillingDiffSuppressFunc, + DiffSuppressFunc: postPaidDiffSuppressFunc, }, "reservation_time_unit": { Type: schema.TypeString, @@ -140,7 +131,7 @@ func resourceBaiduCloudBLB() *schema.Resource { Required: true, Default: "month", ValidateFunc: validateReservationUnit(), - DiffSuppressFunc: postPaidBillingDiffSuppressFunc, + DiffSuppressFunc: postPaidDiffSuppressFunc, }, }, }, @@ -229,9 +220,8 @@ func resourceBaiduCloudBLB() *schema.Resource { "allow_delete": { Type: schema.TypeBool, Default: true, - Description: "Whether to allow deletion, default value is true, do not support modify", + Description: "Whether to allow deletion, default value is true. ", Optional: true, - ForceNew: true, }, "allocate_ipv6": { Type: schema.TypeBool, @@ -336,6 +326,8 @@ func resourceBaiduCloudBLBRead(d *schema.ResourceData, meta interface{}) error { d.Set("create_time", blbDetail.CreateTime) d.Set("performance_level", blbDetail.PerformanceLevel) d.Set("listener", blbService.FlattenListenerModelToMap(blbDetail.Listener)) + d.Set("payment_timing", blbDetail.PaymentTiming) + d.Set("allow_delete", blbModel.AllowDelete) if d.HasChange("tags") { if v, ok := d.GetOk("tags"); ok { if !slicesContainSameElements(blbDetail.Tags, tranceTagMapToModel(v.(map[string]interface{}))) { @@ -415,6 +407,12 @@ func resourceBaiduCloudBLBUpdate(d *schema.ResourceData, meta interface{}) error updateArgs.Description = d.Get("description").(string) } + if d.HasChange("allow_delete") { + update = true + allowDelete := d.Get("allow_delete").(bool) + updateArgs.AllowDelete = &allowDelete + } + stateConf := buildStateConf( BLBProcessingStatus, BLBAvailableStatus, @@ -534,15 +532,12 @@ func buildBaiduCloudCreateBlbArgs(d *schema.ResourceData) *blb.CreateLoadBalance result.Type = v.(string) } - if v, ok := d.GetOk("billing"); ok { - billing := v.(map[string]interface{}) + if v, ok := d.GetOk("payment_timing"); ok { billingRequest := &blb.Billing{ PaymentTiming: "", } - if p, ok := billing["payment_timing"]; ok { - paymentTiming := p.(string) - billingRequest.PaymentTiming = paymentTiming - } + paymentTiming := v.(string) + billingRequest.PaymentTiming = paymentTiming if billingRequest.PaymentTiming == PaymentTimingPrepaid { if r, ok := d.GetOk("reservation"); ok { reservation := r.(map[string]interface{}) diff --git a/website/docs/r/appblb.html.markdown b/website/docs/r/appblb.html.markdown index 884d471..c89a876 100644 --- a/website/docs/r/appblb.html.markdown +++ b/website/docs/r/appblb.html.markdown @@ -1,8 +1,7 @@ --- layout: "baiducloud" -subcategory: "Application Load Balance (APPBLB)" page_title: "BaiduCloud: baiducloud_appblb" -sidebar_current: "docs-baiducloud-resource-appblb" +subcategory: "Application Load Balance (APPBLB)" description: |- Provide a resource to create an APPBLB. --- @@ -31,28 +30,24 @@ resource "baiducloud_appblb" "default" { The following arguments are supported: -* `billing` - (Required, ForceNew) Billing information of the APPBLB. * `subnet_id` - (Required, ForceNew) The subnet ID to which the LoadBalance instance belongs * `vpc_id` - (Required, ForceNew) The VPC short ID to which the LoadBalance instance belongs * `address` - (Optional) LoadBalance instance's service IP, instance can be accessed through this IP * `allocate_ipv6` - (Optional, ForceNew) Whether to allocated ipv6, default value is false, do not support modify -* `allow_delete` - (Optional, ForceNew) Whether to allow deletion, default value is true, do not support modify +* `allow_delete` - (Optional) Whether to allow deletion, default value is true. * `auto_renew_length` - (Optional) The automatic renewal time is 1-9 per month and 1-3 per year. * `auto_renew_time_unit` - (Optional) Monthly payment or annual payment, month is month and year is year. * `description` - (Optional) LoadBalance's description, length must be between 0 and 450 bytes, and support Chinese * `eip` - (Optional) eip of the LoadBalance * `enterprise_security_groups` - (Optional) enterprise security group ids of the APPBLB * `name` - (Optional) LoadBalance instance's name, length must be between 1 and 65 bytes, and will be automatically generated if not set +* `payment_timing` - (Optional, ForceNew) Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid.Do not support modify. * `performance_level` - (Optional, ForceNew) performance level, available values are small1, small2, medium1, medium2, large1, large2, large3 * `reservation` - (Optional) Reservation of the APPBLB. * `resource_group_id` - (Optional, ForceNew) Resource group id, support setting when creating instance, do not support modify! * `security_groups` - (Optional) security group ids of the APPBLB. * `tags` - (Optional, ForceNew) Tags, do not support modify -The `billing` object supports the following: - -* `payment_timing` - (Required) Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid. - The `reservation` object supports the following: * `reservation_length` - (Required) The reservation length that you will pay for your resource. It is valid when payment_timing is Prepaid. Valid values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36]. diff --git a/website/docs/r/blb.html.markdown b/website/docs/r/blb.html.markdown index a69c495..5eeeafb 100644 --- a/website/docs/r/blb.html.markdown +++ b/website/docs/r/blb.html.markdown @@ -1,8 +1,7 @@ --- layout: "baiducloud" -subcategory: "Baidu Load Balance (BLB)" page_title: "BaiduCloud: baiducloud_blb" -sidebar_current: "docs-baiducloud-resource-blb" +subcategory: "Baidu Load Balance (BLB)" description: |- Provide a resource to create an BLB. --- @@ -31,28 +30,24 @@ resource "baiducloud_blb" "default" { The following arguments are supported: -* `billing` - (Required, ForceNew) Billing information of the BLB. * `subnet_id` - (Required, ForceNew) The subnet ID to which the LoadBalance instance belongs * `vpc_id` - (Required, ForceNew) The VPC short ID to which the LoadBalance instance belongs * `address` - (Optional) LoadBalance instance's service IP, instance can be accessed through this IP * `allocate_ipv6` - (Optional, ForceNew) Whether to allocated ipv6, default value is false, do not support modify -* `allow_delete` - (Optional, ForceNew) Whether to allow deletion, default value is true, do not support modify +* `allow_delete` - (Optional) Whether to allow deletion, default value is true. * `auto_renew_length` - (Optional) The automatic renewal time is 1-9 per month and 1-3 per year. * `auto_renew_time_unit` - (Optional) Monthly payment or annual payment, month is "month" and year is "year". * `description` - (Optional) LoadBalance's description, length must be between 0 and 450 bytes, and support Chinese * `eip` - (Optional) eip of the LoadBalance * `enterprise_security_groups` - (Optional) enterprise security group ids of the LoadBalance * `name` - (Optional) LoadBalance instance's name, length must be between 1 and 65 bytes, and will be automatically generated if not set +* `payment_timing` - (Optional, ForceNew) Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid. * `performance_level` - (Optional, ForceNew) performance level, available values are small1, small2, medium1, medium2, large1, large2, large3 * `reservation` - (Optional) Reservation of the BLB. * `resource_group_id` - (Optional, ForceNew) Resource group id, support setting when creating instance, do not support modify! * `security_groups` - (Optional) security groups of the LoadBalance. * `tags` - (Optional, ForceNew) Tags, do not support modify -The `billing` object supports the following: - -* `payment_timing` - (Required) Payment timing of billing, which can be Prepaid or Postpaid. The default is Postpaid. - The `reservation` object supports the following: * `reservation_length` - (Required) The reservation length that you will pay for your resource. It is valid when payment_timing is Prepaid. Valid values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36].