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

Goverance: Improves the invoking goverance api method and supports refreshing credential automatically #8005

Merged
merged 1 commit into from
Dec 20, 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
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_governance_baselines.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -71,18 +70,13 @@ func dataSourceAliCloudGovernanceBaselineRead(d *schema.ResourceData, meta inter
var response map[string]interface{}
var query map[string]interface{}
action := "ListAccountFactoryBaselines"
conn, err := client.NewGovernanceClient()
if err != nil {
return WrapError(err)
}
var err error
request = make(map[string]interface{})
query = make(map[string]interface{})
query["RegionId"] = client.RegionId
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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, true)

if err != nil {
if NeedRetry(err) {
Expand Down
19 changes: 4 additions & 15 deletions alicloud/resource_alicloud_governance_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -93,10 +92,7 @@ func resourceAliCloudGovernanceAccountCreate(d *schema.ResourceData, meta interf
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewGovernanceClient()
if err != nil {
return WrapError(err)
}
var err error
request = make(map[string]interface{})
if v, ok := d.GetOk("account_id"); ok {
request["AccountUid"] = v
Expand Down Expand Up @@ -143,11 +139,9 @@ func resourceAliCloudGovernanceAccountCreate(d *schema.ResourceData, meta interf
baselineItemsMaps = append(baselineItemsMaps, baselineItem)
}
request["BaselineItems"] = baselineItemsMaps
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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -229,10 +223,7 @@ func resourceAliCloudGovernanceAccountUpdate(d *schema.ResourceData, meta interf
update := false

action := "EnrollAccount"
conn, err := client.NewGovernanceClient()
if err != nil {
return WrapError(err)
}
var err error
request = make(map[string]interface{})
query = make(map[string]interface{})
request["AccountUid"] = d.Id()
Expand Down Expand Up @@ -262,11 +253,9 @@ func resourceAliCloudGovernanceAccountUpdate(d *schema.ResourceData, meta interf
request["BaselineId"] = d.Get("baseline_id")

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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
28 changes: 6 additions & 22 deletions alicloud/resource_alicloud_governance_baseline.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 @@ -69,10 +68,7 @@ func resourceAliCloudGovernanceBaselineCreate(d *schema.ResourceData, meta inter
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewGovernanceClient()
if err != nil {
return WrapError(err)
}
var err error
request = make(map[string]interface{})
query["RegionId"] = client.RegionId

Expand All @@ -95,11 +91,9 @@ func resourceAliCloudGovernanceBaselineCreate(d *schema.ResourceData, meta inter
if v, ok := d.GetOk("description"); ok {
request["Description"] = v
}
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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -170,10 +164,7 @@ func resourceAliCloudGovernanceBaselineUpdate(d *schema.ResourceData, meta inter
var query map[string]interface{}
update := false
action := "UpdateAccountFactoryBaseline"
conn, err := client.NewGovernanceClient()
if err != nil {
return WrapError(err)
}
var err error
request = make(map[string]interface{})
query = make(map[string]interface{})
query["BaselineId"] = d.Id()
Expand Down Expand Up @@ -205,11 +196,9 @@ func resourceAliCloudGovernanceBaselineUpdate(d *schema.ResourceData, meta inter
}

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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand All @@ -235,19 +224,14 @@ func resourceAliCloudGovernanceBaselineDelete(d *schema.ResourceData, meta inter
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewGovernanceClient()
if err != nil {
return WrapError(err)
}
var err error
request = make(map[string]interface{})
query["BaselineId"] = d.Id()
query["RegionId"] = client.RegionId

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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, false)

if err != nil {
if NeedRetry(err) {
Expand Down
17 changes: 2 additions & 15 deletions alicloud/service_alicloud_governance_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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 @@ -23,20 +22,14 @@ func (s *GovernanceServiceV2) DescribeGovernanceBaseline(id string) (object map[
var response map[string]interface{}
var query map[string]interface{}
action := "GetAccountFactoryBaseline"
conn, err := client.NewGovernanceClient()
if err != nil {
return object, WrapError(err)
}
request = make(map[string]interface{})
query = make(map[string]interface{})
query["BaselineId"] = id
query["RegionId"] = client.RegionId

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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, true)

if err != nil {
if NeedRetry(err) {
Expand Down Expand Up @@ -91,20 +84,14 @@ func (s *GovernanceServiceV2) DescribeGovernanceAccount(id string) (object map[s
var response map[string]interface{}
var query map[string]interface{}
action := "GetEnrolledAccount"
conn, err := client.NewGovernanceClient()
if err != nil {
return object, WrapError(err)
}
request = make(map[string]interface{})
query = make(map[string]interface{})
request["AccountUid"] = id
request["RegionId"] = client.RegionId

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("2021-01-20"), StringPointer("AK"), query, request, &runtime)
response, err = client.RpcPost("governance", "2021-01-20", action, query, request, true)

if err != nil {
if NeedRetry(err) {
Expand Down
Loading