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

MscOpenSubscription: Improves the invoking MscOpenSubscription api method and supports refreshing credential automatically #8010

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/validation"

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 @@ -41,18 +40,13 @@ func dataSourceAlicloudMscSubContactVerificationMessageRead(d *schema.ResourceDa
action := "SendVerificationMessage"
var response map[string]interface{}
request := make(map[string]interface{})
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
request["ContactId"] = d.Get("contact_id")
request["Type"] = d.Get("type")
request["Locale"] = "en"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2021-07-13"), StringPointer("AK"), request, nil, &runtime)
response, err = client.RpcGet("MscOpenSubscription", "2021-07-13", action, request, nil)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_msc_sub_contacts.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"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -130,16 +129,11 @@ func dataSourceAlicloudMscSubContactsRead(d *schema.ResourceData, meta interface
}
}
var response map[string]interface{}
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2021-07-13"), StringPointer("AK"), request, nil, &runtime)
response, err = client.RpcGet("MscOpenSubscription", "2021-07-13", action, request, nil)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_msc_sub_subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"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 @@ -95,16 +94,11 @@ func dataSourceAlicloudMscSubSubscriptionsRead(d *schema.ResourceData, meta inte
request["MaxResults"] = PageSizeLarge
var objects []map[string]interface{}
var response map[string]interface{}
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2021-07-13"), StringPointer("AK"), request, nil, &runtime)
response, err = client.RpcGet("MscOpenSubscription", "2021-07-13", action, request, nil)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
10 changes: 2 additions & 8 deletions alicloud/data_source_alicloud_msc_sub_webhooks.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"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -94,16 +93,11 @@ func dataSourceAlicloudMscSubWebhooksRead(d *schema.ResourceData, meta interface
}
}
var response map[string]interface{}
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
for {
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("GET"), StringPointer("2021-07-13"), StringPointer("AK"), request, nil, &runtime)
response, err = client.RpcGet("MscOpenSubscription", "2021-07-13", action, request, nil)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
35 changes: 9 additions & 26 deletions alicloud/resource_alicloud_msc_sub_contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"regexp"
"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 @@ -51,32 +50,26 @@ func resourceAlicloudMscSubContact() *schema.Resource {
func resourceAlicloudMscSubContactCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
request := make(map[string]interface{})
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
request["ContactName"] = d.Get("contact_name")
request["Email"] = d.Get("email")
request["Mobile"] = d.Get("mobile")
request["Position"] = d.Get("position")
request["ClientToken"] = buildClientToken("CreateContact")
request["Locale"] = "en"
var response map[string]interface{}
var err error
action := "CreateContact"
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2021-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("MscOpenSubscription", "2021-07-13", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, resp, request)
addDebug(action, response, request)
return nil
})
if err != nil {
Expand Down Expand Up @@ -111,10 +104,7 @@ func resourceAlicloudMscSubContactRead(d *schema.ResourceData, meta interface{})
func resourceAlicloudMscSubContactUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var response map[string]interface{}
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error

update := false
request := map[string]interface{}{
Expand All @@ -135,20 +125,17 @@ func resourceAlicloudMscSubContactUpdate(d *schema.ResourceData, meta interface{
if update {
action := "UpdateContact"
request["ClientToken"] = buildClientToken("UpdateContact")
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2021-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("MscOpenSubscription", "2021-07-13", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, resp, request)
addDebug(action, response, request)
return nil
})
if err != nil {
Expand All @@ -163,27 +150,23 @@ func resourceAlicloudMscSubContactUpdate(d *schema.ResourceData, meta interface{
func resourceAlicloudMscSubContactDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var response map[string]interface{}
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
request := map[string]interface{}{
"ContactId": d.Id(),
}

action := "DeleteContact"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2021-07-13"), StringPointer("AK"), nil, request, &util.RuntimeOptions{})
response, err = client.RpcPost("MscOpenSubscription", "2021-07-13", action, nil, request, false)
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, resp, request)
addDebug(action, response, request)
return nil
})
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions alicloud/resource_alicloud_msc_sub_contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
)

func TestAccAlicloudMscSubContact_basic0(t *testing.T) {
checkoutSupportedRegions(t, true, connectivity.MSCSupportRegions)
var v map[string]interface{}
resourceId := "alicloud_msc_sub_contact.default"
ra := resourceAttrInit(resourceId, AlicloudMscSubContactMap0)
Expand Down Expand Up @@ -118,7 +117,6 @@ variable "name" {
}

func TestAccAlicloudMscSubContact_basic1(t *testing.T) {
checkoutSupportedRegions(t, true, connectivity.MSCSupportRegions)
var v map[string]interface{}
resourceId := "alicloud_msc_sub_contact.default"
ra := resourceAttrInit(resourceId, AlicloudMscSubContactMap1)
Expand Down
17 changes: 4 additions & 13 deletions alicloud/resource_alicloud_msc_sub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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 @@ -80,15 +79,12 @@ func resourceAlicloudMscSubSubscriptionCreate(d *schema.ResourceData, meta inter
var response map[string]interface{}
action := "CreateSubscriptionItem"
request := make(map[string]interface{})
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
request["ItemName"] = d.Get("item_name")
request["Locale"] = "en"
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2021-07-13"), StringPointer("AK"), nil, request, &util.RuntimeOptions{})
response, err = client.RpcPost("MscOpenSubscription", "2021-07-13", action, nil, request, false)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down Expand Up @@ -159,10 +155,7 @@ func resourceAlicloudMscSubSubscriptionRead(d *schema.ResourceData, meta interfa
func resourceAlicloudMscSubSubscriptionUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
var response map[string]interface{}
conn, err := client.NewMscopensubscriptionClient()
if err != nil {
return WrapError(err)
}
var err error
update := false
request := map[string]interface{}{
"ItemId": d.Id(),
Expand Down Expand Up @@ -215,11 +208,9 @@ func resourceAlicloudMscSubSubscriptionUpdate(d *schema.ResourceData, meta inter
if update {
action := "UpdateSubscriptionItem"
request["ClientToken"] = buildClientToken("UpdateSubscriptionItem")
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2021-07-13"), StringPointer("AK"), nil, request, &runtime)
response, err = client.RpcPost("MscOpenSubscription", "2021-07-13", action, nil, request, true)
if err != nil {
if NeedRetry(err) {
wait()
Expand Down
1 change: 0 additions & 1 deletion alicloud/resource_alicloud_msc_sub_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
)

func TestAccAlicloudMscSubSubscription_basic0(t *testing.T) {
checkoutSupportedRegions(t, true, connectivity.MSCSupportRegions)
var v map[string]interface{}
resourceId := "alicloud_msc_sub_subscription.default"
ra := resourceAttrInit(resourceId, AlicloudMscSubSubscriptionMap0)
Expand Down
Loading
Loading