Skip to content

Commit 21dea57

Browse files
committedMar 19, 2025·
resource/alicloud_eais_instance: Support attribute environment_var, image and instance_name; New Resource: alicloud_eais_instance.
1 parent d79d9d3 commit 21dea57

8 files changed

+1814
-100
lines changed
 

‎alicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ func Provider() terraform.ResourceProvider {
895895
"alicloud_vpc_ipam_ipams": dataSourceAliCloudVpcIpamIpams(),
896896
},
897897
ResourcesMap: map[string]*schema.Resource{
898+
"alicloud_eais_client_instance_attachment": resourceAliCloudEaisClientInstanceAttachment(),
898899
"alicloud_resource_manager_auto_grouping_rule": resourceAliCloudResourceManagerAutoGroupingRule(),
899900
"alicloud_eflo_invocation": resourceAliCloudEfloInvocation(),
900901
"alicloud_eflo_cluster": resourceAliCloudEfloCluster(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
package alicloud
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"strings"
7+
"time"
8+
9+
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
12+
)
13+
14+
func resourceAliCloudEaisClientInstanceAttachment() *schema.Resource {
15+
return &schema.Resource{
16+
Create: resourceAliCloudEaisClientInstanceAttachmentCreate,
17+
Read: resourceAliCloudEaisClientInstanceAttachmentRead,
18+
Update: resourceAliCloudEaisClientInstanceAttachmentUpdate,
19+
Delete: resourceAliCloudEaisClientInstanceAttachmentDelete,
20+
Importer: &schema.ResourceImporter{
21+
State: schema.ImportStatePassthrough,
22+
},
23+
Timeouts: &schema.ResourceTimeout{
24+
Create: schema.DefaultTimeout(5 * time.Minute),
25+
Update: schema.DefaultTimeout(5 * time.Minute),
26+
Delete: schema.DefaultTimeout(5 * time.Minute),
27+
},
28+
Schema: map[string]*schema.Schema{
29+
"client_instance_id": {
30+
Type: schema.TypeString,
31+
Required: true,
32+
ForceNew: true,
33+
},
34+
"create_time": {
35+
Type: schema.TypeString,
36+
Computed: true,
37+
},
38+
"ei_instance_type": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Computed: true,
42+
ForceNew: true,
43+
},
44+
"category": {
45+
Type: schema.TypeString,
46+
Optional: true,
47+
},
48+
"instance_id": {
49+
Type: schema.TypeString,
50+
Required: true,
51+
ForceNew: true,
52+
},
53+
"region_id": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
},
57+
"status": {
58+
Type: schema.TypeString,
59+
Optional: true,
60+
Computed: true,
61+
},
62+
},
63+
}
64+
}
65+
66+
func resourceAliCloudEaisClientInstanceAttachmentCreate(d *schema.ResourceData, meta interface{}) error {
67+
68+
client := meta.(*connectivity.AliyunClient)
69+
if InArray(fmt.Sprint(d.Get("category")), []string{"eais", ""}) {
70+
action := "AttachEai"
71+
var request map[string]interface{}
72+
var response map[string]interface{}
73+
query := make(map[string]interface{})
74+
var err error
75+
request = make(map[string]interface{})
76+
if v, ok := d.GetOk("instance_id"); ok {
77+
request["ElasticAcceleratedInstanceId"] = v
78+
}
79+
if v, ok := d.GetOk("client_instance_id"); ok {
80+
request["ClientInstanceId"] = v
81+
}
82+
request["RegionId"] = client.RegionId
83+
84+
wait := incrementalWait(3*time.Second, 5*time.Second)
85+
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
86+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
87+
if err != nil {
88+
if NeedRetry(err) {
89+
wait()
90+
return resource.RetryableError(err)
91+
}
92+
return resource.NonRetryableError(err)
93+
}
94+
return nil
95+
})
96+
addDebug(action, response, request)
97+
98+
if err != nil {
99+
return WrapErrorf(err, DefaultErrorMsg, "alicloud_eais_client_instance_attachment", action, AlibabaCloudSdkGoERROR)
100+
}
101+
102+
d.SetId(fmt.Sprintf("%v:%v", response["ElasticAcceleratedInstanceId"], response["ClientInstanceId"]))
103+
104+
}
105+
106+
if v, ok := d.GetOk("category"); ok && InArray(fmt.Sprint(v), []string{"ei"}) {
107+
action := "AttachEaisEi"
108+
var request map[string]interface{}
109+
var response map[string]interface{}
110+
query := make(map[string]interface{})
111+
var err error
112+
request = make(map[string]interface{})
113+
if v, ok := d.GetOk("instance_id"); ok {
114+
request["EiInstanceId"] = v
115+
}
116+
if v, ok := d.GetOk("client_instance_id"); ok {
117+
request["ClientInstanceId"] = v
118+
}
119+
request["RegionId"] = client.RegionId
120+
121+
if v, ok := d.GetOk("ei_instance_type"); ok {
122+
request["EiInstanceType"] = v
123+
}
124+
wait := incrementalWait(3*time.Second, 5*time.Second)
125+
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
126+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
127+
if err != nil {
128+
if NeedRetry(err) {
129+
wait()
130+
return resource.RetryableError(err)
131+
}
132+
return resource.NonRetryableError(err)
133+
}
134+
return nil
135+
})
136+
addDebug(action, response, request)
137+
138+
if err != nil {
139+
return WrapErrorf(err, DefaultErrorMsg, "alicloud_eais_client_instance_attachment", action, AlibabaCloudSdkGoERROR)
140+
}
141+
142+
d.SetId(fmt.Sprintf("%v:%v", response["EiInstanceId"], response["ClientInstanceId"]))
143+
144+
}
145+
146+
return resourceAliCloudEaisClientInstanceAttachmentUpdate(d, meta)
147+
}
148+
149+
func resourceAliCloudEaisClientInstanceAttachmentRead(d *schema.ResourceData, meta interface{}) error {
150+
client := meta.(*connectivity.AliyunClient)
151+
eaisServiceV2 := EaisServiceV2{client}
152+
153+
objectRaw, err := eaisServiceV2.DescribeEaisClientInstanceAttachment(d.Id())
154+
if err != nil {
155+
if !d.IsNewResource() && NotFoundError(err) {
156+
log.Printf("[DEBUG] Resource alicloud_eais_client_instance_attachment DescribeEaisClientInstanceAttachment Failed!!! %s", err)
157+
d.SetId("")
158+
return nil
159+
}
160+
return WrapError(err)
161+
}
162+
163+
d.Set("create_time", objectRaw["StartTime"])
164+
d.Set("ei_instance_type", objectRaw["InstanceType"])
165+
d.Set("region_id", objectRaw["RegionId"])
166+
d.Set("status", objectRaw["Status"])
167+
d.Set("client_instance_id", objectRaw["ClientInstanceId"])
168+
d.Set("instance_id", objectRaw["ElasticAcceleratedInstanceId"])
169+
170+
return nil
171+
}
172+
173+
func resourceAliCloudEaisClientInstanceAttachmentUpdate(d *schema.ResourceData, meta interface{}) error {
174+
client := meta.(*connectivity.AliyunClient)
175+
var request map[string]interface{}
176+
var response map[string]interface{}
177+
var query map[string]interface{}
178+
179+
enableAction := false
180+
if v, ok := d.GetOk("category"); ok && InArray(fmt.Sprint(v), []string{"ei"}) {
181+
enableAction = true
182+
}
183+
if enableAction && d.HasChange("status") {
184+
eaisServiceV2 := EaisServiceV2{client}
185+
object, err := eaisServiceV2.DescribeEaisClientInstanceAttachment(d.Id())
186+
if err != nil {
187+
return WrapError(err)
188+
}
189+
190+
target := d.Get("status").(string)
191+
if object["Status"].(string) != target {
192+
if target == "InUse" {
193+
parts := strings.Split(d.Id(), ":")
194+
action := "StartEaisEi"
195+
request = make(map[string]interface{})
196+
query = make(map[string]interface{})
197+
request["EiInstanceId"] = parts[0]
198+
request["RegionId"] = client.RegionId
199+
wait := incrementalWait(3*time.Second, 5*time.Second)
200+
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
201+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
202+
if err != nil {
203+
if NeedRetry(err) {
204+
wait()
205+
return resource.RetryableError(err)
206+
}
207+
return resource.NonRetryableError(err)
208+
}
209+
return nil
210+
})
211+
addDebug(action, response, request)
212+
if err != nil {
213+
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
214+
}
215+
216+
}
217+
if target == "Bound" {
218+
parts := strings.Split(d.Id(), ":")
219+
action := "StopEaisEi"
220+
request = make(map[string]interface{})
221+
query = make(map[string]interface{})
222+
request["EiInstanceId"] = parts[0]
223+
request["RegionId"] = client.RegionId
224+
wait := incrementalWait(3*time.Second, 5*time.Second)
225+
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
226+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
227+
if err != nil {
228+
if NeedRetry(err) {
229+
wait()
230+
return resource.RetryableError(err)
231+
}
232+
return resource.NonRetryableError(err)
233+
}
234+
return nil
235+
})
236+
addDebug(action, response, request)
237+
if err != nil {
238+
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
239+
}
240+
241+
}
242+
}
243+
}
244+
245+
return resourceAliCloudEaisClientInstanceAttachmentRead(d, meta)
246+
}
247+
248+
func resourceAliCloudEaisClientInstanceAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
249+
250+
enableDelete := false
251+
if InArray(fmt.Sprint(d.Get("category")), []string{"eais", ""}) {
252+
enableDelete = true
253+
}
254+
if enableDelete {
255+
client := meta.(*connectivity.AliyunClient)
256+
parts := strings.Split(d.Id(), ":")
257+
action := "DetachEai"
258+
var request map[string]interface{}
259+
var response map[string]interface{}
260+
query := make(map[string]interface{})
261+
var err error
262+
request = make(map[string]interface{})
263+
request["ElasticAcceleratedInstanceId"] = parts[0]
264+
request["RegionId"] = client.RegionId
265+
266+
wait := incrementalWait(3*time.Second, 5*time.Second)
267+
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
268+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
269+
270+
if err != nil {
271+
if NeedRetry(err) {
272+
wait()
273+
return resource.RetryableError(err)
274+
}
275+
return resource.NonRetryableError(err)
276+
}
277+
return nil
278+
})
279+
addDebug(action, response, request)
280+
281+
if err != nil {
282+
if NotFoundError(err) {
283+
return nil
284+
}
285+
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
286+
}
287+
288+
}
289+
290+
enableDelete = false
291+
if v, ok := d.GetOk("category"); ok {
292+
if InArray(fmt.Sprint(v), []string{"ei"}) {
293+
enableDelete = true
294+
}
295+
}
296+
if enableDelete {
297+
client := meta.(*connectivity.AliyunClient)
298+
parts := strings.Split(d.Id(), ":")
299+
action := "DetachEaisEi"
300+
var request map[string]interface{}
301+
var response map[string]interface{}
302+
query := make(map[string]interface{})
303+
var err error
304+
request = make(map[string]interface{})
305+
request["EiInstanceId"] = parts[0]
306+
request["RegionId"] = client.RegionId
307+
308+
wait := incrementalWait(3*time.Second, 5*time.Second)
309+
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
310+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
311+
312+
if err != nil {
313+
if NeedRetry(err) {
314+
wait()
315+
return resource.RetryableError(err)
316+
}
317+
return resource.NonRetryableError(err)
318+
}
319+
return nil
320+
})
321+
addDebug(action, response, request)
322+
323+
if err != nil {
324+
if NotFoundError(err) {
325+
return nil
326+
}
327+
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
328+
}
329+
330+
}
331+
return nil
332+
}

