Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/alicloud_ecs_disk: Renames alicloud_disk to alicloud_ecs_disk; Deprecates the name and use disk_name instead; Adds more attribute, like payment_type, encrypt_algorithm, auto_snapshot and so on; Upgrades the its dependence sdk #3443

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

lixue323
Copy link
Contributor

No description provided.

Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"PostPaid", "PrePaid"}, false),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个需要录入一个出入参映射的转换使用 "PayAsYouGo", "Subscription" 这两个枚举值

"auto_pay": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个属性没有在文档中说明
另外这个属性应该设置默认值吧,如果是 后付费 不应该设置这个属性吧,需要添加个压制函数,自动化代码中应该可以通配上

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个参数,产品说api支持了,但是还没对外开放

return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.Disks.Disk", response)
}
if len(v.([]interface{})) < 1 {
return object, WrapErrorf(Error(GetNotFoundMessage("ECS", id)), NotFoundWithResponse, response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块自动化的应该有点问题,应该跟上面一样抛出 GetNotFoundMessage("EcsDisk", id) 调整下吧
下面的也是

* `attached_time` - A mount of time.
* `device` - The mount point of the disk.
* `instance_id` - The instance ID of the disk mount.
* `` - The name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个检查下

@@ -11,6 +11,8 @@ description: |-

Provides a ECS disk resource.

-> **DEPRECATED:** This resource has been renamed to [alicloud_ecs_key_pair](https://www.terraform.io/docs/providers/alicloud/r/ecs_key_pair.html) from version 1.122.0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个替代资源放错了吧

* You cannot specify both the `availability_zone` and `instance_id` parameters.
* `kms_key_id` - (Optional, ForceNew) The ID of the KMS key corresponding to the data disk, The specified parameter `Encrypted` must be `true` when KmsKeyId is not empty.
* `name` - (Optional, Computed, Deprecated in v1.122.0+) Field `name` has been deprecated from provider version 1.122.0. New field `disk_name` instead.
* `payment_type` - (Optional) Payment method for disk. Valid values: `PostPaid`, `PrePaid`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的枚举值记得修改

* `delete_auto_snapshot` - (Optional) Indicates whether the automatic snapshot is deleted when the disk is released. Default value: `false`.
* `delete_with_instance` - (Optional) Indicates whether the disk is released together with the instance. Default value: `false`.
* `description` - (Optional) Description of the disk. This description can have a string of 2 to 256 characters, It cannot begin with http:// or https://. Default value is null.
* `disk_name` - (Optional, Computed) Name of the ECS disk. This 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://. Default value is null.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such as "-", ".", "_", and must not begin or end with a hyphen, and must not begin with `http://` or `https://`. Default value is `null`.

@lixue323 lixue323 force-pushed the change branch 5 times, most recently from a1fdfbb to 4d9cecb Compare April 16, 2021 05:24
}
request["PageSize"] = PageSizeLarge
request["PageNumber"] = 1
request["MaxResults"] = PageSizeLarge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个接口同时支持 Page 和 MaxResults 查询, 如果使用了 Page 分页, MaxResults 参数需要过滤掉

break
}
request["PageNumber"] = request["PageNumber"].(int) + 1
if nextToken, ok := response["NextToken"].(string); ok && nextToken != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也是NextToken 不需要

return WrapError(err)
}
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.Timeout(schema.TimeoutCreate) 这个需要在 schema 中定义, update 中也是一样

* `kms_key_id` - (Optional, ForceNew) The kms key id.
* `name_regex` - (Optional, ForceNew) A regex string to filter results by Disk name.
* `output_file` - (Optional) File name where to save data source results (after running `terraform plan`).
* `payment_type` - (Optional, ForceNew) Payment method for disk.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payment_type 枚举值


Basic usage

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terraform

@lixue323 lixue323 force-pushed the change branch 7 times, most recently from cdd8867 to 8adc101 Compare April 21, 2021 10:59
ResourceName: resourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"advanced_features", "auto_pay", "dedicated_block_storage_cluster_id", "dry_run", "encrypt_algorithm", "storage_set_id", "storage_set_partition_number"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check all of ImportStateVerifyIgnore and I think there are some attribute should not be here.

