Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate cts resource and move to sub directory #1102

Merged
merged 3 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package acceptance

import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud"
)

var (
HW_REGION_NAME = os.Getenv("HW_REGION_NAME")
HW_AVAILABILITY_ZONE = os.Getenv("HW_AVAILABILITY_ZONE")
HW_ACCESS_KEY = os.Getenv("HW_ACCESS_KEY")
HW_SECRET_KEY = os.Getenv("HW_SECRET_KEY")
HW_PROJECT_ID = os.Getenv("HW_PROJECT_ID")
HW_DOMAIN_ID = os.Getenv("HW_DOMAIN_ID")
HW_DOMAIN_NAME = os.Getenv("HW_DOMAIN_NAME")

HW_FLAVOR_ID = os.Getenv("HW_FLAVOR_ID")
HW_FLAVOR_NAME = os.Getenv("HW_FLAVOR_NAME")
HW_IMAGE_ID = os.Getenv("HW_IMAGE_ID")
HW_IMAGE_NAME = os.Getenv("HW_IMAGE_NAME")
HW_VPC_ID = os.Getenv("HW_VPC_ID")
HW_NETWORK_ID = os.Getenv("HW_NETWORK_ID")
HW_SUBNET_ID = os.Getenv("HW_SUBNET_ID")

HW_DEPRECATED_ENVIRONMENT = os.Getenv("HW_DEPRECATED_ENVIRONMENT")
)

var TestAccProviders map[string]terraform.ResourceProvider
var TestAccProvider *schema.Provider

func init() {
TestAccProvider = huaweicloud.Provider().(*schema.Provider)
TestAccProviders = map[string]terraform.ResourceProvider{
"huaweicloud": TestAccProvider,
}
}

func preCheckRequiredEnvVars(t *testing.T) {
if HW_REGION_NAME == "" {
t.Fatal("HW_REGION_NAME must be set for acceptance tests")
}
}

//lintignore:AT003
func TestAccPreCheck(t *testing.T) {
// Do not run the test if this is a deprecated testing environment.
if HW_DEPRECATED_ENVIRONMENT != "" {
t.Skip("This environment only runs deprecated tests")
}

preCheckRequiredEnvVars(t)
}

//lintignore:AT003
func TestAccPreCheckDeprecated(t *testing.T) {
if HW_DEPRECATED_ENVIRONMENT == "" {
t.Skip("This environment does not support deprecated tests")
}

preCheckRequiredEnvVars(t)
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package huaweicloud
package deprecated

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccCTSTrackerV1DataSource_basic(t *testing.T) {
dataName := "data.huaweicloud_cts_tracker.tracker"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { acceptance.TestAccPreCheckDeprecated(t) },
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCTSTrackerV1DataSource_basic,
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,15 +9,16 @@ import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/cts/v1/tracker"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccCTSTrackerV1_basic(t *testing.T) {
var tracker tracker.Tracker
resourceName := "huaweicloud_cts_tracker.tracker"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { acceptance.TestAccPreCheckDeprecated(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: testAccCheckCTSTrackerV1Destroy,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -45,8 +46,8 @@ func TestAccCTSTrackerV1_basic(t *testing.T) {
}

func testAccCheckCTSTrackerV1Destroy(s *terraform.State) error {
config := testAccProvider.Meta().(*config.Config)
ctsClient, err := config.CtsV1Client(HW_REGION_NAME)
config := acceptance.TestAccProvider.Meta().(*config.Config)
ctsClient, err := config.CtsV1Client(config.GetRegion(nil))
if err != nil {
return fmt.Errorf("Error creating cts client: %s", err)
}
Expand Down Expand Up @@ -79,8 +80,8 @@ func testAccCheckCTSTrackerV1Exists(n string, trackers *tracker.Tracker) resourc
return fmt.Errorf("No ID is set")
}

config := testAccProvider.Meta().(*config.Config)
ctsClient, err := config.CtsV1Client(HW_REGION_NAME)
config := acceptance.TestAccProvider.Meta().(*config.Config)
ctsClient, err := config.CtsV1Client(config.GetRegion(nil))
if err != nil {
return fmt.Errorf("Error creating cts client: %s", err)
}
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,9 +9,10 @@ import (
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
)

func dataSourceCTSTrackerV1() *schema.Resource {
func DataSourceCTSTrackerV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceCTSTrackerV1Read,
Read: dataSourceCTSTrackerV1Read,
DeprecationMessage: "CTS tracker has been deprecated.",

Schema: map[string]*schema.Schema{
"region": {
Expand Down Expand Up @@ -69,7 +70,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 +114,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,12 +13,13 @@ import (
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func resourceCTSTrackerV1() *schema.Resource {
func ResourceCTSTrackerV1() *schema.Resource {
return &schema.Resource{
Create: resourceCTSTrackerCreate,
Read: resourceCTSTrackerRead,
Update: resourceCTSTrackerUpdate,
Delete: resourceCTSTrackerDelete,
Create: resourceCTSTrackerCreate,
Read: resourceCTSTrackerRead,
Update: resourceCTSTrackerUpdate,
Delete: resourceCTSTrackerDelete,
DeprecationMessage: "CTS tracker has been deprecated.",
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand Down Expand Up @@ -86,7 +87,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 +122,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 +155,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 +200,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