Skip to content

Commit

Permalink
[DCaaS] add new resource and datasource for `opentelekomcloud_direct_…
Browse files Browse the repository at this point in the history
…connect_v2` (#2287)

[DCaaS] add new resource and datasource for `opentelekomcloud_direct_connect_v2`

Summary of the Pull Request
PR Checklist

 Refers to: #2215
 Tests added/passed.
 Documentation added.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestDirectConnectV2Datasource_basic
--- PASS: TestDirectConnectV2Datasource_basic (32.31s)
PASS

Process finished with the exit code 0

=== RUN   TestDirectConnectV2Resource_basic
--- PASS: TestDirectConnectV2Resource_basic (52.84s)
PASS

Process finished with the exit code 0

Reviewed-by: Anton Sidelnikov
Reviewed-by: Artem Lifshits
  • Loading branch information
vladimirvshivkov authored Aug 31, 2023
1 parent 8f3ce88 commit 5a5a2db
Show file tree
Hide file tree
Showing 10 changed files with 972 additions and 0 deletions.
64 changes: 64 additions & 0 deletions docs/data-sources/direct_connect_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
subcategory: "Direct Connect (DCaaS)"
---
# opentelekomcloud_direct_connect_v2 (Data Source)

Use this data source to get details about a specific Direct Connect (DCaaS) connection.

Example usage
-----------------

```hcl
data "opentelekomcloud_direct_connect_v2" "direct_connect" {
id = "direct_connect_id"
}
```


## Argument Reference

- `id` (String) - Specifies the direct connection ID.

## Attributes Reference
* `bandwidth` (Number) - Specifies the bandwidth of the connection in Mbit/s.
* `location` (String) - Specifies the connection access location.
* `provider_name` (String) - Specifies the carrier who provides the leased line.
* `port_type` (String) - Specifies the type of the port used by the connection. The value can be 1G, 10G, 40G, or 100G.
* `admin_state_up` (Boolean) - Specifies the administrative status of the connection. The value can be true or false.
* `charge_mode` (String) - Specifies the billing mode. The value can only be port for operations connections.
* `description` (String) - Provides supplementary information about the connection.
* `device_id` (String) - Specifies the gateway device ID of the connection.
* `hosting_id` (String) - Specifies the ID of the operations connection on which the hosted connection is created.
* `interface_name` (String) - Specifies the name of the interface accessed by the connection.
* `name` (String) - Specifies the connection name.
* `order_id` (String) - Specifies the connection order ID, which is used to support duration-based billing and identify user orders.
* `peer_location` (String) - Specifies the physical location of the peer device accessed by the connection, specific to the street or data center name.
* `product_id` (String) - Specifies the product ID corresponding to the connection's order, which is used to custom billing policies such as duration-based packages.
* `provider_status` (String) - Specifies the status of the carrier's leased line. The value can be ACTIVE or DOWN.
* `redundant_id` (String) - Specifies the ID of the redundant connection using the same gateway.
* `status` (String) - Specifies the connection status.
The value can be ACTIVE, DOWN, BUILD, ERROR, PENDING_DELETE, DELETED, APPLY, DENY, PENDING_PAY, PAID, ORDERING, ACCEPT, or REJECTED.
* `tenant_id` (String) - Specifies the project ID.
* `type` (String) - Specifies the connection type. The value can only be hosted.
* `vlan` (Number) - Specifies the VLAN ID of the connection.
* `applicant` (String) - This is a reserved field, which is not used currently.
* `apply_time` (String) - Specifies the time when the connection was requested.
* `building_line_product_id` (String) - This is a reserved field, which is not used currently.
* `cable_label` (String) - This is a reserved field, which is not used currently.
* `create_time` (String) - Specifies the time when the connection is created.
* `delete_time` (String) - Specifies the time when the connection was deleted.
* `email` (String) - This is a reserved field, which is not used currently.
* `id` (String) - Specifies the connection ID.
* `lag_id` (String) - This is a reserved field, which is not used currently.
* `last_onestop_product_id` (String) - This is a reserved field, which is not used currently.
* `mobile` (String) - This is a reserved field, which is not used currently.
* `onestop_product_id` (String) - This is a reserved field, which is not used currently.
* `peer_port_type` (String) - This is a reserved field, which is not used currently.
* `peer_provider` (String) - This is a reserved field, which is not used currently.
* `period_num` (Number) - This is a reserved field, which is not used currently.
* `period_type` (Number) - This is a reserved field, which is not used currently.
* `reason` (String) - This is a reserved field, which is not used currently.
* `region_id` (String) - Specifies the region ID.
* `service_key` (String) - This is a reserved field, which is not used currently.
* `spec_code` (String) - This is a reserved field, which is not used currently.
* `vgw_type` (String) - Specifies the type of the gateway. Currently, only the default type is supported.
74 changes: 74 additions & 0 deletions docs/resources/direct_connect_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
subcategory: "Direct Connect (DCaaS)"
---
# opentelekomcloud_direct_connect_v2 (Resource)

Up-to-date reference of API arguments for Direct Connect (DCaaS) you can get at
`https://docs.otc.t-systems.com/direct-connect/api-ref/apis/connection/creating_a_connection.html`.

Example usage
-----------------
```hcl
resource "opentelekomcloud_direct_connect_v2" "direct_connect" {
name = "direct_connect"
bandwidth = 100
location = "location"
provider_name = "provider_name"
port_type = "port_type"
admin_state_up = true
}
```


## Argument Reference

### Required

* `bandwidth` (Number) - Specifies the bandwidth of the connection in Mbit/s.
* `location` (String, ForceNew) - Specifies the connection access location.
* `provider_name` (String, ForceNew) - Specifies the carrier who provides the leased line.
* `port_type` (String, ForceNew) - Specifies the type of the port used by the connection. The value can be 1G, 10G, 40G, or 100G.

### Optional

* `admin_state_up` (Boolean, ForceNew) - Specifies the administrative status of the connection. The value can be true or false.
* `charge_mode` (String, ForceNew) - Specifies the billing mode. The value can only be port for operations connections.
* `description` (String) - Provides supplementary information about the connection.
* `device_id` (String, ForceNew) - Specifies the gateway device ID of the connection.
* `hosting_id` (String, ForceNew) - Specifies the ID of the operations connection on which the hosted connection is created.
* `interface_name` (String, ForceNew) - Specifies the name of the interface accessed by the connection.
* `name` (String) - Specifies the connection name.
* `order_id` (String, ForceNew) - Specifies the connection order ID, which is used to support duration-based billing and identify user orders.
* `peer_location` (String, ForceNew) - Specifies the physical location of the peer device accessed by the connection, specific to the street or data center name.
* `product_id` (String, ForceNew) - Specifies the product ID corresponding to the connection's order, which is used to custom billing policies such as duration-based packages.
* `provider_status` (String) - Specifies the status of the carrier's leased line. The value can be ACTIVE or DOWN.
* `redundant_id` (String, ForceNew) - Specifies the ID of the redundant connection using the same gateway.
* `status` (String, ForceNew) - Specifies the connection status.
The value can be: `ACTIVE, DOWN, BUILD, ERROR, PENDING_DELETE, DELETED, APPLY, DENY, PENDING_PAY, PAID, ORDERING, ACCEPT, or REJECTED.`
* `tenant_id` (String, ForceNew) - Specifies the project ID.
* `type` (String, ForceNew) - Specifies the connection type. The value can only be `hosted`.
* `vlan` (Number, ForceNew) - Specifies the VLAN ID of the connection.

## Attributes Reference

* `applicant` (String) - This is a reserved field, which is not used currently.
* `apply_time` (String) - Specifies the time when the connection was requested.
* `building_line_product_id` (String) - This is a reserved field, which is not used currently.
* `cable_label` (String) - This is a reserved field, which is not used currently.
* `create_time` (String) - Specifies the time when the connection is created.
* `delete_time` (String) - Specifies the time when the connection was deleted.
* `email` (String) - This is a reserved field, which is not used currently.
* `id` (String) - Specifies the connection ID.
* `lag_id` (String) - This is a reserved field, which is not used currently.
* `last_onestop_product_id` (String) - This is a reserved field, which is not used currently.
* `mobile` (String) - This is a reserved field, which is not used currently.
* `onestop_product_id` (String) - This is a reserved field, which is not used currently.
* `peer_port_type` (String) - This is a reserved field, which is not used currently.
* `peer_provider` (String) - This is a reserved field, which is not used currently.
* `period_num` (Number) - This is a reserved field, which is not used currently.
* `period_type` (Number) - This is a reserved field, which is not used currently.
* `reason` (String) - This is a reserved field, which is not used currently.
* `region_id` (String) - Specifies the region ID.
* `service_key` (String) - This is a reserved field, which is not used currently.
* `spec_code` (String) - This is a reserved field, which is not used currently.
* `vgw_type` (String) - Specifies the type of the gateway. Currently, only the default type is supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dcaas

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
)