‎alicloud/resource_alicloud_eais_client_instance_attachment_test.go

+436
Large diffs are not rendered by default.

‎alicloud/resource_alicloud_eais_instance.go

+418-75
Large diffs are not rendered by default.

‎alicloud/resource_alicloud_eais_instance_test.go

+177-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func TestAccAliCloudEaisInstance_basic0(t *testing.T) {
138138
"instance_type": "eais.ei-a6.2xlarge",
139139
"vswitch_id": "${alicloud_vswitch.default.id}",
140140
"security_group_id": "${alicloud_security_group.default.id}",
141+
"category": "eais",
141142
}),
142143
Check: resource.ComposeTestCheckFunc(
143144
testAccCheck(map[string]string{
@@ -151,7 +152,7 @@ func TestAccAliCloudEaisInstance_basic0(t *testing.T) {
151152
ResourceName: resourceId,
152153
ImportState: true,
153154
ImportStateVerify: true,
154-
ImportStateVerifyIgnore: []string{"force"},
155+
ImportStateVerifyIgnore: []string{"category"},
155156
},
156157
},
157158
})
@@ -430,3 +431,178 @@ func TestUnitAliCloudEaisInstance(t *testing.T) {
430431
}
431432

432433
}
434+
435+
// Test Eais Instance. >>> Resource test cases, automatically generated.
436+
// Case cc_jupyter_pro 10128
437+
func TestAccAliCloudEaisInstance_basic10128(t *testing.T) {
438+
var v map[string]interface{}
439+
resourceId := "alicloud_eais_instance.default"
440+
ra := resourceAttrInit(resourceId, AlicloudEaisInstanceMap10128)
441+
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} {
442+
return &EaisServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)}
443+
}, "DescribeEaisInstance")
444+
rac := resourceAttrCheckInit(rc, ra)
445+
testAccCheck := rac.resourceAttrMapUpdateSet()
446+
rand := acctest.RandIntRange(10000, 99999)
447+
name := fmt.Sprintf("tfacceais%d", rand)
448+
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudEaisInstanceBasicDependence10128)
449+
resource.Test(t, resource.TestCase{
450+
PreCheck: func() {
451+
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"})
452+
testAccPreCheck(t)
453+
},
454+
IDRefreshName: resourceId,
455+
Providers: testAccProviders,
456+
CheckDestroy: rac.checkResourceDestroy(),
457+
Steps: []resource.TestStep{
458+
{
459+
Config: testAccConfig(map[string]interface{}{
460+
"instance_name": name,
461+
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}",
462+
"security_group_id": "${alicloud_security_group.sg.id}",
463+
"vswitch_id": "${alicloud_vswitch.vsw.id}",
464+
"instance_type": "eais.ei-a6.2xlarge",
465+
"image": "registry-vpc.cn-hangzhou.aliyuncs.com/eai_beijing/eais-triton:v3.2.5-server",
466+
"environment_var": []map[string]interface{}{
467+
{
468+
"key": "testKey",
469+
"value": "testValue",
470+
},
471+
},
472+
"status": "InUse",
473+
"category": "jupyter",
474+
}),
475+
Check: resource.ComposeTestCheckFunc(
476+
testAccCheck(map[string]string{
477+
"instance_name": name,
478+
"resource_group_id": CHECKSET,
479+
"security_group_id": CHECKSET,
480+
"vswitch_id": CHECKSET,
481+
"instance_type": "eais.ei-a6.2xlarge",
482+
"environment_var.#": "1",
483+
"status": "InUse",
484+
}),
485+
),
486+
},
487+
{
488+
Config: testAccConfig(map[string]interface{}{
489+
"status": "Stopped",
490+
}),
491+
Check: resource.ComposeTestCheckFunc(
492+
testAccCheck(map[string]string{
493+
"status": "Stopped",
494+
}),
495+
),
496+
},
497+
{
498+
Config: testAccConfig(map[string]interface{}{
499+
"status": "InUse",
500+
}),
501+
Check: resource.ComposeTestCheckFunc(
502+
testAccCheck(map[string]string{
503+
"status": "InUse",
504+
}),
505+
),
506+
},
507+
{
508+
Config: testAccConfig(map[string]interface{}{
509+
"tags": map[string]string{
510+
"Created": "TF",
511+
"For": "Test",
512+
},
513+
"environment_var": []map[string]interface{}{
514+
{
515+
"key": "testKey-update",
516+
"value": "testValue-update",
517+
},
518+
},
519+
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.1}",
520+
}),
521+
Check: resource.ComposeTestCheckFunc(
522+
testAccCheck(map[string]string{
523+
"tags.%": "2",
524+
"tags.Created": "TF",
525+
"tags.For": "Test",
526+
}),
527+
),
528+
},
529+
{
530+
Config: testAccConfig(map[string]interface{}{
531+
"tags": map[string]string{
532+
"Created": "TF-update",
533+
"For": "Test-update",
534+
},
535+
}),
536+
Check: resource.ComposeTestCheckFunc(
537+
testAccCheck(map[string]string{
538+
"tags.%": "2",
539+
"tags.Created": "TF-update",
540+
"tags.For": "Test-update",
541+
}),
542+
),
543+
},
544+
{
545+
Config: testAccConfig(map[string]interface{}{
546+
"tags": REMOVEKEY,
547+
}),
548+
Check: resource.ComposeTestCheckFunc(
549+
testAccCheck(map[string]string{
550+
"tags.%": "0",
551+
"tags.Created": REMOVEKEY,
552+
"tags.For": REMOVEKEY,
553+
}),
554+
),
555+
},
556+
{
557+
ResourceName: resourceId,
558+
ImportState: true,
559+
ImportStateVerify: true,
560+
ImportStateVerifyIgnore: []string{"environment_var", "image", "category"},
561+
},
562+
},
563+
})
564+
}
565+
566+
var AlicloudEaisInstanceMap10128 = map[string]string{
567+
"create_time": CHECKSET,
568+
"region_id": "cn-hangzhou",
569+
}
570+
571+
func AlicloudEaisInstanceBasicDependence10128(name string) string {
572+
return fmt.Sprintf(`
573+
variable "name" {
574+
default = "%s"
575+
}
576+
577+
variable "zone" {
578+
default = "cn-hangzhou-i"
579+
}
580+
581+
variable "region" {
582+
default = "cn-hangzhou"
583+
}
584+
585+
data "alicloud_resource_manager_resource_groups" "default" {}
586+
587+
resource "alicloud_vpc" "vpc" {
588+
cidr_block = "172.16.0.0/12"
589+
vpc_name = var.name
590+
}
591+
592+
resource "alicloud_vswitch" "vsw" {
593+
vpc_id = alicloud_vpc.vpc.id
594+
cidr_block = "172.16.0.0/24"
595+
vswitch_name = alicloud_vpc.vpc.id
596+
zone_id = var.zone
597+
}
598+
599+
resource "alicloud_security_group" "sg" {
600+
security_group_name = alicloud_vpc.vpc.id
601+
vpc_id = alicloud_vpc.vpc.id
602+
}
603+
604+
605+
`, name)
606+
}
607+
608+
// Test Eais Instance. <<< Resource test cases, automatically generated.

