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

data-source/alicloud_ecs_disks: Removed the default value of the field enable_auto_snapshot; Improved the document #8048

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions alicloud/data_source_alicloud_ecs_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func dataSourceAlicloudEcsDisks() *schema.Resource {
func dataSourceAliCloudEcsDisks() *schema.Resource {
return &schema.Resource{
Read: dataSourceAlicloudEcsDisksRead,
Read: dataSourceAliCloudEcsDisksRead,
Schema: map[string]*schema.Schema{
"additional_attributes": {
Type: schema.TypeList,
Expand Down Expand Up @@ -89,7 +89,6 @@ func dataSourceAlicloudEcsDisks() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Default: true,
},
"enable_automated_snapshot_policy": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -247,6 +246,10 @@ func dataSourceAlicloudEcsDisks() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"expiration_time": {
Type: schema.TypeString,
Computed: true,
},
"iops": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -382,7 +385,7 @@ func dataSourceAlicloudEcsDisks() *schema.Resource {
}
}

func dataSourceAlicloudEcsDisksRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceAliCloudEcsDisksRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)

action := "DescribeDisks"
Expand Down Expand Up @@ -580,6 +583,7 @@ func dataSourceAlicloudEcsDisksRead(d *schema.ResourceData, meta interface{}) er
"enable_automated_snapshot_policy": object["EnableAutomatedSnapshotPolicy"],
"encrypted": string(OnFlag),
"expired_time": object["ExpiredTime"],
"expiration_time": object["ExpiredTime"],
"iops": formatInt(object["IOPS"]),
"iops_read": formatInt(object["IOPSRead"]),
"iops_write": formatInt(object["IOPSWrite"]),
Expand Down
115 changes: 58 additions & 57 deletions alicloud/data_source_alicloud_ecs_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,101 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
)

func TestAccAlicloudECSDisksDataSource(t *testing.T) {
func TestAccAliCloudECSDisksDataSource(t *testing.T) {
rand := acctest.RandInt()
idsConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}_fake"]`,
}),
}
ZoneIdConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"zone_id": `"${alicloud_ecs_disk.default.zone_id}"`,
}),
}
categoryConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"category": `"cloud_efficiency"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"category": `"cloud"`,
}),
}
deleteAutoSnapshotConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"delete_auto_snapshot": `"true"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"delete_auto_snapshot": `"false"`,
}),
}
deleteWithInstanceConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"delete_with_instance": `"true"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"delete_with_instance": `"false"`,
}),
}
diskNameConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"disk_name": `"${alicloud_ecs_disk.default.disk_name}"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"disk_name": `"${alicloud_ecs_disk.default.disk_name}_fake"`,
}),
}
enableAutoSnapshotConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"enable_auto_snapshot": `"true"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"enable_auto_snapshot": `"false"`,
}),
}
encryptedConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"encrypted": `"on"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"encrypted": `"off"`,
}),
}
paymentTypeConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"payment_type": `"PayAsYouGo"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"payment_type": `"Subscription"`,
}),
}
tagsConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"tags": `{
"Created" = "TF"
"Environment" = "Acceptance-test"
}`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"tags": `{
"Created" = "TF-fake"
Expand All @@ -111,37 +111,37 @@ func TestAccAlicloudECSDisksDataSource(t *testing.T) {
}),
}
nameRegexConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"name_regex": `"${alicloud_ecs_disk.default.disk_name}"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"name_regex": `"${alicloud_ecs_disk.default.disk_name}_fake"`,
}),
}
statusConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"status": `"Available"`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"ids": `["${alicloud_ecs_disk.default.id}"]`,
"status": `"Creating"`,
}),
}

pagingConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"disk_name": `"${alicloud_ecs_disk.default.disk_name}"`,
"page_number": `1`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"disk_name": `"${alicloud_ecs_disk.default.disk_name}"`,
"page_number": `2`,
}),
}

allConf := dataSourceTestAccConfig{
existConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
existConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"zone_id": `"${alicloud_ecs_disk.default.zone_id}"`,
"category": `"cloud_efficiency"`,
"delete_auto_snapshot": `"true"`,
Expand All @@ -159,7 +159,7 @@ func TestAccAlicloudECSDisksDataSource(t *testing.T) {
}`,
"page_number": `1`,
}),
fakeConfig: testAccCheckAlicloudEcsDisksDataSourceName(rand, map[string]string{
fakeConfig: testAccCheckAliCloudEcsDisksDataSourceName(rand, map[string]string{
"category": `"cloud"`,
"delete_auto_snapshot": `"false"`,
"delete_with_instance": `"false"`,
Expand All @@ -177,7 +177,7 @@ func TestAccAlicloudECSDisksDataSource(t *testing.T) {
"page_number": `2`,
}),
}
var existAlicloudEcsDisksDataSourceNameMapFunc = func(rand int) map[string]string {
var existAliCloudEcsDisksDataSourceNameMapFunc = func(rand int) map[string]string {
return map[string]string{
"ids.#": "1",
"names.#": "1",
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestAccAlicloudECSDisksDataSource(t *testing.T) {
"disks.0.tags.Environment": "Acceptance-test",
}
}
var fakeAlicloudEcsDisksDataSourceNameMapFunc = func(rand int) map[string]string {
var fakeAliCloudEcsDisksDataSourceNameMapFunc = func(rand int) map[string]string {
return map[string]string{
"ids.#": "0",
"names.#": "0",
Expand All @@ -217,44 +217,45 @@ func TestAccAlicloudECSDisksDataSource(t *testing.T) {
}
var alicloudEcsDisksCheckInfo = dataSourceAttr{
resourceId: "data.alicloud_ecs_disks.default",
existMapFunc: existAlicloudEcsDisksDataSourceNameMapFunc,
fakeMapFunc: fakeAlicloudEcsDisksDataSourceNameMapFunc,
existMapFunc: existAliCloudEcsDisksDataSourceNameMapFunc,
fakeMapFunc: fakeAliCloudEcsDisksDataSourceNameMapFunc,
}
alicloudEcsDisksCheckInfo.dataSourceTestCheck(t, rand, idsConf, ZoneIdConf, categoryConf, deleteAutoSnapshotConf, deleteWithInstanceConf, diskNameConf, enableAutoSnapshotConf, encryptedConf, paymentTypeConf, tagsConf, nameRegexConf, statusConf, pagingConf, allConf)
}
func testAccCheckAlicloudEcsDisksDataSourceName(rand int, attrMap map[string]string) string {
func testAccCheckAliCloudEcsDisksDataSourceName(rand int, attrMap map[string]string) string {
var pairs []string
for k, v := range attrMap {
pairs = append(pairs, k+" = "+v)
}

config := fmt.Sprintf(`
variable "name" {
default = "tf-testAccDisk-%d"
}

variable "name" {
default = "tf-testAccDisk-%d"
}
data "alicloud_zones" "default" {
available_resource_creation= "VSwitch"
}
resource "alicloud_ecs_disk" "default" {
zone_id = "${data.alicloud_zones.default.zones.0.id}"
category = "cloud_efficiency"
delete_auto_snapshot = "true"
delete_with_instance = "true"
description = "Test For Terraform"
disk_name = var.name
enable_auto_snapshot = "true"
encrypted = "true"
size = "500"
tags = {
Created = "TF"
Environment = "Acceptance-test"
}
}
data "alicloud_zones" "default" {
available_resource_creation = "VSwitch"
}

data "alicloud_ecs_disks" "default" {
%s
}
resource "alicloud_ecs_disk" "default" {
zone_id = data.alicloud_zones.default.zones.0.id
category = "cloud_efficiency"
delete_auto_snapshot = "true"
delete_with_instance = "true"
description = "Test For Terraform"
disk_name = var.name
enable_auto_snapshot = "true"
encrypted = "true"
size = "500"
tags = {
Created = "TF"
Environment = "Acceptance-test"
}
}

data "alicloud_ecs_disks" "default" {
%s
}
`, rand, strings.Join(pairs, " \n "))
return config
}
4 changes: 2 additions & 2 deletions alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_instance_type_families": dataSourceAlicloudInstanceTypeFamilies(),
"alicloud_instance_types": dataSourceAlicloudInstanceTypes(),
"alicloud_instances": dataSourceAlicloudInstances(),
"alicloud_disks": dataSourceAlicloudEcsDisks(),
"alicloud_disks": dataSourceAliCloudEcsDisks(),
"alicloud_network_interfaces": dataSourceAlicloudEcsNetworkInterfaces(),
"alicloud_snapshots": dataSourceAlicloudEcsSnapshots(),
"alicloud_vpcs": dataSourceAlicloudVpcs(),
Expand Down Expand Up @@ -487,7 +487,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_adb_db_clusters": dataSourceAlicloudAdbDbClusters(),
"alicloud_vpc_flow_logs": dataSourceAlicloudVpcFlowLogs(),
"alicloud_network_acls": dataSourceAlicloudNetworkAcls(),
"alicloud_ecs_disks": dataSourceAlicloudEcsDisks(),
"alicloud_ecs_disks": dataSourceAliCloudEcsDisks(),
"alicloud_ddoscoo_domain_resources": dataSourceAlicloudDdoscooDomainResources(),
"alicloud_ddoscoo_ports": dataSourceAlicloudDdoscooPorts(),
"alicloud_slb_load_balancers": dataSourceAlicloudSlbLoadBalancers(),
Expand Down
Loading
Loading