-
Notifications
You must be signed in to change notification settings - Fork 562
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_cloud_monitor_service_enterprise_public; New R…
…esource: alicloud_cloud_monitor_service_basic_public.
- Loading branch information
1 parent
ad44fd4
commit cb5722d
Showing
9 changed files
with
870 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
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
161 changes: 161 additions & 0 deletions
161
alicloud/resource_alicloud_cloud_monitor_service_basic_public.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,161 @@ | ||
// Package alicloud. This file is generated automatically. Please do not modify it manually, thank you! | ||
package alicloud | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
"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" | ||
) | ||
|
||
func resourceAliCloudCloudMonitorServiceBasicPublic() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAliCloudCloudMonitorServiceBasicPublicCreate, | ||
Read: resourceAliCloudCloudMonitorServiceBasicPublicRead, | ||
Delete: resourceAliCloudCloudMonitorServiceBasicPublicDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(5 * time.Minute), | ||
Delete: schema.DefaultTimeout(5 * time.Minute), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"create_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAliCloudCloudMonitorServiceBasicPublicCreate(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*connectivity.AliyunClient) | ||
|
||
action := "CreateInstance" | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
query := make(map[string]interface{}) | ||
conn, err := client.NewBssopenapiClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
|
||
request["ClientToken"] = buildClientToken(action) | ||
|
||
request["ProductCode"] = "cms" | ||
request["ProductType"] = "cms_basic_public_cn" | ||
request["SubscriptionType"] = "PayAsYouGo" | ||
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("2017-12-14"), StringPointer("AK"), query, request, &runtime) | ||
request["ClientToken"] = buildClientToken(action) | ||
|
||
if err != nil { | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
addDebug(action, response, request) | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, "alicloud_cloud_monitor_service_basic_public", action, AlibabaCloudSdkGoERROR) | ||
} | ||
if response["Code"] == "Has.effect.suit" { | ||
parts := strings.Split(response["Message"].(string), ": ") | ||
if len(parts) < 2 { | ||
return WrapErrorf(err, ResponseCodeMsg, "alicloud_cloud_monitor_service_basic_public", action, response) | ||
} | ||
d.SetId(parts[1]) | ||
return resourceAliCloudCloudMonitorServiceBasicPublicRead(d, meta) | ||
} | ||
|
||
id, _ := jsonpath.Get("$.Data.InstanceId", response) | ||
d.SetId(fmt.Sprint(id)) | ||
|
||
return resourceAliCloudCloudMonitorServiceBasicPublicRead(d, meta) | ||
} | ||
|
||
func resourceAliCloudCloudMonitorServiceBasicPublicRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*connectivity.AliyunClient) | ||
cloudMonitorServiceServiceV2 := CloudMonitorServiceServiceV2{client} | ||
|
||
objectRaw, err := cloudMonitorServiceServiceV2.DescribeCloudMonitorServiceBasicPublic(d.Id()) | ||
if err != nil { | ||
if !d.IsNewResource() && NotFoundError(err) { | ||
log.Printf("[DEBUG] Resource alicloud_cloud_monitor_service_basic_public DescribeCloudMonitorServiceBasicPublic Failed!!! %s", err) | ||
d.SetId("") | ||
return nil | ||
} | ||
return WrapError(err) | ||
} | ||
|
||
d.Set("create_time", objectRaw["CreateTime"]) | ||
|
||
return nil | ||
} | ||
|
||
func resourceAliCloudCloudMonitorServiceBasicPublicDelete(d *schema.ResourceData, meta interface{}) error { | ||
|
||
client := meta.(*connectivity.AliyunClient) | ||
action := "StopPostPayQuota" | ||
var request map[string]interface{} | ||
var response map[string]interface{} | ||
query := make(map[string]interface{}) | ||
conn, err := client.NewCloudmonitorserviceClient() | ||
if err != nil { | ||
return WrapError(err) | ||
} | ||
request = make(map[string]interface{}) | ||
query["InstanceId"] = d.Id() | ||
request["PostType"] = "postPayV2" | ||
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("2019-01-01"), StringPointer("AK"), query, request, &runtime) | ||
|
||
if err != nil { | ||
if NeedRetry(err) { | ||
wait() | ||
return resource.RetryableError(err) | ||
} | ||
return resource.NonRetryableError(err) | ||
} | ||
addDebug(action, response, request) | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR) | ||
} | ||
|
||
cloudMonitorServiceServiceV2 := CloudMonitorServiceServiceV2{client} | ||
stateConf := BuildStateConf([]string{}, []string{}, d.Timeout(schema.TimeoutDelete), 5*time.Second, cloudMonitorServiceServiceV2.CloudMonitorServiceBasicPublicStateRefreshFunc(d.Id(), "InstanceID", []string{})) | ||
if _, err := stateConf.WaitForState(); err != nil { | ||
return WrapErrorf(err, IdMsg, d.Id()) | ||
} | ||
return nil | ||
} | ||
|
||
func convertCloudMonitorServicePostTypeRequest(source interface{}) interface{} { | ||
switch source { | ||
case "cms_basic_public_cn": | ||
return "postPayV2" | ||
} | ||
return source | ||
} |
64 changes: 64 additions & 0 deletions
64
alicloud/resource_alicloud_cloud_monitor_service_basic_public_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,64 @@ | ||
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 CloudMonitorService BasicPublic. >>> Resource test cases, automatically generated. | ||
// Case 5537 | ||
func TestAccAliCloudCloudMonitorServiceBasicPublic_basic5537(t *testing.T) { | ||
var v map[string]interface{} | ||
resourceId := "alicloud_cloud_monitor_service_basic_public.default" | ||
ra := resourceAttrInit(resourceId, AlicloudCloudMonitorServiceBasicPublicMap5537) | ||
rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { | ||
return &CloudMonitorServiceServiceV2{testAccProvider.Meta().(*connectivity.AliyunClient)} | ||
}, "DescribeCloudMonitorServiceBasicPublic") | ||
rac := resourceAttrCheckInit(rc, ra) | ||
testAccCheck := rac.resourceAttrMapUpdateSet() | ||
rand := acctest.RandIntRange(10000, 99999) | ||
name := fmt.Sprintf("tf-testacc%scloudmonitorservicebasicpublic%d", defaultRegionToTest, rand) | ||
testAccConfig := resourceTestAccConfigFunc(resourceId, name, AlicloudCloudMonitorServiceBasicPublicBasicDependence5537) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
IDRefreshName: resourceId, | ||
Providers: testAccProviders, | ||
CheckDestroy: rac.checkResourceDestroy(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccConfig(map[string]interface{}{}), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheck(map[string]string{}), | ||
), | ||
}, | ||
{ | ||
ResourceName: resourceId, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var AlicloudCloudMonitorServiceBasicPublicMap5537 = map[string]string{ | ||
"create_time": CHECKSET, | ||
} | ||
|
||
func AlicloudCloudMonitorServiceBasicPublicBasicDependence5537(name string) string { | ||
return fmt.Sprintf(` | ||
variable "name" { | ||
default = "%s" | ||
} | ||
`, name) | ||
} | ||
|
||
// Test CloudMonitorService BasicPublic. <<< Resource test cases, automatically generated. |
Oops, something went wrong.