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

ResourceCenter: Improves the invoking resource center api method and supports refreshing credential automatically #8011

Merged
merged 1 commit into from
Dec 23, 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
31 changes: 6 additions & 25 deletions alicloud/resource_alicloud_resource_manager_saved_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"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"
Expand Down Expand Up @@ -54,24 +53,18 @@ func resourceAliCloudResourceManagerSavedQueryCreate(d *schema.ResourceData, met
action := "CreateSavedQuery"
var request map[string]interface{}
var response map[string]interface{}
var err error
query := make(map[string]interface{})
conn, err := client.NewResourceCenterClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})

request["Expression"] = d.Get("expression")
if v, ok := d.GetOk("description"); ok {
request["Description"] = v
}
request["Name"] = d.Get("saved_query_name")
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(action), nil, StringPointer("POST"), StringPointer("2022-12-01"), StringPointer("AK"), query, request, &runtime)

response, err = client.RpcPost("ResourceCenter", "2022-12-01", action, query, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -118,13 +111,10 @@ func resourceAliCloudResourceManagerSavedQueryUpdate(d *schema.ResourceData, met
client := meta.(*connectivity.AliyunClient)
var request map[string]interface{}
var response map[string]interface{}
var err error
var query map[string]interface{}
update := false
action := "UpdateSavedQuery"
conn, err := client.NewResourceCenterClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
query = make(map[string]interface{})
query["QueryId"] = d.Id()
Expand All @@ -142,12 +132,9 @@ func resourceAliCloudResourceManagerSavedQueryUpdate(d *schema.ResourceData, met
}
request["Name"] = d.Get("saved_query_name")
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(action), nil, StringPointer("POST"), StringPointer("2022-12-01"), StringPointer("AK"), query, request, &runtime)

response, err = client.RpcPost("ResourceCenter", "2022-12-01", action, query, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand All @@ -172,19 +159,13 @@ func resourceAliCloudResourceManagerSavedQueryDelete(d *schema.ResourceData, met
action := "DeleteSavedQuery"
var request map[string]interface{}
var response map[string]interface{}
var err error
query := make(map[string]interface{})
conn, err := client.NewResourceCenterClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
query["QueryId"] = d.Id()

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2022-12-01"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("ResourceCenter", "2022-12-01", action, query, request, false)

if err != nil {
if NeedRetry(err) {
Expand Down
10 changes: 1 addition & 9 deletions alicloud/service_alicloud_resource_manager_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)
Expand All @@ -22,20 +21,13 @@ func (s *ResourceManagerServiceV2) DescribeResourceManagerSavedQuery(id string)
var response map[string]interface{}
var query map[string]interface{}
action := "GetSavedQuery"
conn, err := client.NewResourceCenterClient()
if err != nil {
return object, WrapError(err)
}
request = make(map[string]interface{})
query = make(map[string]interface{})
query["QueryId"] = id

runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(1*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2022-12-01"), StringPointer("AK"), query, request, &runtime)

response, err = client.RpcPost("ResourceCenter", "2022-12-01", action, query, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
Loading