Skip to content

Commit

Permalink
[VPC] Add vpc_bandwidth_associate_v2 resource (#1549)
Browse files Browse the repository at this point in the history
[VPC] Add `vpc_bandwidth_associate_v2` resource

Summary of the Pull Request
Add new resource opentelekomcloud_vpc_bandwidth_associate_v2
Fix minor problems with opentelekomcloud_vpc_bandwidth_v2 doc and RN
Part of #716 (still need a data source)
PR Checklist

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

Acceptance Steps Performed
=== RUN   TestBandwidthAssociateV2_basic
=== PAUSE TestBandwidthAssociateV2_basic
=== CONT  TestBandwidthAssociateV2_basic
--- PASS: TestBandwidthAssociateV2_basic (71.67s)
=== RUN   TestBandwidthAssociateV2_EIPv1
=== PAUSE TestBandwidthAssociateV2_EIPv1
=== CONT  TestBandwidthAssociateV2_EIPv1
--- PASS: TestBandwidthAssociateV2_EIPv1 (88.06s)
=== RUN   TestBandwidthAssociateV2_import
=== PAUSE TestBandwidthAssociateV2_import
=== CONT  TestBandwidthAssociateV2_import
--- PASS: TestBandwidthAssociateV2_import (46.76s)
PASS

Process finished with the exit code 0

Reviewed-by: Rodion Gyrbu <fpsoff@outlook.com>
Reviewed-by: None <None>
Reviewed-by: Vladimir Vshivkov <None>
  • Loading branch information
outcatcher committed Nov 25, 2021
1 parent 73eaa0e commit 5e9136e
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 2 deletions.
59 changes: 59 additions & 0 deletions docs/resources/vpc_bandwidth_associate_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
subcategory: "Virtual Private Cloud (VPC)"
---

# opentelekomcloud_vpc_bandwidth_associate_v2

Provides a resource to associate floating IP with a shared bandwidth within Open Telekom Cloud.

## Example Usage

```hcl
resource "opentelekomcloud_networking_floatingip_v2" "ip1" {}
resource "opentelekomcloud_networking_floatingip_v2" "ip2" {}
resource "opentelekomcloud_vpc_bandwidth_v2" "band20m" {
name = "bandwidth-20MBit"
size = 20
}
resource "opentelekomcloud_vpc_bandwidth_associate_v2" "associate" {
bandwidth = opentelekomcloud_vpc_bandwidth_v2.band20m.id
floating_ips = [
opentelekomcloud_networking_floatingip_v2.ip1.id,
opentelekomcloud_networking_floatingip_v2.ip2.id,
]
}
```

## Argument Reference

The following arguments are supported:

* `bandwidth` - (Required) Specifies ID of the bandwidth to be assigned.

* `floating_ips` - (Required) Specifies IDs of floating IPs to be added to the bandwidth.

->
After an EIP is removed from a shared bandwidth, a dedicated bandwidth will be allocated to the EIP, and you will be
billed for the dedicated bandwidth.

* `backup_charge_mode` - (Optional) Specifies whether the dedicated bandwidth used by the EIP that has been removed from
a shared bandwidth is billed by traffic or by bandwidth.

The value can be `bandwidth` or `traffic`.

Default value is `bandwidth`.

* `backup_size` - (Optional) Specifies the size (Mbit/s) of the dedicated bandwidth used by the EIP that has been
removed from a shared bandwidth.

Default value is `1`.

## Import

VPC bandwidth association can be imported using the bandwidth `id`, e.g.

```sh
terraform import opentelekomcloud_vpc_bandwidth_associate_v2.associate eb187fc8-e482-43eb-a18a-9da947ef89f6
```
2 changes: 1 addition & 1 deletion docs/resources/vpc_bandwidth_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ subcategory: "Virtual Private Cloud (VPC)"
---
# opentelekomcloud_vpc_bandwidth_v2

Provides a resource to create a shared bandwidth within OpenTelekomCloud.
Provides a resource to create a shared bandwidth within Open Telekom Cloud.

## Example Usage

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package acceptance

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v2/bandwidths"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common"
"github.com/opentelekomcloud/terraform-provider-opentelekomcloud/opentelekomcloud/acceptance/common/quotas"
)

const resourceBandwidthAssociateName = "opentelekomcloud_vpc_bandwidth_associate_v2.associate"

func TestBandwidthAssociateV2_basic(t *testing.T) {
var b bandwidths.Bandwidth

t.Parallel()
qts := quotas.MultipleQuotas{
{Q: quotas.SharedBandwidth, Count: 1},
{Q: quotas.FloatingIP, Count: 2},
}
quotas.BookMany(t, qts)

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testCheckBandwidthV2Destroy,
Steps: []resource.TestStep{
{
Config: testBandwidthAssociateV2Basic,
Check: resource.ComposeTestCheckFunc(
testCheckBandwidthExists(resourceBandwidthAssociateName, &b),
resource.TestCheckResourceAttr(resourceBandwidthAssociateName, "floating_ips.#", "1"),
),
},
{
Config: testBandwidthAssociateV2Updated,
Check: resource.ComposeTestCheckFunc(
testCheckBandwidthExists(resourceBandwidthAssociateName, &b),
resource.TestCheckResourceAttr(resourceBandwidthAssociateName, "floating_ips.#", "1"),
),
},
},
})
}

