-
Notifications
You must be signed in to change notification settings - Fork 533
/
data_source_alicloud_oss_service.go
58 lines (49 loc) · 1.67 KB
/
data_source_alicloud_oss_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package alicloud
import (
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)
func dataSourceAlicloudOssService() *schema.Resource {
return &schema.Resource{
Read: dataSourceAlicloudOssServiceRead,
Schema: map[string]*schema.Schema{
"enable": {
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"On", "Off"}, false),
Optional: true,
Default: "Off",
},
"status": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAlicloudOssServiceRead(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("enable"); !ok || v.(string) != "On" {
d.SetId("OssServiceHasNotBeenOpened")
d.Set("status", "")
return nil
}
conn, err := meta.(*connectivity.AliyunClient).NewTeaCommonClient(connectivity.OpenOssService)
if err != nil {
return WrapError(err)
}
response, err := conn.DoRequest(StringPointer("OpenOssService"), nil, StringPointer("POST"), StringPointer("2019-04-22"), StringPointer("AK"), nil, nil, &util.RuntimeOptions{})
addDebug("OpenOssService", response, nil)
if err != nil {
if IsExpectedErrors(err, []string{"SYSTEM.SALE_VALIDATE_NO_SPECIFIC_CODE_FAILEDError", "ORDER.OPEND"}) {
d.SetId("OssServicHasBeenOpened")
d.Set("status", "Opened")
return nil
}
return WrapErrorf(err, DataDefaultErrorMsg, "alicloud_oss_service", "OpenOssService", AlibabaCloudSdkGoERROR)
}
d.SetId(fmt.Sprintf("%v", response["OrderId"]))
d.Set("status", "Opened")
return nil
}