func TestDirectConnectV2Datasource_basic(t *testing.T) {
var directConnectName = fmt.Sprintf("dc-%s", acctest.RandString(5))
const dc = "opentelekomcloud_direct_connect_v2.direct_connect"

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckDirectConnectV2Destroy,
Steps: []resource.TestStep{
{
Config: testAccDirectConnectV2Datasource_basic(directConnectName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dc, "bandwidth", "100"),
),
},
},
})
}

func testAccDirectConnectV2Datasource_basic(directConnectName string) string {
return fmt.Sprintf(`
resource "opentelekomcloud_direct_connect_v2" "direct_connect" {
name = "%s"
port_type = "1G"
location = "Biere"
bandwidth = 100
provider_name = "OTC"
}
data "opentelekomcloud_direct_connect_v2" "direct_connect" {
id = opentelekomcloud_direct_connect_v2.direct_connect.id
}
`, directConnectName)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package dcaas

import (
"errors"
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
dcaas "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/direct-connect"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/env"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/common/cfg"
)

func TestDirectConnectV2Resource_basic(t *testing.T) {
directConnectName := fmt.Sprintf("dc-%s", acctest.RandString(5))
directConnectNameUpdated := fmt.Sprintf("dc-updated-%s", acctest.RandString(5))

const dc = "opentelekomcloud_direct_connect_v2.direct_connect"

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckDirectConnectV2Destroy,
Steps: []resource.TestStep{
{
Config: testAccDirectConnectV2Resource_basic(directConnectName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dc, "bandwidth", "50"),
resource.TestCheckResourceAttrSet(dc, "id"),
),
},
{
Config: testAccDirectConnectV2ResourceUpdate_basic(directConnectNameUpdated),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dc, "bandwidth", "100"),
resource.TestCheckResourceAttrSet(dc, "id"),
),
},
},
})
}

