Skip to content

Commit

Permalink
deprecate cts resource and move to sub directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiChangkuo committed May 6, 2021
1 parent 537ef7a commit 3d5312a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
5 changes: 3 additions & 2 deletions docs/data-sources/cts_tracker.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
subcategory: "Cloud Trace Service (CTS)"
subcategory: "Deprecated"
---

# huaweicloud\_cts\_tracker

!> **Warning:** It has been deprecated.

CTS Tracker data source allows access of Cloud Tracker.
This is an alternative to `huaweicloud_cts_tracker_v1`

## Example Usage

Expand Down
5 changes: 3 additions & 2 deletions docs/resources/cts_tracker.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
subcategory: "Cloud Trace Service (CTS)"
subcategory: "Deprecated"
---

# huaweicloud\_cts\_tracker

!> **Warning:** It has been deprecated.

Allows you to collect, store, and query cloud resource operation records.
This is an alternative to `huaweicloud_cts_tracker_v1`

## Example Usage

Expand Down
23 changes: 23 additions & 0 deletions huaweicloud/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/helper/pathorcontents"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk"
huaweisdk "github.com/huaweicloud/golangsdk/openstack"
"github.com/huaweicloud/golangsdk/openstack/identity/v3/domains"
Expand Down Expand Up @@ -513,6 +514,28 @@ func (c *Config) loadUserProjects(client *golangsdk.ProviderClient, region strin
return nil
}

// GetRegion returns the region that was specified in the resource. If a
// region was not set, the provider-level region is checked. The provider-level
// region can either be set by the region argument or by HW_REGION_NAME.
func (c *Config) GetRegion(d *schema.ResourceData) string {
if v, ok := d.GetOk("region"); ok {
return v.(string)
}

return c.Region
}

// GetEnterpriseProjectID returns the enterprise_project_id that was specified in the resource.
// If it was not set, the provider-level value is checked. The provider-level value can
// either be set by the `enterprise_project_id` argument or by HW_ENTERPRISE_PROJECT_ID.
func (c *Config) GetEnterpriseProjectID(d *schema.ResourceData) string {
if v, ok := d.GetOk("enterprise_project_id"); ok {
return v.(string)
}

return c.EnterpriseProjectID
}

// ********** client for Global Service **********
func (c *Config) IAMV3Client(region string) (*golangsdk.ServiceClient, error) {
return c.NewServiceClient("iam", region)
Expand Down
7 changes: 3 additions & 4 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/deprecated"
)

