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

support a cpu_options block to specify accelerators options. #8497

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
support a cpu_options block to specify accelerators options.
xwu2intel committed Mar 12, 2025
commit f709aac8b9739a1e1dec7c1fd2d139bc7b43e86c
30 changes: 30 additions & 0 deletions alicloud/resource_alicloud_instance.go
Original file line number Diff line number Diff line change
@@ -696,6 +696,23 @@ func resourceAliCloudInstance() *schema.Resource {
},
},
},
"cpu_options": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"accelerators": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MaxItems: 10,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
}
}
@@ -1120,6 +1137,19 @@ func resourceAliCloudInstanceCreate(d *schema.ResourceData, meta interface{}) er
}
}

if v, ok := d.GetOk("cpu_options"); ok {
for _, raw := range v.(*schema.Set).List() {
cpuOptionsArg := raw.(map[string]interface{})
if v, ok := cpuOptionsArg["accelerators"]; ok {
count := 1
for _, accelerator := range v.(*schema.Set).List() {
request[fmt.Sprintf("CpuOptions.Accelerators.%d", count)] = accelerator
count++
}
}
}
}

wait := incrementalWait(1*time.Second, 1*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = client.RpcPost("Ecs", "2014-05-26", action, nil, request, false)
7 changes: 7 additions & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
@@ -238,6 +238,7 @@ The following arguments are supported:
-> **NOTE:** If you set `password_inherit` to `true`, make sure that you have not specified `password` or `kms_encrypted_password` and the selected image has a preset password.

* `image_options` - (Optional, Available since v1.237.0) The options of images. See [`image_options`](#image_options) below.
* `cpu_options` - (Optional, Available since v1.245.0) The options of cpus. See [`cpu_options`](#cpu_options) below.

-> **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.

@@ -312,6 +313,12 @@ The image_options supports the following:

* `login_as_non_root` - (Optional, ForceNew) Whether to allow the instance logging in with the ecs-user user.

### `cpu_options`

The cpu_options supports the following:

* `accelerators` - (Optional) The list of accelerators to enable with the instance.

## Attributes Reference

The following attributes are exported: