Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new resource
vpc_bandwidth_associate_v2
- Loading branch information
1 parent
da9bcb2
commit aa76adc
Showing
6 changed files
with
426 additions
and
1 deletion.
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,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 | ||
``` | ||
|
||
|
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
Oops, something went wrong.