func testAccDirectConnectV2Resource_basic(directConnectName string) string {
return fmt.Sprintf(`
resource "opentelekomcloud_direct_connect_v2" "direct_connect" {
name = "%s"
port_type = "1G"
location = "Biere"
bandwidth = 50
provider_name = "OTC"
}
`, directConnectName)
}

func testAccDirectConnectV2ResourceUpdate_basic(directConnectName string) string {
return fmt.Sprintf(`
resource "opentelekomcloud_direct_connect_v2" "direct_connect" {
name = "%s"
port_type = "1G"
location = "Biere"
bandwidth = 100
provider_name = "OTC"
}
`, directConnectName)
}

func testAccCheckDirectConnectV2Destroy(s *terraform.State) error {
config := common.TestAccProvider.Meta().(*cfg.Config)
dcaasClient, err := config.DCaaSV2Client(env.OS_REGION_NAME)
if err != nil {
return fmt.Errorf("Error creating DCaaS client: %s", err)
}

for _, rs := range s.RootModule().Resources {
if rs.Type != "opentelekomcloud_direct_connect_v2" {
continue
}

_, err := dcaas.Get(dcaasClient, rs.Primary.ID)
if err == nil {
return fmt.Errorf("DirectConnect still exists")
}
var errDefault404 golangsdk.ErrDefault404
if !errors.As(err, &errDefault404) {
return err
}
}
return nil
}
7 changes: 7 additions & 0 deletions opentelekomcloud/common/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,13 @@ func (c *Config) CsbsV1Client(region string) (*golangsdk.ServiceClient, error) {
})
}

func (c *Config) DCaaSV2Client(region string) (*golangsdk.ServiceClient, error) {
return openstack.NewDCaaSV2(c.HwClient, golangsdk.EndpointOpts{
Region: region,
Availability: c.getEndpointType(),
})
}

func (c *Config) DehV1Client(region string) (*golangsdk.ServiceClient, error) {
return openstack.NewDeHServiceV1(c.HwClient, golangsdk.EndpointOpts{
Region: region,
Expand Down
3 changes: 3 additions & 0 deletions opentelekomcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/csbs"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/css"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/cts"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/dcaas"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/dcs"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/dds"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/services/deh"
Expand Down Expand Up @@ -252,6 +253,7 @@ func Provider() *schema.Provider {
"opentelekomcloud_csbs_backup_policy_v1": csbs.DataSourceCSBSBackupPolicyV1(),
"opentelekomcloud_css_flavor_v1": css.DataSourceCSSFlavorV1(),
"opentelekomcloud_cts_tracker_v1": cts.DataSourceCTSTrackerV1(),
"opentelekomcloud_direct_connect_v2": dcaas.DataSourceDirectConnectV2(),
"opentelekomcloud_dcs_az_v1": dcs.DataSourceDcsAZV1(),
"opentelekomcloud_dcs_maintainwindow_v1": dcs.DataSourceDcsMaintainWindowV1(),
"opentelekomcloud_dcs_product_v1": dcs.DataSourceDcsProductV1(),
Expand Down Expand Up @@ -349,6 +351,7 @@ func Provider() *schema.Provider {
"opentelekomcloud_cts_tracker_v3": cts.ResourceCTSTrackerV3(),
"opentelekomcloud_css_cluster_v1": css.ResourceCssClusterV1(),
"opentelekomcloud_css_snapshot_configuration_v1": css.ResourceCssSnapshotConfigurationV1(),
"opentelekomcloud_direct_connect_v2": dcaas.ResourceDirectConnectV2(),
"opentelekomcloud_dcs_instance_v1": dcs.ResourceDcsInstanceV1(),
"opentelekomcloud_dds_instance_v3": dds.ResourceDdsInstanceV3(),
"opentelekomcloud_deh_host_v1": deh.ResourceDeHHostV1(),
Expand Down
6 changes: 6 additions & 0 deletions opentelekomcloud/services/dcaas/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dcaas

const (
errCreateClient = "error creating OpenTelekomCloud DCaaSv2 client: %w"
keyClientV2 = "dcaas-v2-client"
)
Loading

0 comments on commit 5a5a2db

Please sign in to comment.