Skip to content

Commit

Permalink
merge commit from master and resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lyu571 committed May 22, 2023
2 parents f31667b + 8a11baa commit 48305f0
Show file tree
Hide file tree
Showing 48 changed files with 3,957 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .changelog/1797.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:new-data-source
tencentcloud_lighthouse_all_scene
```

```release-note:new-data-source
tencentcloud_lighthouse_modify_instance_bundle
```

```release-note:new-resource
tencentcloud_lighthouse_renew_disk
```

```release-note:new-resource
tencentcloud_lighthouse_renew_instance
```
7 changes: 7 additions & 0 deletions .changelog/1799.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
tencentcloud_vpc_snapshot_policy
```

```release-note:new-resource
tencentcloud_vpc_snapshot_policy_attachment
```
3 changes: 3 additions & 0 deletions .changelog/1801.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
tencentcloud_vpc_snapshot_policy_config
```
19 changes: 19 additions & 0 deletions .changelog/1802.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:new-data-source
tencentcloud_cvm_image_quota
```

```release-note:new-data-source
tencentcloud_cvm_image_share_permission
```

```release-note:new-data-source
tencentcloud_cvm_import_image_os
```

```release-note:new-resource
tencentcloud_cvm_renew_instance
```

```release-note:new-resource
tencentcloud_cvm_sync_image
```
76 changes: 76 additions & 0 deletions tencentcloud/data_source_tc_cvm_image_quota.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Use this data source to query detailed information of cvm image_quota
Example Usage
```hcl
data "tencentcloud_cvm_image_quota" "image_quota" {
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudCvmImageQuota() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudCvmImageQuotaRead,
Schema: map[string]*schema.Schema{
"image_num_quota": {
Computed: true,
Type: schema.TypeInt,
Description: "The image quota of an account.",
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudCvmImageQuotaRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_cvm_image_quota.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

var imageNumQuota int64
ctx := context.WithValue(context.TODO(), logIdKey, logId)

paramMap := make(map[string]interface{})
service := CvmService{client: meta.(*TencentCloudClient).apiV3Conn}

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCvmImageQuotaByFilter(ctx, paramMap)
if e != nil {
return retryError(e)
}
imageNumQuota = result
return nil
})
if err != nil {
return err
}

_ = d.Set("image_num_quota", imageNumQuota)

d.SetId(helper.BuildToken())
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), map[string]interface{}{
"image_num_quota": imageNumQuota,
}); e != nil {
return e
}
}
return nil
}
29 changes: 29 additions & 0 deletions tencentcloud/data_source_tc_cvm_image_quota_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccTencentCloudCvmImageQuotaDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCvmImageQuotaDataSource,
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cvm_image_quota.image_quota")),
},
},
})
}

const testAccCvmImageQuotaDataSource = `
data "tencentcloud_cvm_image_quota" "image_quota" {
}
`
121 changes: 121 additions & 0 deletions tencentcloud/data_source_tc_cvm_image_share_permission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Use this data source to query detailed information of cvm image_share_permission
Example Usage
```hcl
data "tencentcloud_cvm_image_share_permission" "image_share_permission" {
image_id = "img-xxxxxx"
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudCvmImageSharePermission() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudCvmImageSharePermissionRead,
Schema: map[string]*schema.Schema{
"image_id": {
Required: true,
Type: schema.TypeString,
Description: "The ID of the image to be shared.",
},

"share_permission_set": {
Computed: true,
Type: schema.TypeList,
Description: "Information on image sharing.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"created_time": {
Type: schema.TypeString,
Computed: true,
Description: "Time when an image was shared.",
},
"account_id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the account with which the image is shared.",
},
},
},
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudCvmImageSharePermissionRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_cvm_image_share_permission.read")()
defer inconsistentCheck(d, meta)()

logId := getLogId(contextNil)

ctx := context.WithValue(context.TODO(), logIdKey, logId)

paramMap := make(map[string]interface{})
if v, ok := d.GetOk("image_id"); ok {
paramMap["ImageId"] = helper.String(v.(string))
}

service := CvmService{client: meta.(*TencentCloudClient).apiV3Conn}

var sharePermissionSet []*cvm.SharePermission

err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeCvmImageSharePermissionByFilter(ctx, paramMap)
if e != nil {
return retryError(e)
}
sharePermissionSet = result
return nil
})
if err != nil {
return err
}

ids := make([]string, 0, len(sharePermissionSet))
tmpList := make([]map[string]interface{}, 0, len(sharePermissionSet))

if sharePermissionSet != nil {
for _, sharePermission := range sharePermissionSet {
sharePermissionMap := map[string]interface{}{}

if sharePermission.CreatedTime != nil {
sharePermissionMap["created_time"] = sharePermission.CreatedTime
}

if sharePermission.AccountId != nil {
sharePermissionMap["account_id"] = sharePermission.AccountId
}

ids = append(ids, *sharePermission.AccountId)
tmpList = append(tmpList, sharePermissionMap)
}

_ = d.Set("share_permission_set", tmpList)
}

d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := writeToFile(output.(string), tmpList); e != nil {
return e
}
}
return nil
}
28 changes: 28 additions & 0 deletions tencentcloud/data_source_tc_cvm_image_share_permission_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccTencentCloudCvmImageSharePermissionDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCvmImageSharePermissionDataSource,
Check: resource.ComposeTestCheckFunc(testAccCheckTencentCloudDataSourceID("data.tencentcloud_cvm_image_share_permission.image_share_permission")),
},
},
})
}

const testAccCvmImageSharePermissionDataSource = `
data "tencentcloud_cvm_image_share_permission" "image_share_permission" {
image_id = "img-k4h0m5la"
}
`
Loading

0 comments on commit 48305f0

Please sign in to comment.