-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource: alicloud_pai_workspace_default_workspace.
- Loading branch information
1 parent
3c4b46d
commit 14e3994
Showing
5 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
alicloud/resource_alicloud_pai_workspace_default_workspace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! | ||
package alicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
util "github.com/alibabacloud-go/tea-utils/service" | ||
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceAliCloudPaiWorkspaceDefaultWorkspace() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAliCloudPaiWorkspaceDefaultWorkspaceCreate, | ||
Read: resourceAliCloudPaiWorkspaceDefaultWorkspaceRead, | ||
Update: resourceAliCloudPaiWorkspaceDefaultWorkspaceUpdate, | ||
Delete: resourceAliCloudPaiWorkspaceDefaultWorkspaceDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(5 * time.Minute), | ||
Update: schema.DefaultTimeout(5 * time.Minute), | ||
Delete: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"description": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"env_types": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"workspace_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAliCloudPaiWorkspaceDefaultWorkspaceCreate(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*connectivity.AliyunClient) | ||
|
||
action := fmt.Sprintf("/api/v1/defaultWorkspaces") | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
query := make(map[string]*string) | ||
body := make(map[string]interface{}) | ||
conn, err := client.NewPaiworkspaceClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
|
||
request["Description"] = d.Get("description") | ||
if v, ok := d.GetOk("env_types"); ok { | ||
envTypesMapsArray := v.([]interface{}) | ||
request["EnvTypes"] = envTypesMapsArray | ||
} | ||
|
||
body = request | ||
runtime := util.RuntimeOptions{} | ||
runtime.SetAutoretry(true) | ||
wait := incrementalWait(3*time.Second, 5*time.Second) | ||
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError { | ||
response, err = conn.DoRequest(StringPointer("2021-02-04"), nil, StringPointer("POST"), StringPointer("AK"), StringPointer(action), query, nil, body, &runtime) | ||
if err != nil { | ||
if IsExpectedErrors(err, []string{"100400009"}) { | ||
return nil | ||
} | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
return nil | ||
}) | ||
addDebug(action, response, request) | ||
|
||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, "alicloud_pai_workspace_default_workspace", action, AlibabaCloudSdkGoERROR) | ||
} | ||
|
||
accountId, err := client.AccountId() | ||
d.SetId(accountId) | ||
|
||
return resourceAliCloudPaiWorkspaceDefaultWorkspaceUpdate(d, meta) | ||
} | ||
|
||
func resourceAliCloudPaiWorkspaceDefaultWorkspaceRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
paiWorkspaceServiceV2 := PaiWorkspaceServiceV2{client} | ||
|
||
objectRaw, err := paiWorkspaceServiceV2.DescribePaiWorkspaceDefaultWorkspace(d.Id()) | ||
if err != nil { | ||
if !d.IsNewResource() && NotFoundError(err) { | ||
log.Printf("[DEBUG] Resource alicloud_pai_workspace_default_workspace DescribePaiWorkspaceDefaultWorkspace Failed!!! %s", err) | ||
d.SetId("") | ||
return nil | ||
} | ||
return WrapError(err) | ||
} | ||
|
||
if objectRaw["Description"] != nil { | ||
d.Set("description", objectRaw["Description"]) | ||
} | ||
if objectRaw["Status"] != nil { | ||
d.Set("status", objectRaw["Status"]) | ||
} | ||
if objectRaw["WorkspaceId"] != nil { | ||
d.Set("workspace_id", objectRaw["WorkspaceId"]) | ||
} | ||
|
||
envTypes1Raw := make([]interface{}, 0) | ||
if objectRaw["EnvTypes"] != nil { | ||
envTypes1Raw = objectRaw["EnvTypes"].([]interface{}) | ||
} | ||
|
||
d.Set("env_types", envTypes1Raw) | ||
|
||
return nil | ||
} | ||
|
||
func resourceAliCloudPaiWorkspaceDefaultWorkspaceUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
var query map[string]*string | ||
var body map[string]interface{} | ||
update := false | ||
|
||
action := fmt.Sprintf("/api/v1/defaultWorkspaces") | ||
conn, err := client.NewPaiworkspaceClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
query = make(map[string]*string) | ||
body = make(map[string]interface{}) | ||
|
||
if d.HasChange("workspace_id") { | ||
update = true | ||
} | ||
if v, ok := d.GetOk("workspace_id"); ok || d.HasChange("workspace_id") { | ||
request["WorkspaceId"] = v | ||
} | ||
body = request | ||
if update { | ||
runtime := util.RuntimeOptions{} | ||
runtime.SetAutoretry(true) | ||
wait := incrementalWait(3*time.Second, 5*time.Second) | ||
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { | ||
response, err = conn.DoRequest(StringPointer("2021-02-04"), nil, StringPointer("PUT"), StringPointer("AK"), StringPointer(action), query, nil, body, &runtime) | ||
if err != nil { | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
return nil | ||
}) | ||
addDebug(action, response, request) | ||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) | ||
} | ||
} | ||
|
||
return resourceAliCloudPaiWorkspaceDefaultWorkspaceRead(d, meta) | ||
} | ||
|
||
func resourceAliCloudPaiWorkspaceDefaultWorkspaceDelete(d *schema.ResourceData, meta interface{}) error { | ||
log.Printf("[WARN] Cannot destroy resource AliCloud Resource Default Workspace. Terraform will remove this resource from the state file, however resources may remain.") | ||
return nil | ||
} |
105 changes: 105 additions & 0 deletions
105
alicloud/resource_alicloud_pai_workspace_default_workspace_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package alicloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
// Test PaiWorkspace DefaultWorkspace. >>> Resource test cases, automatically generated. | ||
// Case DefaultWorkspace 用例测试01 6819 | ||
func TestAccAliCloudPaiWorkspaceDefaultWorkspace_basic6819(t *testing.T) { | ||
var v map[string]interface{} | ||
resourceId := "alicloud_pai_workspace_default_workspace.default" | ||
ra := resourceAttrInit(resourceId, AlicloudPaiWorkspaceDefaultWorkspaceMap6819) | ||
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { | ||
return &PaiWorkspaceServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} | ||
}, "DescribePaiWorkspaceDefaultWorkspace") | ||
rac := resourceAttrCheckInit(rc, ra) | ||
testAccCheck := rac.resourceAttrMapUpdateSet() | ||
rand := acctest.RandIntRange(1, 999) | ||
name := fmt.Sprintf("tf_testacc%d", rand) | ||
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudPaiWorkspaceDefaultWorkspaceBasicDependence6819) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheckWithRegions(t, true, []connectivity.Region{"cn-hangzhou"}) | ||
testAccPreCheck(t) | ||
}, | ||
IDRefreshName: resourceId, | ||
Providers: testAccProviders, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccConfig(map[string]interface{}{ | ||
"description": "it", | ||
"env_types": []string{ | ||
"prod"}, | ||
}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheck(map[string]string{ | ||
"description": "defaultWorkspace", | ||
"env_types.#": "1", | ||
}), | ||
), | ||
}, | ||
{ | ||
Config: testAccConfig(map[string]interface{}{ | ||
"workspace_id": "${alicloud_pai_workspace_workspace.changeWorkspace.id}", | ||
}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheck(map[string]string{ | ||
"workspace_id": CHECKSET, | ||
}), | ||
), | ||
}, | ||
{ | ||
Config: testAccConfig(map[string]interface{}{ | ||
"workspace_id": "${alicloud_pai_workspace_workspace.changeWorkspace.id}", | ||
}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheck(map[string]string{ | ||
"workspace_id": CHECKSET, | ||
}), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceId, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var AlicloudPaiWorkspaceDefaultWorkspaceMap6819 = map[string]string{ | ||
"status": CHECKSET, | ||
} | ||
|
||
func AlicloudPaiWorkspaceDefaultWorkspaceBasicDependence6819(name string) string { | ||
return fmt.Sprintf(` | ||
variable "name" { | ||
default = "%s" | ||
} | ||
resource "alicloud_pai_workspace_workspace" "defaultWorkspace" { | ||
description = "dataset_pop_test_535" | ||
display_name = "DatasetResouceTest_16" | ||
workspace_name = var.name | ||
env_types = ["prod"] | ||
} | ||
resource "alicloud_pai_workspace_workspace" "changeWorkspace" { | ||
description = "dataset_pop_test_185" | ||
display_name = "DatasetResouceTest_146" | ||
workspace_name = var.name | ||
env_types = ["prod"] | ||
} | ||
`, name) | ||
} | ||
|
||
// Test PaiWorkspace DefaultWorkspace. <<< Resource test cases, automatically generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.