-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VPC] Add
vpc_bandwidth_associate_v2
resource (#1549)
[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
1 parent
73eaa0e
commit 5e9136e
Showing
8 changed files
with
433 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
opentelekomcloud/acceptance/vpc/resource_opentelekomcloud_vpc_bandwidth_associate_v2_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.