const defaultCloud string = "myhuaweicloud.com"
Expand Down Expand Up @@ -265,7 +266,6 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_compute_instance": DataSourceComputeInstance(),
"huaweicloud_csbs_backup": dataSourceCSBSBackupV1(),
"huaweicloud_csbs_backup_policy": dataSourceCSBSBackupPolicyV1(),
"huaweicloud_cts_tracker": dataSourceCTSTrackerV1(),
"huaweicloud_dcs_az": dataSourceDcsAZV1(),
"huaweicloud_dcs_maintainwindow": dataSourceDcsMaintainWindowV1(),
"huaweicloud_dcs_product": dataSourceDcsProductV1(),
Expand Down Expand Up @@ -331,7 +331,6 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_dms_maintainwindow_v1": dataSourceDmsMaintainWindowV1(),
"huaweicloud_vbs_backup_policy_v2": dataSourceVBSBackupPolicyV2(),
"huaweicloud_vbs_backup_v2": dataSourceVBSBackupV2(),
"huaweicloud_cts_tracker_v1": dataSourceCTSTrackerV1(),
"huaweicloud_antiddos_v1": dataSourceAntiDdosV1(),
"huaweicloud_dcs_az_v1": dataSourceDcsAZV1(),
"huaweicloud_dcs_maintainwindow_v1": dataSourceDcsMaintainWindowV1(),
Expand All @@ -347,6 +346,7 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_rts_stack_v1": dataSourceRTSStackV1(),
"huaweicloud_rts_stack_resource_v1": dataSourceRTSStackResourcesV1(),
"huaweicloud_rts_software_config_v1": dataSourceRtsSoftwareConfigV1(),
"huaweicloud_cts_tracker": deprecated.DataSourceCTSTrackerV1(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -381,7 +381,6 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_csbs_backup_policy": resourceCSBSBackupPolicyV1(),
"huaweicloud_css_cluster": resourceCssClusterV1(),
"huaweicloud_css_snapshot": resourceCssSnapshot(),
"huaweicloud_cts_tracker": resourceCTSTrackerV1(),
"huaweicloud_dcs_instance": ResourceDcsInstanceV1(),
"huaweicloud_dds_instance": resourceDdsInstanceV3(),
"huaweicloud_dis_stream": resourceDisStreamV2(),
Expand Down Expand Up @@ -536,7 +535,6 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_csbs_backup_policy_v1": resourceCSBSBackupPolicyV1(),
"huaweicloud_vbs_backup_policy_v2": resourceVBSBackupPolicyV2(),
"huaweicloud_vbs_backup_v2": resourceVBSBackupV2(),
"huaweicloud_cts_tracker_v1": resourceCTSTrackerV1(),
"huaweicloud_maas_task": resourceMaasTaskV1(),
"huaweicloud_maas_task_v1": resourceMaasTaskV1(),
"huaweicloud_identity_project_v3": ResourceIdentityProjectV3(),
Expand Down Expand Up @@ -577,6 +575,7 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_compute_floatingip_associate_v2": ResourceComputeFloatingIPAssociateV2(),
"huaweicloud_rts_stack_v1": resourceRTSStackV1(),
"huaweicloud_rts_software_config_v1": resourceSoftwareConfigV1(),
"huaweicloud_cts_tracker": deprecated.ResourceCTSTrackerV1(),
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package huaweicloud
package deprecated

import (
"fmt"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
)

func dataSourceCTSTrackerV1() *schema.Resource {
func DataSourceCTSTrackerV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceCTSTrackerV1Read,

Expand Down Expand Up @@ -69,7 +69,7 @@ func dataSourceCTSTrackerV1() *schema.Resource {

func dataSourceCTSTrackerV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
trackerClient, err := config.CtsV1Client(GetRegion(d, config))
trackerClient, err := config.CtsV1Client(config.GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating cts Client: %s", err)
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func dataSourceCTSTrackerV1Read(d *schema.ResourceData, meta interface{}) error
d.Set("operations", trackers.SimpleMessageNotification.Operations)
d.Set("need_notify_user_list", trackers.SimpleMessageNotification.NeedNotifyUserList)

d.Set("region", GetRegion(d, config))
d.Set("region", config.GetRegion(d))

return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package huaweicloud
package deprecated

import (
"time"
Expand All @@ -13,7 +13,7 @@ import (
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func resourceCTSTrackerV1() *schema.Resource {
func ResourceCTSTrackerV1() *schema.Resource {
return &schema.Resource{
Create: resourceCTSTrackerCreate,
Read: resourceCTSTrackerRead,
Expand Down Expand Up @@ -86,7 +86,7 @@ func resourceCTSTrackerV1() *schema.Resource {

func resourceCTSTrackerCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
ctsClient, err := config.CtsV1Client(GetRegion(d, config))
ctsClient, err := config.CtsV1Client(config.GetRegion(d))

if err != nil {
return fmt.Errorf("Error creating cts Client: %s", err)
Expand Down Expand Up @@ -121,7 +121,7 @@ func resourceCTSTrackerCreate(d *schema.ResourceData, meta interface{}) error {

func resourceCTSTrackerRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
ctsClient, err := config.CtsV1Client(GetRegion(d, config))
ctsClient, err := config.CtsV1Client(config.GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating cts Client: %s", err)
}
Expand Down Expand Up @@ -154,14 +154,14 @@ func resourceCTSTrackerRead(d *schema.ResourceData, meta interface{}) error {
d.Set("operations", ctsTracker.SimpleMessageNotification.Operations)
d.Set("need_notify_user_list", ctsTracker.SimpleMessageNotification.NeedNotifyUserList)

d.Set("region", GetRegion(d, config))
d.Set("region", config.GetRegion(d))

return nil
}

func resourceCTSTrackerUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
ctsClient, err := config.CtsV1Client(GetRegion(d, config))
ctsClient, err := config.CtsV1Client(config.GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating cts Client: %s", err)
}
Expand Down Expand Up @@ -199,7 +199,7 @@ func resourceCTSTrackerUpdate(d *schema.ResourceData, meta interface{}) error {

func resourceCTSTrackerDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
ctsClient, err := config.CtsV1Client(GetRegion(d, config))
ctsClient, err := config.CtsV1Client(config.GetRegion(d))
if err != nil {
return fmt.Errorf("Error creating cts Client: %s", err)
}
Expand Down

0 comments on commit 3d5312a

Please sign in to comment.