-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,232 additions
and
222 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
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
120 changes: 120 additions & 0 deletions
120
tencentcloud/services/tco/data_source_tc_organization_org_share_area.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,120 @@ | ||
package tco | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
organization "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331" | ||
|
||
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" | ||
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" | ||
) | ||
|
||
func DataSourceTencentCloudOrganizationOrgShareArea() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceTencentCloudOrganizationOrgShareAreaRead, | ||
Schema: map[string]*schema.Schema{ | ||
"lang": { | ||
Optional: true, | ||
Type: schema.TypeString, | ||
Description: "Language.default zh.\nValid values:\n - `zh`: Chinese.\n - `en`: English.", | ||
}, | ||
|
||
"items": { | ||
Computed: true, | ||
Type: schema.TypeList, | ||
Description: "Area list.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Region name.", | ||
}, | ||
"area": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Region identifier.", | ||
}, | ||
"area_id": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Region ID.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"result_output_file": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Used to save results.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTencentCloudOrganizationOrgShareAreaRead(d *schema.ResourceData, meta interface{}) error { | ||
defer tccommon.LogElapsed("data_source.tencentcloud_organization_org_share_area.read")() | ||
defer tccommon.InconsistentCheck(d, meta)() | ||
|
||
logId := tccommon.GetLogId(tccommon.ContextNil) | ||
|
||
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId) | ||
|
||
paramMap := make(map[string]interface{}) | ||
if v, ok := d.GetOk("lang"); ok { | ||
paramMap["Lang"] = helper.String(v.(string)) | ||
} | ||
|
||
service := OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} | ||
|
||
var items []*organization.ShareArea | ||
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { | ||
result, e := service.DescribeOrganizationOrgShareAreaByFilter(ctx, paramMap) | ||
if e != nil { | ||
return tccommon.RetryError(e) | ||
} | ||
items = result | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ids := make([]string, 0, len(items)) | ||
tmpList := make([]map[string]interface{}, 0, len(items)) | ||
|
||
if items != nil { | ||
for _, shareArea := range items { | ||
shareAreaMap := map[string]interface{}{} | ||
|
||
if shareArea.Name != nil { | ||
shareAreaMap["name"] = shareArea.Name | ||
} | ||
|
||
if shareArea.Area != nil { | ||
shareAreaMap["area"] = shareArea.Area | ||
} | ||
|
||
if shareArea.AreaId != nil { | ||
shareAreaMap["area_id"] = shareArea.AreaId | ||
} | ||
|
||
ids = append(ids, *shareArea.Area) | ||
tmpList = append(tmpList, shareAreaMap) | ||
} | ||
|
||
_ = d.Set("items", tmpList) | ||
} | ||
|
||
d.SetId(helper.DataResourceIdsHash(ids)) | ||
output, ok := d.GetOk("result_output_file") | ||
if ok && output.(string) != "" { | ||
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil { | ||
return e | ||
} | ||
} | ||
return nil | ||
} |
9 changes: 9 additions & 0 deletions
9
tencentcloud/services/tco/data_source_tc_organization_org_share_area.md
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,9 @@ | ||
Use this data source to query detailed information of organization org_share_area | ||
|
||
Example Usage | ||
|
||
```hcl | ||
data "tencentcloud_organization_org_share_area" "org_share_area" { | ||
lang = "zh" | ||
} | ||
``` |
33 changes: 33 additions & 0 deletions
33
tencentcloud/services/tco/data_source_tc_organization_org_share_area_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,33 @@ | ||
package tco_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" | ||
) | ||
|
||
func TestAccTencentCloudOrganizationOrgShareAreaDataSource_basic(t *testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
tcacctest.AccPreCheck(t) | ||
}, | ||
Providers: tcacctest.AccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOrganizationOrgShareAreaDataSource, | ||
Check: resource.ComposeTestCheckFunc(tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_org_share_area.org_share_area")), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccOrganizationOrgShareAreaDataSource = ` | ||
data "tencentcloud_organization_org_share_area" "org_share_area" { | ||
lang = "zh" | ||
} | ||
` |
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
2 changes: 1 addition & 1 deletion
2
vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.