‎alicloud/service_alicloud_eais_v2.go

+265
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
package alicloud
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
8+
"github.com/PaesslerAG/jsonpath"
9+
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
12+
)
13+
14+
type EaisServiceV2 struct {
15+
client *connectivity.AliyunClient
16+
}
17+
18+
// DescribeEaisClientInstanceAttachment <<< Encapsulated get interface for Eais ClientInstanceAttachment.
19+
20+
func (s *EaisServiceV2) DescribeEaisClientInstanceAttachment(id string) (object map[string]interface{}, err error) {
21+
client := s.client
22+
var request map[string]interface{}
23+
var response map[string]interface{}
24+
var query map[string]interface{}
25+
parts := strings.Split(id, ":")
26+
if len(parts) != 2 {
27+
err = WrapError(fmt.Errorf("invalid Resource Id %s. Expected parts' length %d, got %d", id, 2, len(parts)))
28+
}
29+
request = make(map[string]interface{})
30+
query = make(map[string]interface{})
31+
request["ElasticAcceleratedInstanceIds"] = expandSingletonToList(parts[0])
32+
request["RegionId"] = client.RegionId
33+
action := "DescribeEais"
34+
35+
wait := incrementalWait(3*time.Second, 5*time.Second)
36+
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
37+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
38+
39+
if err != nil {
40+
if NeedRetry(err) {
41+
wait()
42+
return resource.RetryableError(err)
43+
}
44+
return resource.NonRetryableError(err)
45+
}
46+
return nil
47+
})
48+
addDebug(action, response, request)
49+
if err != nil {
50+
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
51+
}
52+
53+
v, err := jsonpath.Get("$.Instances.Instance[*]", response)
54+
if err != nil {
55+
return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.Instances.Instance[*]", response)
56+
}
57+
58+
if len(v.([]interface{})) == 0 {
59+
return object, WrapErrorf(Error(GetNotFoundMessage("ClientInstanceAttachment", id)), NotFoundMsg, response)
60+
}
61+
62+
result, _ := v.([]interface{})
63+
for _, v := range result {
64+
item := v.(map[string]interface{})
65+
if fmt.Sprint(item["ClientInstanceId"]) != parts[1] {
66+
continue
67+
}
68+
return item, nil
69+
}
70+
return object, WrapErrorf(Error(GetNotFoundMessage("ClientInstanceAttachment", id)), NotFoundMsg, response)
71+
}
72+
73+
func (s *EaisServiceV2) EaisClientInstanceAttachmentStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc {
74+
return func() (interface{}, string, error) {
75+
object, err := s.DescribeEaisClientInstanceAttachment(id)
76+
if err != nil {
77+
if NotFoundError(err) {
78+
return object, "", nil
79+
}
80+
return nil, "", WrapError(err)
81+
}
82+
83+
v, err := jsonpath.Get(field, object)
84+
currentStatus := fmt.Sprint(v)
85+
86+
if strings.HasPrefix(field, "#") {
87+
v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object)
88+
if v != nil {
89+
currentStatus = "#CHECKSET"
90+
}
91+
}
92+
93+
for _, failState := range failStates {
94+
if currentStatus == failState {
95+
return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus))
96+
}
97+
}
98+
return object, currentStatus, nil
99+
}
100+
}
101+
102+
// DescribeEaisClientInstanceAttachment >>> Encapsulated.
103+
104+
// DescribeEaisInstance <<< Encapsulated get interface for Eais Instance.
105+
106+
func (s *EaisServiceV2) DescribeEaisInstance(id string) (object map[string]interface{}, err error) {
107+
client := s.client
108+
var request map[string]interface{}
109+
var response map[string]interface{}
110+
var query map[string]interface{}
111+
request = make(map[string]interface{})
112+
query = make(map[string]interface{})
113+
request["ElasticAcceleratedInstanceIds"] = convertObjectToJsonString(expandSingletonToList(id))
114+
request["RegionId"] = client.RegionId
115+
action := "DescribeEais"
116+
117+
wait := incrementalWait(3*time.Second, 5*time.Second)
118+
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
119+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
120+
121+
if err != nil {
122+
if NeedRetry(err) {
123+
wait()
124+
return resource.RetryableError(err)
125+
}
126+
return resource.NonRetryableError(err)
127+
}
128+
return nil
129+
})
130+
addDebug(action, response, request)
131+
if err != nil {
132+
if IsExpectedErrors(err, []string{"InvalidParameter.InstanceId.NotFound"}) {
133+
return object, WrapErrorf(Error(GetNotFoundMessage("Instance", id)), NotFoundMsg, response)
134+
}
135+
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
136+
}
137+
138+
v, err := jsonpath.Get("$.Instances.Instance[*]", response)
139+
if err != nil {
140+
return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.Instances.Instance[*]", response)
141+
}
142+
143+
if len(v.([]interface{})) == 0 {
144+
return object, WrapErrorf(Error(GetNotFoundMessage("Instance", id)), NotFoundMsg, response)
145+
}
146+
147+
return v.([]interface{})[0].(map[string]interface{}), nil
148+
}
149+
150+
func (s *EaisServiceV2) EaisInstanceStateRefreshFunc(id string, field string, failStates []string) resource.StateRefreshFunc {
151+
return func() (interface{}, string, error) {
152+
object, err := s.DescribeEaisInstance(id)
153+
if err != nil {
154+
if NotFoundError(err) {
155+
return object, "", nil
156+
}
157+
return nil, "", WrapError(err)
158+
}
159+
160+
v, err := jsonpath.Get(field, object)
161+
currentStatus := fmt.Sprint(v)
162+
163+
if strings.HasPrefix(field, "#") {
164+
v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object)
165+
if v != nil {
166+
currentStatus = "#CHECKSET"
167+
}
168+
}
169+
170+
for _, failState := range failStates {
171+
if currentStatus == failState {
172+
return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus))
173+
}
174+
}
175+
return object, currentStatus, nil
176+
}
177+
}
178+
179+
// DescribeEaisInstance >>> Encapsulated.
180+
181+
// SetResourceTags <<< Encapsulated tag function for Eais.
182+
func (s *EaisServiceV2) SetResourceTags(d *schema.ResourceData, resourceType string) error {
183+
if d.HasChange("tags") {
184+
var action string
185+
var err error
186+
client := s.client
187+
var request map[string]interface{}
188+
var response map[string]interface{}
189+
query := make(map[string]interface{})
190+
191+
added, removed := parsingTags(d)
192+
removedTagKeys := make([]string, 0)
193+
for _, v := range removed {
194+
if !ignoredTags(v, "") {
195+
removedTagKeys = append(removedTagKeys, v)
196+
}
197+
}
198+
if len(removedTagKeys) > 0 {
199+
action = "UntagResources"
200+
request = make(map[string]interface{})
201+
query = make(map[string]interface{})
202+
request["ResourceId.1"] = d.Id()
203+
request["RegionId"] = client.RegionId
204+
for i, key := range removedTagKeys {
205+
request[fmt.Sprintf("TagKey.%d", i+1)] = key
206+
}
207+
208+
request["ResourceType"] = resourceType
209+
wait := incrementalWait(3*time.Second, 5*time.Second)
210+
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
211+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
212+
if err != nil {
213+
if NeedRetry(err) {
214+
wait()
215+
return resource.RetryableError(err)
216+
}
217+
return resource.NonRetryableError(err)
218+
}
219+
return nil
220+
})
221+
addDebug(action, response, request)
222+
if err != nil {
223+
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
224+
}
225+
226+
}
227+
228+
if len(added) > 0 {
229+
action = "TagResources"
230+
request = make(map[string]interface{})
231+
query = make(map[string]interface{})
232+
request["ResourceId.1"] = d.Id()
233+
request["RegionId"] = client.RegionId
234+
count := 1
235+
for key, value := range added {
236+
request[fmt.Sprintf("Tag.%d.Key", count)] = key
237+
request[fmt.Sprintf("Tag.%d.Value", count)] = value
238+
count++
239+
}
240+
241+
request["ResourceType"] = resourceType
242+
wait := incrementalWait(3*time.Second, 5*time.Second)
243+
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
244+
response, err = client.RpcPost("eais", "2019-06-24", action, query, request, true)
245+
if err != nil {
246+
if NeedRetry(err) {
247+
wait()
248+
return resource.RetryableError(err)
249+
}
250+
return resource.NonRetryableError(err)
251+
}
252+
return nil
253+
})
254+
addDebug(action, response, request)
255+
if err != nil {
256+
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
257+
}
258+
259+
}
260+
}
261+
262+
return nil
263+
}
264+
265+
// SetResourceTags >>> tag function encapsulated.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
subcategory: "Elastic Accelerated Computing Instances (EAIS)"
3+
layout: "alicloud"
4+
page_title: "Alicloud: alicloud_eais_client_instance_attachment"
5+
description: |-
6+
Provides a Alicloud EAIS Client Instance Attachment resource.
7+
---
8+
9+
# alicloud_eais_client_instance_attachment
10+
11+
Provides a EAIS Client Instance Attachment resource.
12+
13+
Bind an ECS or ECI instance.
14+
15+
For information about EAIS Client Instance Attachment and how to use it, see [What is Client Instance Attachment](https://www.alibabacloud.com/help/en/resource-orchestration-service/latest/aliyun-eais-clientinstanceattachment).
16+
17+
-> **NOTE:** Available since v1.246.0.
18+
19+
## Example Usage
20+
21+
Basic Usage
22+
23+
```terraform
24+
variable "name" {
25+
default = "terraform-example"
26+
}
27+
28+
provider "alicloud" {
29+
region = "cn-hangzhou"
30+
}
31+
32+
variable "zone" {
33+
default = "cn-hangzhou-i"
34+
}
35+
36+
variable "ecs_image" {
37+
default = "ubuntu_20_04_x64_20G_alibase_20230316.vhd"
38+
}
39+
40+
variable "ecs_type" {
41+
default = "ecs.g7.large"
42+
}
43+
44+
variable "region" {
45+
default = "cn-hangzhou"
46+
}
47+
48+
variable "category" {
49+
default = "ei"
50+
}
51+
52+
data "alicloud_zones" "default" {
53+
available_resource_creation = "VSwitch"
54+
}
55+
56+
data "alicloud_instance_types" "example" {
57+
availability_zone = "cn-hangzhou-i"
58+
cpu_core_count = 1
59+
memory_size = 2
60+
}
61+
62+
data "alicloud_images" "example" {
63+
name_regex = "^ubuntu_18.*64"
64+
owners = "system"
65+
}
66+
67+
resource "alicloud_vpc" "example" {
68+
vpc_name = var.name
69+
cidr_block = "10.4.0.0/16"
70+
}
71+
72+
resource "alicloud_vswitch" "example" {
73+
vswitch_name = var.name
74+
cidr_block = "10.4.0.0/24"
75+
vpc_id = alicloud_vpc.example.id
76+
zone_id = "cn-hangzhou-i"
77+
}
78+
79+
resource "alicloud_security_group" "example" {
80+
security_group_name = var.name
81+
description = var.name
82+
vpc_id = alicloud_vpc.example.id
83+
}
84+
85+
resource "alicloud_instance" "example" {
86+
availability_zone = "cn-hangzhou-i"
87+
vswitch_id = alicloud_vswitch.example.id
88+
image_id = data.alicloud_images.example.images.0.id
89+
instance_type = data.alicloud_instance_types.example.instance_types.0.id
90+
system_disk_category = "cloud_efficiency"
91+
internet_charge_type = "PayByTraffic"
92+
internet_max_bandwidth_out = 5
93+
security_groups = [alicloud_security_group.example.id]
94+
instance_name = var.name
95+
user_data = "echo 'net.ipv4.ip_forward=1'>> /etc/sysctl.conf"
96+
}
97+
98+
resource "alicloud_eais_instance" "eais" {
99+
instance_name = var.name
100+
vswitch_id = alicloud_vswitch.example.id
101+
security_group_id = alicloud_security_group.example.id
102+
instance_type = "eais.ei-a6.2xlarge"
103+
category = "ei"
104+
}
105+
106+
107+
resource "alicloud_eais_client_instance_attachment" "default" {
108+
instance_id = alicloud_eais_instance.eais.id
109+
client_instance_id = alicloud_instance.example.id
110+
category = "ei"
111+
status = "Bound"
112+
ei_instance_type = "eais.ei-a6.2xlarge"
113+
}
114+
```
115+
116+
### Deleting `alicloud_eais_client_instance_attachment` or removing it from your configuration
117+
118+
The `alicloud_eais_client_instance_attachment` resource allows you to manage `category = "eais"` instance, but Terraform cannot destroy it.
119+
Deleting the subscription resource or removing it from your configuration will remove it from your state file and management, but will not destroy the Instance.
120+
You can resume managing the subscription instance via the AlibabaCloud Console.
121+
122+
## Argument Reference
123+
124+
The following arguments are supported:
125+
* `category` - (Optional) EAIS instance category, valid values: `eais`, `ei`, default is `eais`.
126+
* `client_instance_id` - (Required, ForceNew) The ID of the ECS or ECI instance bound to the EAIS instance.
127+
* `ei_instance_type` - (Optional, ForceNew) The Ei instance specification, which is used to filter matching specifications for updating.
128+
* `instance_id` - (Required, ForceNew) The EAIS instance ID.
129+
* `status` - (Optional, Computed) The status of the resource
130+
131+
## Attributes Reference
132+
133+
The following attributes are exported:
134+
* `id` - The ID of the resource supplied above.The value is formulated as `<instance_id>:<client_instance_id>`.
135+
* `create_time` - The creation time of the resource
136+
* `region_id` - The region ID of the resource
137+
138+
## Timeouts
139+
140+
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration-0-11/resources.html#timeouts) for certain actions:
141+
* `create` - (Defaults to 5 mins) Used when create the Client Instance Attachment.
142+
* `delete` - (Defaults to 5 mins) Used when delete the Client Instance Attachment.
143+
* `update` - (Defaults to 5 mins) Used when update the Client Instance Attachment.
144+
145+
## Import
146+
147+
EAIS Client Instance Attachment can be imported using the id, e.g.
148+
149+
```shell
150+
$ terraform import alicloud_eais_client_instance_attachment.example <instance_id>:<client_instance_id>
151+
```

‎website/docs/r/eais_instance.html.markdown

+34-24
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,24 @@
22
subcategory: "Elastic Accelerated Computing Instances (EAIS)"
33
layout: "alicloud"
44
page_title: "Alicloud: alicloud_eais_instance"
5-
sidebar_current: "docs-alicloud-resource-eais-instance"
65
description: |-
7-
Provides a Alicloud Elastic Accelerated Computing Instances (EAIS) Instance resource.
6+
Provides a Alicloud EAIS Instance resource.
87
---
98

109
# alicloud_eais_instance
1110

12-
Provides a Elastic Accelerated Computing Instances (EAIS) Instance resource.
11+
Provides a EAIS Instance resource.
1312

14-
For information about Elastic Accelerated Computing Instances (EAIS) Instance and how to use it, see [What is Instance](https://www.alibabacloud.com/help/en/resource-orchestration-service/latest/aliyun-eais-instance).
13+
Instance resource definition.
14+
15+
For information about EAIS Instance and how to use it, see [What is Instance](https://www.alibabacloud.com/help/en/resource-orchestration-service/latest/aliyun-eais-instance).
1516

1617
-> **NOTE:** Available since v1.137.0.
1718

1819
## Example Usage
1920

2021
Basic Usage
2122

22-
<div style="display: block;margin-bottom: 40px;"><div class="oics-button" style="float: right;position: absolute;margin-bottom: 10px;">
23-
<a href="https://api.aliyun.com/terraform?resource=alicloud_eais_instance&exampleId=b4b42fb3-673c-12f3-9a98-6cdf7e94e29fccb36fa6&activeTab=example&spm=docs.r.eais_instance.0.b4b42fb367&intl_lang=EN_US" target="_blank">
24-
<img alt="Open in AliCloud" src="https://img.alicdn.com/imgextra/i1/O1CN01hjjqXv1uYUlY56FyX_!!6000000006049-55-tps-254-36.svg" style="max-height: 44px; max-width: 100%;">
25-
</a>
26-
</div></div>
27-
2823
```terraform
2924
variable "name" {
3025
default = "terraform-example"
@@ -63,36 +58,51 @@ resource "alicloud_eais_instance" "default" {
6358
}
6459
```
6560

61+
### Deleting `alicloud_eais_instance` or removing it from your configuration
62+
63+
The `alicloud_eais_instance` resource allows you to manage `category = "ei"` instance, but Terraform cannot destroy it.
64+
Deleting the subscription resource or removing it from your configuration will remove it from your state file and management, but will not destroy the Instance.
65+
You can resume managing the subscription instance via the AlibabaCloud Console.
66+
6667
## Argument Reference
6768

6869
The following arguments are supported:
69-
70-
* `instance_type` - (Required, ForceNew) The type of the Instance. Valid values: `eais.ei-a6.4xlarge`, `eais.ei-a6.2xlarge`, `eais.ei-a6.xlarge`, `eais.ei-a6.large`, `eais.ei-a6.medium`.
71-
* `vswitch_id` - (Required, ForceNew) The ID of the vSwitch.
72-
* `security_group_id` - (Required, ForceNew) The ID of the security group.
73-
* `instance_name` - (Optional, ForceNew) The name of the Instance.
74-
* `force` - (Optional, Bool) Specifies whether to force delete the Instance. Default value: `false`. Valid values:
75-
- `true`: Enable.
76-
- `false`: Disable.
70+
* `category` - (Optional) EAIS instance category, valid values: `eais`, `jupyter`, `ei`, default is `eais`.
71+
* `environment_var` - (Optional, List, Available since v1.246.0) Setting environment variables in eais instance on Initialization See [`environment_var`](#environment_var) below.
72+
* `force` - (Optional, Deprecated since v1.246.0) Whether to force the deletion when the instance status does not meet the deletion conditions.
73+
* `image` - (Optional, Available since v1.246.0) EAIS instance image.
74+
* `instance_name` - (Optional, ForceNew) Name of the instance
75+
* `instance_type` - (Required, ForceNew) EAIS instance type
76+
* `resource_group_id` - (Optional, Computed, Available since v1.246.0) The ID of the resource group
77+
* `security_group_id` - (Required, ForceNew) Security group ID
78+
* `status` - (Optional, Computed) The status of the resource
79+
* `tags` - (Optional, Map, Available since v1.246.0) The tags.
80+
* `vswitch_id` - (Required, ForceNew) Switch ID.
81+
82+
### `environment_var`
83+
84+
The environment_var supports the following:
85+
* `key` - (Optional, Available since v1.246.0) Keys for environment variables
86+
* `value` - (Optional, Available since v1.246.0) Values of environment variables
7787

7888
## Attributes Reference
7989

8090
The following attributes are exported:
81-
82-
* `id` - The resource ID in terraform of Instance.
83-
* `status` - The status of the Instance.
91+
* `id` - The ID of the resource supplied above.
92+
* `create_time` - The creation time of the resource
93+
* `region_id` - Region ID
8494

8595
## Timeouts
8696

8797
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration-0-11/resources.html#timeouts) for certain actions:
88-
8998
* `create` - (Defaults to 5 mins) Used when create the Instance.
9099
* `delete` - (Defaults to 5 mins) Used when delete the Instance.
100+
* `update` - (Defaults to 5 mins) Used when update the Instance.
91101

92102
## Import
93103

94-
Elastic Accelerated Computing Instances (EAIS) Instance can be imported using the id, e.g.
104+
EAIS Instance can be imported using the id, e.g.
95105

96106
```shell
97107
$ terraform import alicloud_eais_instance.example <id>
98-
```
108+
```

0 commit comments

Comments
 (0)
Please sign in to comment.