"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func testAccCheckDiskAttachmentDestroy(s *terraform.State) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method also used? I think using new test structure can instead.

},
"delete_with_instance": {
Type: schema.TypeBool,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bootable and delete_with_instance should have default value.


if v, ok := d.GetOk("device"); ok {
request["Device"] = v
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the block 83-85 can be removed because of it has been useless.

d.Set("disk_id", disk["DiskId"])

if strings.HasPrefix(disk["Device"].(string), "/dev/x") {
disk["Device"] = "/dev/" + disk["Device"].(string)[len("/dev/x"):]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to do more joint jobs.

@lixue323 lixue323 force-pushed the change branch 3 times, most recently from 864116a to ab8f9bf Compare April 27, 2021 02:21
request["AutoSnapshotPolicyId"] = v
}
if v, ok := d.GetOk("availability_zone"); ok {
request["ZoneId"] = v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecated availability_zone and using zone_id instead

Optional: true,
ForceNew: true,
},
"availability_zone": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecated the. availability_zone and using zone_id instead.

"DiskId": d.Id(),
}
request["NewSize"] = d.Get("size")
request["Type"] = "online"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expose the type to an attaibute.

request["DiskType"] = v
}
if v, ok := d.GetOk("type"); ok {
request["DiskType"] = v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check line 399-401.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新参数diskType, 老参数Type, 做兼容

}
if v, ok := d.GetOk("availability_zone"); ok {
request["ZoneId"] = v
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If zone_id is specified, availability_zone should be ingored.

"category": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"cloud", "cloud_efficiency", "cloud_essd", "cloud_ssd"}, false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enum values are not equal to its datasource

"type": {
Type: schema.TypeString,
Optional: true,
Default: "offline",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the type have enum values?

available_resource_creation= "VSwitch"
}
resource "alicloud_ecs_disk" "default" {
availability_zone = "${data.alicloud_zones.disk.zones.0.id}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be zone_id

continue
}
sweeped = true
action = "DeleteDisk"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line 76 should be action := "DeleteDisk"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前边已经定义了action,查询接口调用之后,去做删除

{
Config: testAccConfig(map[string]interface{}{
"disk_name": name,
"availability_zone": "${data.alicloud_zones.default.zones.0.id}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zone_id


* `additional_attributes` - (Optional, ForceNew) Other attribute values. Currently, only the incoming value of IOPS is supported, which means to query the IOPS upper limit of the current disk.
* `auto_snapshot_policy_id` - (Optional, ForceNew) Query cloud disks based on the automatic snapshot policy ID.
* `availability_zone` - (Optional, ForceNew) ID of the free zone to which the disk belongs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep sync the attribute with the schema.

* `expiration_time` - Disk expiration time.
* `tags` - A map of tags assigned to the disk.
* `resource_group_id` - The Id of resource group.
* `auto_snapshot_policy_id` - Query cloud disks based on the automatic snapshot policy ID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should not have indent.


```terraform
resource "alicloud_ecs_disk" "example" {
availability_zone = "cn-beijing-b"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the latest attribute name.

@lixue323 lixue323 force-pushed the change branch 2 times, most recently from acae4ee to 266cdb6 Compare April 27, 2021 09:50
})
if err != nil {
if IsExpectedErrors(err, []string{"InvalidDiskChargeType.NotFound", "InvalidDiskIds.ValueNotSupported", "InvalidFilterKey.NotFound", "InvalidFilterValue", "InvalidLockReason.NotFound"}) {
return object, WrapErrorf(Error(GetNotFoundMessage("ECS:Disk", id)), NotFoundMsg, ProviderERROR, fmt.Sprint(response["RequestId"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so many error codes?

log.Printf("[ERROR] Failed to delete Disk (%s): %s", item["DiskName"].(string), err)
}
if sweeped {
time.Sleep(5 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove to outside of for block.

}

ecsService := EcsService{client}
oldDisk, err := ecsService.DescribeEcsDisk(d.Get("disk_id").(string))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is a describe action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

兼容之前代码,绑定前后,属性可能会改变,如果对比之后改变了,之后会调用更新方法改回来

Optional: true,
ForceNew: true,
},
"disk_type": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a default value all in the docs.

ECS Disk can be imported using the id, e.g.

```
$ terraform import alicloud_ecs_disk.example <id>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a fake resource id, not

@lixue323 lixue323 force-pushed the change branch 2 times, most recently from 74091ed to f40e2f1 Compare April 29, 2021 03:34
@xiaozhu36 xiaozhu36 changed the title resource/alicloud_ecs_disk: Deprecates the name and use disk_name instead; Upgrades the its dependence sdk resource/alicloud_ecs_disk: Renames alicloud_disk to alicloud_ecs_disk; Deprecates the name and use disk_name instead; Adds more attribute, like payment_type, encrypt_algorithm, auto_snapshot and so on; Upgrades the its dependence sdk Apr 29, 2021
@xiaozhu36 xiaozhu36 merged commit 7e0de8b into aliyun:master Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants