Skip to content

Commit

Permalink
Add new resource vpc_bandwidth_associate_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
outcatcher committed Nov 25, 2021
1 parent da9bcb2 commit aa76adc
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 1 deletion.
61 changes: 61 additions & 0 deletions docs/resources/vpc_bandwidth_associate_v2.md
@@ -0,0 +1,61 @@
---
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
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
@@ -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]
}
`
1 change: 1 addition & 0 deletions opentelekomcloud/provider.go
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

0 comments on commit aa76adc

Please sign in to comment.