func TestBandwidthAssociateV2_EIPv1(t *testing.T) {
var b bandwidths.Bandwidth

t.Parallel()
qts := quotas.MultipleQuotas{
{Q: quotas.SharedBandwidth, Count: 1},
{Q: quotas.FloatingIP, Count: 1},
}
quotas.BookMany(t, qts)

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testCheckBandwidthV2Destroy,
Steps: []resource.TestStep{
{
Config: testBandwidthAssociateV2EipV1,
Check: resource.ComposeTestCheckFunc(
testCheckBandwidthExists(resourceBandwidthAssociateName, &b),
resource.TestCheckResourceAttr(resourceBandwidthAssociateName, "floating_ips.#", "1"),
),
ExpectNonEmptyPlan: true, // opentelekomcloud_vpc_eip_v1 bandwidth is updated
},
},
})
}

func TestBandwidthAssociateV2_import(t *testing.T) {
t.Parallel()
qts := quotas.MultipleQuotas{
{Q: quotas.SharedBandwidth, Count: 1},
{Q: quotas.FloatingIP, Count: 1},
}
quotas.BookMany(t, qts)

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testCheckBandwidthV2Destroy,
Steps: []resource.TestStep{
{
Config: testBandwidthAssociateV2Basic,
},
{
ResourceName: resourceBandwidthAssociateName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"backup_charge_mode", "backup_size"},
},
},
})
}

const testBandwidthAssociateV2Basic = `
resource "opentelekomcloud_networking_floatingip_v2" "ip" {}
resource "opentelekomcloud_vpc_bandwidth_v2" "band_test" {
name = "shared-test-associate"
size = 20
}
resource "opentelekomcloud_vpc_bandwidth_associate_v2" "associate" {
bandwidth = opentelekomcloud_vpc_bandwidth_v2.band_test.id
floating_ips = [opentelekomcloud_networking_floatingip_v2.ip.id]
}
`

const testBandwidthAssociateV2Updated = `
resource "opentelekomcloud_networking_floatingip_v2" "ip2" {}
resource "opentelekomcloud_vpc_bandwidth_v2" "band_test" {
name = "shared-test-associate"
size = 20
}
resource "opentelekomcloud_vpc_bandwidth_associate_v2" "associate" {
bandwidth = opentelekomcloud_vpc_bandwidth_v2.band_test.id
floating_ips = [opentelekomcloud_networking_floatingip_v2.ip2.id]
}
`

const testBandwidthAssociateV2EipV1 = `
resource "opentelekomcloud_vpc_eip_v1" "eip" {
bandwidth {
name = "tmp-band"
share_type = "PER"
size = 10
}
publicip {
type = "5_bgp"
}
}
resource "opentelekomcloud_vpc_bandwidth_v2" "band_test" {
name = "shared-test-associate"
size = 20
}
resource "opentelekomcloud_vpc_bandwidth_associate_v2" "associate" {
bandwidth = opentelekomcloud_vpc_bandwidth_v2.band_test.id
floating_ips = [opentelekomcloud_vpc_eip_v1.eip.id]
}
`
8 changes: 8 additions & 0 deletions opentelekomcloud/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,11 @@ var (
DataSourceTooFewDiag = diag.Errorf("your query returned no results. Please change your search criteria and try again.")
DataSourceTooManyDiag = diag.Errorf("your query returned more than one result. Please change your search criteria and try again.")
)

// GetSetChanges returns a pair of sets describing removed and added items
func GetSetChanges(d *schema.ResourceData, key string) (removed, added *schema.Set) {
oldOne, newOne := d.GetChange(key)
oldSet := oldOne.(*schema.Set)
newSet := newOne.(*schema.Set)
return oldSet.Difference(newSet), newSet.Difference(oldSet)
}
1 change: 1 addition & 0 deletions opentelekomcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ func Provider() *schema.Provider {
"opentelekomcloud_swr_organization_permissions_v2": swr.ResourceSwrOrganizationPermissionsV2(),
"opentelekomcloud_swr_organization_v2": swr.ResourceSwrOrganizationV2(),
"opentelekomcloud_swr_repository_v2": swr.ResourceSwrRepositoryV2(),
"opentelekomcloud_vpc_bandwidth_associate_v2": vpc.ResourceBandwidthAssociateV2(),
"opentelekomcloud_vpc_bandwidth_v2": vpc.ResourceBandwidthV2(),
"opentelekomcloud_vpc_eip_v1": vpc.ResourceVpcEIPV1(),
"opentelekomcloud_vpc_v1": vpc.ResourceVirtualPrivateCloudV1(),
Expand Down
Loading

0 comments on commit 5e9136e

Please sign in to comment.