diff --git a/.gitignore b/.gitignore index 6ec65f5c3381..9f209be398d5 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ coverage.out .qwenignore .qoder/ .terraflow/ -.terraflow.jsonc \ No newline at end of file +.terraflow.jsonc +.opencode/package-lock.json \ No newline at end of file diff --git a/.opencode/skills/provider-fix-regression/SKILL.md b/.opencode/skills/provider-fix-regression/SKILL.md new file mode 100644 index 000000000000..8bcb9ee74913 --- /dev/null +++ b/.opencode/skills/provider-fix-regression/SKILL.md @@ -0,0 +1,253 @@ +--- +name: provider-fix-regression +description: Automatically fetch failed regression test cases for a specific Alibaba Cloud product from ACube, analyze the root cause, fix the Provider resource code or test case, and submit a PR. Supports filtering by product / resource / error type / date range. +metadata: + version: "1.0.0" + domain: terraform-provider + triggers: fix regression test, 修复回归测试, auto fix failed testcase, concourse build analysis, 修失败用例, regression repair, 自动修复回归 +--- + +# Provider Fix Regression Tests + +Fetch failed regression cases from ACube, analyze, fix the Provider code or test, and submit a PR. + +## Data Source + +ACube exposes regression analysis records (`concourse_build_analysis` table) via HTTP API. Each record contains: `caseName`, `errorType`, `conclusion`, and the full `logContext` of the failed test. + +## API + +``` +GET https://pre-acube.aliyun-inc.com/api/v1/resource_type/info/query_build_analysis +``` + +Production host: `https://acube.aliyun-inc.com` (omit if unknown, ask user to confirm). + +| Param | Required | Notes | +|---|---|---| +| `namespace` | Y | Product name, e.g. `ecs`, `vpc`, `rds` | +| `resourceCode` | N | Specific resource, omit to get all resources under the product | +| `errorType` | N | Filter by error type, default: all; use `OTHER` / `FAIL`-like types to get failures only | +| `startDate` | N | `yyyy-MM-dd`, default: last 7 days | +| `endDate` | N | `yyyy-MM-dd` | +| `pageNum` | N | default `0` | +| `pageSize` | N | default `20`, max `100` | + +**Error type values** (from `ConcourseErrorTypeEnum`): + +| value | meaning | +|---|---| +| `PASS` | passed (skip) | +| `SKIP` | skipped (skip) | +| `QUOTA_EXCEEDED` | quota problem — usually NOT a code bug, run `make sweep` | +| `ACCOUNT_AUTHORIZE` | auth problem — infra issue, not code | +| `RESOURCE_NOT_FOUND` | dependency resource missing | +| `REQUIRED_ARGUMENT_ABSENT` | required arg missing in test config | +| `REQUEST_PARAMETER_INVALID` | bad request params | +| `ATTRIBUTE_NOT_FOUND` | attribute missing from Read response | +| `ATTRIBUTE_NOT_EXPECTED` | attribute value mismatch in assertion | +| `INVALID_OPERATION` | resource state wrong for operation | +| `RESOURCE_NOT_DESTROYED` | cleanup failure | +| `OTHER` | uncategorized | + +## Step 1: Obtain Scope + +Determine from the user request: + +- **Product** (`namespace`) — required. If missing, ask. +- **Resource** (`resourceCode`) — optional, narrows scope. +- **Time range** — default last 7 days. + +If the user says "fix all failures for ecs", use `namespace=ecs` without `resourceCode`. + +## Step 2: Fetch Failed Cases + +```bash +# Fetch failures only (exclude PASS/SKIP) +curl -sG "https://pre-acube.aliyun-inc.com/api/v1/resource_type/info/query_build_analysis" \ + --data-urlencode "namespace=" \ + --data-urlencode "resourceCode=" \ + --data-urlencode "pageSize=100" | jq . +``` + +Since `errorType` filters by exact value, to get all failures in one call omit `errorType` and client-side filter out `PASS` / `SKIP`. + +**Group results by `caseName`**. Same case may fail multiple times across runs — use the most recent record per case (highest `id` or latest `gmtCreate`). + +**Bucket by `errorType`** to prioritize: + +1. **Skip-category (no code fix needed)** — `QUOTA_EXCEEDED`, `ACCOUNT_AUTHORIZE`, `PASS`, `SKIP`. Document, do not modify. +2. **Likely Provider bug** — `ATTRIBUTE_NOT_FOUND`, `ATTRIBUTE_NOT_EXPECTED`, `RESOURCE_NOT_DESTROYED`, `INVALID_OPERATION`. +3. **Likely test case bug** — `REQUIRED_ARGUMENT_ABSENT`, `REQUEST_PARAMETER_INVALID`, `RESOURCE_NOT_FOUND` (test's dependency config wrong). +4. **Needs deeper log analysis** — `OTHER`. + +## Step 3: Prepare Development Environment + +```bash +cd +git checkout master +git pull --rebase alicloud master +git checkout -b fix/--regression-$(date +%Y%m%d) +``` + +Use ONE branch for all failures within the same resource. If fixing multiple resources, use separate branches. + +## Step 4: Locate Target Files + +For each failing `caseName` (e.g. `TestAccAliCloudEcsInstance_basic`): + +- Test file: `alicloud/resource_alicloud__test.go` +- Resource: `alicloud/resource_alicloud_.go` +- Service: `alicloud/service_alicloud_[_v2].go` +- Doc (if attribute-related): `website/docs/r/_.html.markdown` + +Extract resource name from caseName: `TestAccAliCloud_` → resource is ``. + +## Step 5: Root-Cause Analysis + +Parse `logContext` of the failing case. Key patterns to extract: + +| Pattern in log | Likely cause | Where to fix | +|---|---|---| +| `Attribute '' not found` | Read method missing `d.Set` call, or API response path changed | `resource_*.go` Read func | +| `Attribute '' expected ... got ...` | Type coercion bug, zero-value drop, or API returned different format | Read func + possibly Schema | +| `Missing required argument "" is required` | Test config missing required field | `*_test.go` config template | +| `Failed: ... InvalidParameter ...` | Wrong request payload, e.g. `GetOk` on bool dropping `false` | Create/Update func | +| `the resource was not destroyed` | Delete API not wired up or dependency order wrong | Delete func | +| `cannot be found` during Read | Read returns object but not handling `NotFound` — should `d.SetId(""); return nil` | Read func | + +If pattern unclear, **print the log snippet to the user with a suggested fix plan before modifying code**. + +## Step 6: Apply Fix + +Use sibling skills for the specific fix type: + +| Failure type | Load skill | +|---|---| +| Attribute missing / wrong in docs | `provider-fix-documentation` | +| Need to add/change an attribute | `provider-add-attribute` | +| General code review needed before fix | `provider-resource-review` | + +Common fix patterns (apply directly if simple): + +### Fix A: `GetOk` drop on bool/int + +```go +// ❌ +if v, ok := d.GetOk("enabled"); ok { ... } +// ✅ +if v, ok := d.GetOkExists("enabled"); ok { ... } +``` + +### Fix B: Missing `d.Set` in Read + +Check every Schema field — each non-`ForceNew`, non-write-only field needs a matching `d.Set(..., object["..."])` in Read. + +### Fix C: Wrong array type assertion + +```go +// ❌ Panics +items := v.(*schema.Set).List() +items := v.([]interface{}) +// ✅ +items := convertToInterfaceArray(v) +``` + +### Fix D: Test config missing required arg + +Update the `config` string in the `*_test.go` file to include the required field. Prefer referencing via `${var.name}` / `${alicloud_.default.id}`. + +### Fix E: NotFound handling in Read + +```go +object, err := service.DescribeXxx(d.Id()) +if err != nil { + if NotFoundError(err) { + log.Printf("[DEBUG] Resource %s not found, removing from state", d.Id()) + d.SetId("") + return nil + } + return WrapError(err) +} +``` + +## Step 7: Verify Fix Locally + +For each fixed `caseName`: + +```bash +make test-resource-debug RESOURCE=alicloud_ TESTCASE= LOGLEVEL=TRACE LOGFILE=-fix.log +``` + +All targeted cases must PASS. Then run the full resource test set: + +```bash +make test-resource-debug RESOURCE=alicloud_ +``` + +Other failures unrelated to our fix → document, do not modify (acceptable pre-existing state). + +### 3-strike rule + +If 3 consecutive fix attempts on the **same case** fail, `git stash`, report full context (log + attempted diffs) to the user, STOP. + +## Step 8: Commit & CI + +```bash +git status && git diff +make commit +make ci-check +``` + +Squash to single commit: + +```bash +git log --oneline master..HEAD +# if >1 commit: +git reset --soft HEAD~N && git commit -m "" +``` + +Commit message format: + +``` +fix(): fix regression test cases + +- : +- : + +Refs: concourse_build_analysis#, +``` + +## Step 9: Report + +Present to the user: + +- **Fixed cases** (case name + root cause + diff file list) +- **Skipped cases** (case name + why skipped: quota / auth / pre-existing) +- **Unresolved cases** (case name + attempted fixes + why blocked) +- **Branch name + CI status** + +## Important Notes + +1. **Handle infra-category errors** (`QUOTA_EXCEEDED`, `ACCOUNT_AUTHORIZE`) — these are NOT code bugs. For `QUOTA_EXCEEDED` (e.g. `QuotaExceeded.Vpc`), first clean up dangling resources in the affected region before re-running tests: + ```bash + # Clean up VPC quota in the affected region (e.g. cn-hangzhou) + make sweep REGION=cn-hangzhou RESOURCE=alicloud_vpc + # Or sweep all resources + make sweep REGION=cn-hangzhou + # Then re-run the failing cases + make test-resource-debug RESOURCE=alicloud_ TESTCASE= + ``` + If sweep doesn't resolve the quota issue, escalate via ops ticket — do NOT modify code to workaround quota limits. +2. **One PR per resource** — do not batch unrelated resources into one branch. +3. **Always run `make ci-check`** before reporting success. `ci-check-quick` is only for docs-only changes. +4. **Do NOT modify** auto-generated resource files' first-line comment without a real content change. +5. The ACube API returns the `env` field as the run date (`yyyy-MM-dd`), not an environment name. Use it for time-based filtering. + +## Acceptance Criteria + +1. All in-scope failures addressed (fixed OR explicitly documented as out-of-scope). +2. `make test-resource-debug RESOURCE=alicloud_` — all previously-fixed cases PASS. +3. `make ci-check` passes. +4. Single squashed commit per resource. +5. Report delivered to user listing each case's outcome. diff --git a/alicloud/resource_alicloud_ecs_network_interface_attachment_test.go b/alicloud/resource_alicloud_ecs_network_interface_attachment_test.go index ed7ad38a2b82..322e3cb7d5be 100644 --- a/alicloud/resource_alicloud_ecs_network_interface_attachment_test.go +++ b/alicloud/resource_alicloud_ecs_network_interface_attachment_test.go @@ -74,6 +74,7 @@ func TestAccAliCloudECSNetworkInterfaceAttachment_basic0_twin(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -164,6 +165,7 @@ func TestAccAliCloudECSNetworkInterfaceAttachmentMulti(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -190,49 +192,49 @@ func AliCloudAliCloudEcsNetworkInterfaceAttachmentBasicDependence0(name string) default = "%s" } - data "alicloud_zones" "default" { - available_resource_creation = "Instance" +data "alicloud_zones" "default" { + available_resource_creation = "Instance" } - data "alicloud_instance_types" "default" { - availability_zone = data.alicloud_zones.default.zones.0.id - instance_type_family = "ecs.g7nex" +data "alicloud_instance_types" "default" { + image_id = data.alicloud_images.default.images.0.id + system_disk_category = "cloud_essd" } data "alicloud_images" "default" { - name_regex = "^ubuntu_[0-9]+_[0-9]+_x64*" - most_recent = true - owners = "system" + name_regex = "^ubuntu_[0-9]+_[0-9]+_x64*" + most_recent = true + owners = "system" } resource "alicloud_vpc" "default" { - vpc_name = var.name - cidr_block = "192.168.0.0/16" + vpc_name = var.name + cidr_block = "192.168.0.0/16" } resource "alicloud_vswitch" "default" { - vswitch_name = var.name - vpc_id = alicloud_vpc.default.id - cidr_block = "192.168.192.0/24" - zone_id = data.alicloud_zones.default.zones.0.id + vswitch_name = var.name + vpc_id = alicloud_vpc.default.id + cidr_block = "192.168.192.0/24" + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 } resource "alicloud_security_group" "default" { - name = var.name - vpc_id = alicloud_vpc.default.id + name = var.name + vpc_id = alicloud_vpc.default.id } resource "alicloud_instance" "default" { image_id = data.alicloud_images.default.images.0.id - instance_type = data.alicloud_instance_types.default.instance_types.0.id - instance_name = var.name - security_groups = alicloud_security_group.default.*.id - internet_charge_type = "PayByTraffic" - internet_max_bandwidth_out = "10" - availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + instance_type = data.alicloud_instance_types.default.instance_types.0.id + instance_name = var.name + security_groups = alicloud_security_group.default.*.id + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_out = "10" + availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 instance_charge_type = "PostPaid" system_disk_category = "cloud_essd" - vswitch_id = alicloud_vswitch.default.id + vswitch_id = alicloud_vswitch.default.id } resource "alicloud_ecs_network_interface" "default" { @@ -315,46 +317,46 @@ func AliCloudEcsNetworkInterfaceAttachmentBasicDependenceMulti(name string) stri available_resource_creation = "Instance" } - data "alicloud_instance_types" "default" { - availability_zone = data.alicloud_zones.default.zones.0.id - instance_type_family = "ecs.sn1ne" +data "alicloud_instance_types" "default" { + image_id = data.alicloud_images.default.images.0.id + system_disk_category = "cloud_essd" } data "alicloud_images" "default" { - name_regex = "^ubuntu_[0-9]+_[0-9]+_x64*" - most_recent = true - owners = "system" + name_regex = "^ubuntu_[0-9]+_[0-9]+_x64*" + most_recent = true + owners = "system" } resource "alicloud_vpc" "default" { - vpc_name = var.name - cidr_block = "192.168.0.0/16" + vpc_name = var.name + cidr_block = "192.168.0.0/16" } resource "alicloud_vswitch" "default" { - vswitch_name = var.name - vpc_id = alicloud_vpc.default.id - cidr_block = "192.168.192.0/24" - zone_id = data.alicloud_zones.default.zones.0.id + vswitch_name = var.name + vpc_id = alicloud_vpc.default.id + cidr_block = "192.168.192.0/24" + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 } resource "alicloud_security_group" "default" { - name = var.name - vpc_id = alicloud_vpc.default.id + name = var.name + vpc_id = alicloud_vpc.default.id } resource "alicloud_instance" "default" { - count = 2 - image_id = data.alicloud_images.default.images.0.id - instance_type = data.alicloud_instance_types.default.instance_types.0.id - instance_name = var.name - security_groups = alicloud_security_group.default.*.id - internet_charge_type = "PayByTraffic" - internet_max_bandwidth_out = "10" - availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 - instance_charge_type = "PostPaid" - system_disk_category = "cloud_efficiency" - vswitch_id = alicloud_vswitch.default.id + count = 2 + image_id = data.alicloud_images.default.images.0.id + instance_type = data.alicloud_instance_types.default.instance_types.0.id + instance_name = var.name + security_groups = alicloud_security_group.default.*.id + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_out = "10" + availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + instance_charge_type = "PostPaid" + system_disk_category = "cloud_essd" + vswitch_id = alicloud_vswitch.default.id } resource "alicloud_ecs_network_interface" "default" { diff --git a/alicloud/resource_alicloud_ecs_snapshot_group_test.go b/alicloud/resource_alicloud_ecs_snapshot_group_test.go index 3fbcfd975821..4ccd9b902808 100644 --- a/alicloud/resource_alicloud_ecs_snapshot_group_test.go +++ b/alicloud/resource_alicloud_ecs_snapshot_group_test.go @@ -123,6 +123,7 @@ func TestAccAliCloudECSSnapshotGroup_basic0(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -214,6 +215,7 @@ func TestAccAliCloudECSSnapshotGroup_basic1(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -269,14 +271,13 @@ data "alicloud_resource_manager_resource_groups" "default" { } data "alicloud_zones" default { available_resource_creation = "Instance" - available_disk_category = "cloud_essd" } data "alicloud_instance_types" "default" { - availability_zone = "${data.alicloud_zones.default.zones.0.id}" - cpu_core_count = 2 - memory_size = 4 - system_disk_category = "cloud_essd" + image_id = data.alicloud_images.default.images.0.id + system_disk_category = "cloud_essd" + cpu_core_count = 2 + memory_size = 4 } data "alicloud_vpcs" "default" { @@ -285,7 +286,7 @@ data "alicloud_vpcs" "default" { data "alicloud_vswitches" "default" { vpc_id = data.alicloud_vpcs.default.ids.0 - zone_id = data.alicloud_zones.default.zones.0.id + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 } resource "alicloud_security_group" "default" { @@ -307,13 +308,14 @@ data "alicloud_images" "default" { } resource "alicloud_instance" "default" { - availability_zone = "${data.alicloud_zones.default.zones.0.id}" - instance_name = "${var.name}" - host_name = "tf-testAcc" - image_id = data.alicloud_images.default.images.0.id - instance_type = data.alicloud_instance_types.default.instance_types.0.id - security_groups = [alicloud_security_group.default.id] - vswitch_id = data.alicloud_vswitches.default.ids.0 + availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + instance_name = "${var.name}" + host_name = "tf-testAcc" + image_id = data.alicloud_images.default.images.0.id + instance_type = data.alicloud_instance_types.default.instance_types.0.id + security_groups = [alicloud_security_group.default.id] + vswitch_id = data.alicloud_vswitches.default.ids.0 + system_disk_category = "cloud_essd" } resource "alicloud_disk_attachment" "default" { diff --git a/alicloud/resource_alicloud_ecs_snapshot_test.go b/alicloud/resource_alicloud_ecs_snapshot_test.go index cfdb243dee85..22620fa2416f 100644 --- a/alicloud/resource_alicloud_ecs_snapshot_test.go +++ b/alicloud/resource_alicloud_ecs_snapshot_test.go @@ -117,6 +117,7 @@ func TestAccAliCloudECSSnapshot_basic0(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -202,6 +203,7 @@ func TestAccAliCloudECSSnapshot_basic0_twin(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -357,6 +359,7 @@ func TestAccAliCloudECSSnapshot_basic1_twin(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -417,66 +420,64 @@ func AliCloudEcsSnapshotBasicDependence0(name string) string { status = "OK" } - data "alicloud_zones" "default" { - available_disk_category = "cloud_essd" - available_resource_creation = "VSwitch" +data "alicloud_zones" "default" { + available_resource_creation = "VSwitch" } data "alicloud_images" "default" { - most_recent = true - owners = "system" + most_recent = true + owners = "system" } data "alicloud_instance_types" "default" { - availability_zone = data.alicloud_zones.default.zones.0.id - image_id = data.alicloud_images.default.images.0.id - system_disk_category = "cloud_essd" + image_id = data.alicloud_images.default.images.0.id + system_disk_category = "cloud_essd" } resource "alicloud_vpc" "default" { - vpc_name = var.name - cidr_block = "192.168.0.0/16" + vpc_name = var.name + cidr_block = "192.168.0.0/16" } resource "alicloud_vswitch" "default" { vswitch_name = var.name - vpc_id = alicloud_vpc.default.id - cidr_block = "192.168.192.0/24" - zone_id = data.alicloud_zones.default.zones.0.id + vpc_id = alicloud_vpc.default.id + cidr_block = "192.168.192.0/24" + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 } - + resource "alicloud_security_group" "default" { - name = var.name - vpc_id = alicloud_vpc.default.id + name = var.name + vpc_id = alicloud_vpc.default.id } - + resource "alicloud_instance" "default" { - image_id = data.alicloud_images.default.images.0.id - instance_type = data.alicloud_instance_types.default.instance_types.0.id - security_groups = alicloud_security_group.default.*.id - internet_charge_type = "PayByTraffic" - internet_max_bandwidth_out = "10" - availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 - instance_charge_type = "PostPaid" - system_disk_category = "cloud_essd" - vswitch_id = alicloud_vswitch.default.id - instance_name = var.name + image_id = data.alicloud_images.default.images.0.id + instance_type = data.alicloud_instance_types.default.instance_types.0.id + security_groups = alicloud_security_group.default.*.id + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_out = "10" + availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + instance_charge_type = "PostPaid" + system_disk_category = "cloud_essd" + vswitch_id = alicloud_vswitch.default.id + instance_name = var.name data_disks { category = "cloud_essd" size = 20 - } + } } resource "alicloud_ecs_disk" "default" { - disk_name = var.name - zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 - category = "cloud_essd" - size = 500 + disk_name = var.name + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + category = "cloud_essd" + size = 500 } resource "alicloud_ecs_disk_attachment" "default" { - disk_id = alicloud_ecs_disk.default.id - instance_id = alicloud_instance.default.id + disk_id = alicloud_ecs_disk.default.id + instance_id = alicloud_instance.default.id } `, name) } @@ -491,9 +492,8 @@ func AliCloudEcsSnapshotBasicDependence1(name string) string { status = "OK" } - data "alicloud_zones" "default" { - available_disk_category = "cloud_efficiency" - available_resource_creation = "VSwitch" +data "alicloud_zones" "default" { + available_resource_creation = "VSwitch" } data "alicloud_images" "default" { @@ -501,51 +501,51 @@ func AliCloudEcsSnapshotBasicDependence1(name string) string { owners = "system" } - data "alicloud_instance_types" "default" { - availability_zone = data.alicloud_zones.default.zones.0.id - image_id = data.alicloud_images.default.images.0.id +data "alicloud_instance_types" "default" { + image_id = data.alicloud_images.default.images.0.id + system_disk_category = "cloud_essd" } resource "alicloud_vpc" "default" { - vpc_name = var.name - cidr_block = "192.168.0.0/16" + vpc_name = var.name + cidr_block = "192.168.0.0/16" } resource "alicloud_vswitch" "default" { vswitch_name = var.name - vpc_id = alicloud_vpc.default.id - cidr_block = "192.168.192.0/24" - zone_id = data.alicloud_zones.default.zones.0.id + vpc_id = alicloud_vpc.default.id + cidr_block = "192.168.192.0/24" + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 } resource "alicloud_security_group" "default" { - name = var.name - vpc_id = alicloud_vpc.default.id + name = var.name + vpc_id = alicloud_vpc.default.id } resource "alicloud_instance" "default" { - image_id = data.alicloud_images.default.images.0.id - instance_type = data.alicloud_instance_types.default.instance_types.0.id - security_groups = alicloud_security_group.default.*.id - internet_charge_type = "PayByTraffic" - internet_max_bandwidth_out = "10" - availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 - instance_charge_type = "PostPaid" - system_disk_category = "cloud_efficiency" - vswitch_id = alicloud_vswitch.default.id - instance_name = var.name + image_id = data.alicloud_images.default.images.0.id + instance_type = data.alicloud_instance_types.default.instance_types.0.id + security_groups = alicloud_security_group.default.*.id + internet_charge_type = "PayByTraffic" + internet_max_bandwidth_out = "10" + availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + instance_charge_type = "PostPaid" +system_disk_category = "cloud_essd" + vswitch_id = alicloud_vswitch.default.id + instance_name = var.name } resource "alicloud_ecs_disk" "default" { - disk_name = var.name - zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 - category = "cloud_efficiency" - size = 500 + disk_name = var.name + zone_id = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 + category = "cloud_essd" + size = 500 } resource "alicloud_ecs_disk_attachment" "default" { - instance_id = alicloud_instance.default.id - disk_id = alicloud_ecs_disk.default.id + instance_id = alicloud_instance.default.id + disk_id = alicloud_ecs_disk.default.id } `, name) } diff --git a/alicloud/resource_alicloud_image_test.go b/alicloud/resource_alicloud_image_test.go index deef3afde8c2..c94d45618844 100644 --- a/alicloud/resource_alicloud_image_test.go +++ b/alicloud/resource_alicloud_image_test.go @@ -29,6 +29,7 @@ func TestAccAliCloudECSImageBasic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -131,6 +132,7 @@ func TestAccAliCloudECSImageBasic1(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -180,6 +182,7 @@ func TestAccAliCloudECSImageBasic2(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -226,7 +229,8 @@ variable "name" { } data "alicloud_instance_types" "default" { - instance_type_family = "ecs.sn1ne" + instance_type_family = "ecs.g6" + system_disk_category = "cloud_essd" } data "alicloud_images" "default" { @@ -279,8 +283,8 @@ data "alicloud_zones" default { data "alicloud_instance_types" "default" { - availability_zone = "${data.alicloud_zones.default.zones.0.id}" - instance_type_family = "ecs.sn1ne" + instance_type_family = "ecs.g6" + system_disk_category = "cloud_essd" } data "alicloud_images" "default" { @@ -323,7 +327,7 @@ resource "alicloud_disk" "default" { count = "2" disk_name = "${var.name}" availability_zone = data.alicloud_instance_types.default.instance_types.0.availability_zones.0 - category = "cloud_efficiency" + category = "cloud_essd" size = "20" } @@ -363,6 +367,7 @@ func TestAccAliCloudECSImageBasic7009(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) + testAccPreCheckWithRegions(t, true, []connectivity.Region{connectivity.Hangzhou}) }, IDRefreshName: resourceId, Providers: testAccProviders, @@ -620,7 +625,8 @@ variable "name" { } data "alicloud_instance_types" "default" { - instance_type_family = "ecs.sn1ne" + instance_type_family = "ecs.g6" + system_disk_category = "cloud_essd" } data "alicloud_resource_manager_resource_groups" "default" {}