From b3252ba7a2dfb1422deb7214e6202c35580c950c Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 6 Sep 2019 10:50:28 +0800 Subject: [PATCH 1/2] Add Shared Bandwidth V2 support --- go.mod | 2 +- go.sum | 4 +- huaweicloud/provider.go | 3 +- .../resource_huaweicloud_vpc_bandwidth_v2.go | 190 ++++++++++++++++++ ...ource_huaweicloud_vpc_bandwidth_v2_test.go | 106 ++++++++++ huaweicloud/validators.go | 13 ++ .../huaweicloud/golangsdk/openstack/client.go | 6 + .../networking/v1/bandwidths/results.go | 29 +++ .../networking/v2/bandwidths/requests.go | 157 +++++++++++++++ .../networking/v2/bandwidths/results.go | 131 ++++++++++++ .../networking/v2/bandwidths/urls.go | 26 +++ vendor/modules.txt | 3 +- 12 files changed, 665 insertions(+), 5 deletions(-) create mode 100644 huaweicloud/resource_huaweicloud_vpc_bandwidth_v2.go create mode 100644 huaweicloud/resource_huaweicloud_vpc_bandwidth_v2_test.go create mode 100644 vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/requests.go create mode 100644 vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/results.go create mode 100644 vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/urls.go diff --git a/go.mod b/go.mod index 04887653f9..6740806854 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.0 github.com/hashicorp/terraform v0.12.0 - github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19 + github.com/huaweicloud/golangsdk v0.0.0-20190906094835-10f659f0ae54 github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a github.com/mitchellh/go-homedir v1.0.0 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect diff --git a/go.sum b/go.sum index e2e3d2ae1e..f490c7fdbb 100644 --- a/go.sum +++ b/go.sum @@ -192,8 +192,8 @@ github.com/hashicorp/vault v0.10.4/go.mod h1:KfSyffbKxoVyspOdlaGVjIuwLobi07qD1bA github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19 h1:FUlribrcVGqGR4irupy34lbps5BPTJMurJ+kt/zxDmM= -github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= +github.com/huaweicloud/golangsdk v0.0.0-20190906094835-10f659f0ae54 h1:M4DStISEwrjmVtNkd/8UAaAOAkMa6HswIaCQMnQ02ns= +github.com/huaweicloud/golangsdk v0.0.0-20190906094835-10f659f0ae54/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA= github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY= diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 50428ce8e5..adea8e1c83 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -283,11 +283,12 @@ func Provider() terraform.ResourceProvider { "huaweicloud_rds_instance_v1": resourceRdsInstance(), "huaweicloud_nat_gateway_v2": resourceNatGatewayV2(), "huaweicloud_nat_snat_rule_v2": resourceNatSnatRuleV2(), - "huaweicloud_vpc_eip_v1": resourceVpcEIPV1(), "huaweicloud_sfs_file_system_v2": resourceSFSFileSystemV2(), "huaweicloud_rts_stack_v1": resourceRTSStackV1(), "huaweicloud_iam_agency_v3": resourceIAMAgencyV3(), "huaweicloud_vpc_v1": resourceVirtualPrivateCloudV1(), + "huaweicloud_vpc_bandwidth_v2": resourceVpcBandWidthV2(), + "huaweicloud_vpc_eip_v1": resourceVpcEIPV1(), "huaweicloud_vpc_peering_connection_v2": resourceVpcPeeringConnectionV2(), "huaweicloud_vpc_peering_connection_accepter_v2": resourceVpcPeeringConnectionAccepterV2(), "huaweicloud_vpc_route_v2": resourceVPCRouteV2(), diff --git a/huaweicloud/resource_huaweicloud_vpc_bandwidth_v2.go b/huaweicloud/resource_huaweicloud_vpc_bandwidth_v2.go new file mode 100644 index 0000000000..e5eed8b9f4 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_vpc_bandwidth_v2.go @@ -0,0 +1,190 @@ +package huaweicloud + +import ( + "fmt" + "log" + "time" + + "github.com/huaweicloud/golangsdk" + bandwidthsv1 "github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths" + "github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" +) + +func resourceVpcBandWidthV2() *schema.Resource { + return &schema.Resource{ + Create: resourceVpcBandWidthV2Create, + Read: resourceVpcBandWidthV2Read, + Update: resourceVpcBandWidthV2Update, + Delete: resourceVpcBandWidthV2Delete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Update: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: false, + }, + "size": { + Type: schema.TypeInt, + Required: true, + ForceNew: false, + ValidateFunc: validateIntegerInRange(5, 2000), + }, + "enterprise_project_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + }, + } +} + +func resourceVpcBandWidthV2Create(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + networkingClient, err := config.networkingV2Client(GetRegion(d, config)) + networkingV1Client, err := config.networkingV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating networking client: %s", err) + } + + size := d.Get("size").(int) + createOpts := bandwidths.CreateOpts{ + Name: d.Get("name").(string), + Size: &size, + EnterpriseProjectId: d.Get("enterprise_project_id").(string), + } + + log.Printf("[DEBUG] Create Options: %#v", createOpts) + b, err := bandwidths.Create(networkingClient, createOpts).Extract() + if err != nil { + return fmt.Errorf("Error creating Bandwidth: %s", err) + } + + log.Printf("[DEBUG] Waiting for Bandwidth (%s) to become available.", b.ID) + stateConf := &resource.StateChangeConf{ + Target: []string{"NORMAL"}, + Pending: []string{"CREATING"}, + Refresh: waitForBandwidth(networkingV1Client, b.ID), + Timeout: d.Timeout(schema.TimeoutCreate), + Delay: 3 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + + if err != nil { + return fmt.Errorf( + "Error waiting for Bandwidth (%s) to become ACTIVE for creation: %s", + b.ID, err) + } + d.SetId(b.ID) + + return resourceVpcBandWidthV2Read(d, meta) +} + +func resourceVpcBandWidthV2Update(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + networkingClient, err := config.networkingV2Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating networking client: %s", err) + } + + var bandwidthOpts bandwidths.Bandwidth + + if d.HasChange("name") { + bandwidthOpts.Name = d.Get("name").(string) + } + if d.HasChange("size") { + bandwidthOpts.Size = d.Get("size").(int) + } + + if bandwidthOpts != (bandwidths.Bandwidth{}) { + updateOpts := bandwidths.UpdateOpts{ + Bandwidth: bandwidthOpts, + } + _, err := bandwidths.Update(networkingClient, d.Id(), updateOpts) + if err != nil { + return fmt.Errorf("Error updating Huaweicloud BandWidth (%s): %s", d.Id(), err) + } + } + + return resourceVpcBandWidthV2Read(d, meta) +} + +func resourceVpcBandWidthV2Read(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + networkingClient, err := config.networkingV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating networking client: %s", err) + } + + b, err := bandwidthsv1.Get(networkingClient, d.Id()).Extract() + if err != nil { + return CheckDeleted(d, err, "bandwidth") + } + + d.Set("name", b.Name) + d.Set("size", b.Size) + d.Set("enterprise_project_id", b.EnterpriseProjectID) + + return nil +} + +func resourceVpcBandWidthV2Delete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + networkingClient, err := config.networkingV2Client(GetRegion(d, config)) + networkingV1Client, err := config.networkingV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating networking client: %s", err) + } + + err = bandwidths.Delete(networkingClient, d.Id()).ExtractErr() + if err != nil { + return fmt.Errorf("Error deleting HuaweiCloud Bandwidth: %s", err) + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{"ACTIVE"}, + Target: []string{"DELETED"}, + Refresh: waitForBandwidth(networkingV1Client, d.Id()), + Timeout: d.Timeout(schema.TimeoutDelete), + Delay: 3 * time.Second, + MinTimeout: 3 * time.Second, + } + + _, err = stateConf.WaitForState() + if err != nil { + return fmt.Errorf("Error deleting Bandwidth: %s", err) + } + + d.SetId("") + + return nil +} + +func waitForBandwidth(networkingClient *golangsdk.ServiceClient, Id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + b, err := bandwidthsv1.Get(networkingClient, Id).Extract() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + return b, "DELETED", nil + } + return nil, "", err + } + + log.Printf("[DEBUG] HuaweiCloud Bandwidth (%s) current status: %s", b.ID, b.Status) + return b, b.Status, nil + } +} diff --git a/huaweicloud/resource_huaweicloud_vpc_bandwidth_v2_test.go b/huaweicloud/resource_huaweicloud_vpc_bandwidth_v2_test.go new file mode 100644 index 0000000000..29b47c23b5 --- /dev/null +++ b/huaweicloud/resource_huaweicloud_vpc_bandwidth_v2_test.go @@ -0,0 +1,106 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + + "github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths" +) + +func TestAccVpcBandWidthV2_basic(t *testing.T) { + var bandwidth bandwidths.BandWidth + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcBandWidthV2Destroy, + Steps: []resource.TestStep{ + { + Config: testAccVpcBandWidthV2_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcBandWidthV2Exists("huaweicloud_vpc_bandwidth_v2.bandwidth_1", &bandwidth), + resource.TestCheckResourceAttr( + "huaweicloud_vpc_bandwidth_v2.bandwidth_1", "name", "bandwidth_1"), + ), + }, + { + Config: testAccVpcBandWidthV2_update, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcBandWidthV2Exists("huaweicloud_vpc_bandwidth_v2.bandwidth_1", &bandwidth), + resource.TestCheckResourceAttr( + "huaweicloud_vpc_bandwidth_v2.bandwidth_1", "name", "bandwidth_1_updated"), + resource.TestCheckResourceAttr( + "huaweicloud_vpc_bandwidth_v2.bandwidth_1", "size", "6"), + ), + }, + }, + }) +} + +func testAccCheckVpcBandWidthV2Destroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + networkingClient, err := config.networkingV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating huaweicloud networking client: %s", err) + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "huaweicloud_vpc_bandwidth_v2" { + continue + } + + _, err := bandwidths.Get(networkingClient, rs.Primary.ID).Extract() + if err == nil { + return fmt.Errorf("BandWidth still exists") + } + } + + return nil +} + +func testAccCheckVpcBandWidthV2Exists(n string, bandwidth *bandwidths.BandWidth) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No ID is set") + } + + config := testAccProvider.Meta().(*Config) + networkingClient, err := config.networkingV1Client(OS_REGION_NAME) + if err != nil { + return fmt.Errorf("Error creating huaweicloud networking client: %s", err) + } + + found, err := bandwidths.Get(networkingClient, rs.Primary.ID).Extract() + if err != nil { + return err + } + + if found.ID != rs.Primary.ID { + return fmt.Errorf("bandwidth not found") + } + + *bandwidth = found + + return nil + } +} + +const testAccVpcBandWidthV2_basic = ` +resource "huaweicloud_vpc_bandwidth_v2" "bandwidth_1" { + name = "bandwidth_1" + size = 5 +}` + +const testAccVpcBandWidthV2_update = ` +resource "huaweicloud_vpc_bandwidth_v2" "bandwidth_1" { + name = "bandwidth_1_updated" + size = 6 +}` diff --git a/huaweicloud/validators.go b/huaweicloud/validators.go index 7e9dc9bd92..ca3826b202 100644 --- a/huaweicloud/validators.go +++ b/huaweicloud/validators.go @@ -6,6 +6,8 @@ import ( "regexp" "strings" "time" + + "github.com/hashicorp/terraform/helper/schema" ) func ValidateStringList(v interface{}, k string, l []string) (ws []string, errors []error) { @@ -287,3 +289,14 @@ func validateECSTagValue(v interface{}, k string) (ws []string, errors []error) } return } + +func validateIntegerInRange(min, max int) schema.SchemaValidateFunc { + return func(v interface{}, k string) (ws []string, errors []error) { + value := v.(int) + if value < min || value > max { + errors = append(errors, fmt.Errorf( + "%q cannot be lower than %d and larger than %d. Current value is %d.", k, min, max, value)) + } + return + } +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go index 4246f564a7..37392a308e 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/client.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/client.go @@ -998,3 +998,9 @@ func NewSDKClient(c *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, servic return initClientOpts(c, eo, serviceType) } + +// NewCESV1 creates a ServiceClient that may be used with the v1 CES service. +func NewCESV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) { + sc, err := initClientOpts(client, eo, "cesv1") + return sc, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths/results.go index 496d93ef7d..5dac6847ba 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths/results.go @@ -14,6 +14,35 @@ type BandWidth struct { TenantID string `json:"tenant_id"` BandwidthType string `json:"bandwidth_type"` ChargeMode string `json:"charge_mode"` + + PublicipInfo []PublicIpinfo `json:"publicip_info"` + + // Specifies the billing information. + BillingInfo string `json:"billing_info"` + + // Enterprise project id + EnterpriseProjectID string `json:"enterprise_project_id"` + + // Status + Status string `json:"status"` +} + +type PublicIpinfo struct { + // Specifies the tenant ID of the user. + PublicipId string `json:"publicip_id"` + + // Specifies the elastic IP address. + PublicipAddress string `json:"publicip_address"` + + // Specifies the elastic IP v6 address. + Publicipv6Address string `json:"publicipv6_address"` + + // Specifies the elastic IP version. + IPVersion int `json:"ip_version"` + + // Specifies the elastic IP address type. The value can be + // 5_telcom, 5_union, or 5_bgp. + PublicipType string `json:"publicip_type"` } //GetResult is a return struct of get method diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/requests.go new file mode 100644 index 0000000000..b5535bdad8 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/requests.go @@ -0,0 +1,157 @@ +package bandwidths + +import ( + "github.com/huaweicloud/golangsdk" +) + +type UpdateOpts struct { + Bandwidth Bandwidth `json:"bandwidth" required:"true"` + ExtendParam *ExtendParam `json:"extendParam,omitempty"` +} +type Bandwidth struct { + Name string `json:"name,omitempty"` + Size int `json:"size,omitempty"` +} +type ExtendParam struct { + IsAutoPay string `json:"is_auto_pay,omitempty"` +} + +func (opts UpdateOpts) ToBandWidthUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "") +} + +type CreateOptsBuilder interface { + ToBandWidthCreateMap() (map[string]interface{}, error) +} + +type CreateOpts struct { + Name string `json:"name" required:"true"` + Size *int `json:"size" required:"true"` + EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` +} + +func (opts CreateOpts) ToBandWidthCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "bandwidth") +} + +func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToBandWidthCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(PostURL(client), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} + +type BatchCreateOptsBuilder interface { + ToBandWidthBatchCreateMap() (map[string]interface{}, error) +} + +type BatchCreateOpts struct { + Name string `json:"name" required:"true"` + Size *int `json:"size" required:"true"` + Count *int `json:"count" required:"true"` +} + +func (opts BatchCreateOpts) ToBandWidthBatchCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "bandwidth") +} + +type BandWidthInsertOptsBuilder interface { + ToBandWidthInsertMap() (map[string]interface{}, error) +} + +type BandWidthRemoveOptsBuilder interface { + ToBandWidthBatchRemoveMap() (map[string]interface{}, error) +} + +type BandWidthInsertOpts struct { + PublicipInfo []PublicIpInfoID `json:"publicip_info" required:"true"` +} + +func (opts BandWidthInsertOpts) ToBandWidthInsertMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "bandwidth") +} + +type BandWidthRemoveOpts struct { + ChargeMode string `json:"charge_mode" required:"true"` + Size *int `json:"size" required:"true"` + PublicipInfo []PublicIpInfoID `json:"publicip_info" required:"true"` +} + +func (opts BandWidthRemoveOpts) ToBandWidthBatchRemoveMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "bandwidth") +} + +type PublicIpInfoID struct { + PublicIPID string `json:"publicip_id" required:"true"` +} + +func Insert(client *golangsdk.ServiceClient, bandwidthID string, opts BandWidthInsertOptsBuilder) (r CreateResult) { + b, err := opts.ToBandWidthInsertMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(InsertURL(client, bandwidthID), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} + +func Remove(client *golangsdk.ServiceClient, bandwidthID string, opts BandWidthRemoveOptsBuilder) (r DeleteResult) { + b, err := opts.ToBandWidthBatchRemoveMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(RemoveURL(client, bandwidthID), b, nil, &golangsdk.RequestOpts{ + OkCodes: []int{200, 204}, + }) + return +} + +func BatchCreate(client *golangsdk.ServiceClient, opts BatchCreateOptsBuilder) (r BatchCreateResult) { + b, err := opts.ToBandWidthBatchCreateMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(BatchPostURL(client), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} + +func Delete(client *golangsdk.ServiceClient, bandwidthID string) (r DeleteResult) { + url := DeleteURL(client, bandwidthID) + _, r.Err = client.Delete(url, nil) + return +} + +func Update(c *golangsdk.ServiceClient, bandwidthID string, opts UpdateOpts) (interface{}, error) { + var r UpdateResult + body, err := opts.ToBandWidthUpdateMap() + if err != nil { + return nil, err + } + + _, r.Err = c.Put(UpdateURL(c, bandwidthID), body, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) + + onDemandData, onDemandErr := r.Extract() + orderData, orderErr := r.ExtractOrderID() + + if orderData.OrderID != "" { + return orderData, orderErr + } + + return onDemandData, onDemandErr + +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/results.go new file mode 100644 index 0000000000..377f7c05cb --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/results.go @@ -0,0 +1,131 @@ +package bandwidths + +import ( + "github.com/huaweicloud/golangsdk" +) + +type PrePaid struct { + OrderID string `json:"order_id"` +} + +type PostPaid struct { + Name string `json:"name"` + Size int `json:"size"` + ID string `json:"id"` + ShareType string `json:"share_type"` + ChargeMode string `json:"charge_mode"` + BandwidthType string `json:"bandwidth_type"` + TenantID string `json:"tenant_id"` + PublicipInfo []PublicipInfo `json:"publicip_info"` + EnterpriseProjectID string `json:"enterprise_project_id"` + //BillingInfo string `json:"billing_info"` +} + +type PublicipInfo struct { + PublicipID string `json:"publicip_id"` + PublicIPAddress string `json:"publicip_address"` + Publicipv6Address string `json:"publicipv_6_address"` + IpVersion int `json:"ip_version"` + PublicipType string `json:"publicip_type"` +} + +type UpdateResult struct { + golangsdk.Result +} + +func (r UpdateResult) ExtractOrderID() (PrePaid, error) { + var s PrePaid + err := r.ExtractInto(&s) + return s, err +} + +func (r UpdateResult) Extract() (PostPaid, error) { + var s struct { + Bandwidth PostPaid `json:"bandwidth"` + } + err := r.ExtractInto(&s) + return s.Bandwidth, err +} + +type CreateResult struct { + golangsdk.Result +} + +func (r CreateResult) Extract() (*BandWidth, error) { + var entity BandWidth + err := r.ExtractIntoStructPtr(&entity, "bandwidth") + return &entity, err +} + +type BatchCreateResult struct { + golangsdk.Result +} + +func (r BatchCreateResult) Extract() (*[]BandWidth, error) { + var entity []BandWidth + err := r.ExtractIntoSlicePtr(&entity, "bandwidths") + return &entity, err +} + +type BandWidth struct { + // Specifies the bandwidth name. The value is a string of 1 to 64 + // characters that can contain letters, digits, underscores (_), and hyphens (-). + Name string `json:"name"` + + // Specifies the bandwidth size. The value ranges from 1 Mbit/s to + // 300 Mbit/s. + Size int `json:"size"` + + // Specifies the bandwidth ID, which uniquely identifies the + // bandwidth. + ID string `json:"id"` + + // Specifies whether the bandwidth is shared or exclusive. The + // value can be PER or WHOLE. + ShareType string `json:"share_type"` + + // Specifies the elastic IP address of the bandwidth. The + // bandwidth, whose type is set to WHOLE, supports up to 20 elastic IP addresses. The + // bandwidth, whose type is set to PER, supports only one elastic IP address. + PublicipInfo []PublicIpinfo `json:"publicip_info"` + + // Specifies the tenant ID of the user. + TenantId string `json:"tenant_id"` + + // Specifies the bandwidth type. + BandwidthType string `json:"bandwidth_type"` + + // Specifies the charging mode (by traffic or by bandwidth). + ChargeMode string `json:"charge_mode"` + + // Specifies the billing information. + BillingInfo string `json:"billing_info"` + + // Enterprise project id + EnterpriseProjectID string `json:"enterprise_project_id"` + + // Status + Status string `json:"status"` +} + +type PublicIpinfo struct { + // Specifies the tenant ID of the user. + PublicipId string `json:"publicip_id"` + + // Specifies the elastic IP address. + PublicipAddress string `json:"publicip_address"` + + // Specifies the elastic IP v6 address. + Publicipv6Address string `json:"publicipv6_address"` + + // Specifies the elastic IP version. + IPVersion int `json:"ip_version"` + + // Specifies the elastic IP address type. The value can be + // 5_telcom, 5_union, or 5_bgp. + PublicipType string `json:"publicip_type"` +} + +type DeleteResult struct { + golangsdk.ErrResult +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/urls.go new file mode 100644 index 0000000000..57a51732e6 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths/urls.go @@ -0,0 +1,26 @@ +package bandwidths + +import "github.com/huaweicloud/golangsdk" + +func PostURL(c *golangsdk.ServiceClient) string { + return c.ServiceURL(c.ProjectID, "bandwidths") +} + +func BatchPostURL(c *golangsdk.ServiceClient) string { + return c.ServiceURL(c.ProjectID, "batch-bandwidths") +} +func UpdateURL(c *golangsdk.ServiceClient, ID string) string { + return c.ServiceURL(c.ProjectID, "bandwidths", ID) +} + +func DeleteURL(c *golangsdk.ServiceClient, ID string) string { + return c.ServiceURL(c.ProjectID, "bandwidths", ID) +} + +func InsertURL(c *golangsdk.ServiceClient, ID string) string { + return c.ServiceURL(c.ProjectID, "bandwidths", ID, "insert") +} + +func RemoveURL(c *golangsdk.ServiceClient, ID string) string { + return c.ServiceURL(c.ProjectID, "bandwidths", ID, "remove") +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8903d66348..4e62760a34 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -178,7 +178,7 @@ github.com/hashicorp/terraform/svchost/auth github.com/hashicorp/terraform-config-inspect/tfconfig # github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20190902122622-e395391e1f19 +# github.com/huaweicloud/golangsdk v0.0.0-20190906094835-10f659f0ae54 github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/openstack github.com/huaweicloud/golangsdk/openstack/antiddos/v1/antiddos @@ -240,6 +240,7 @@ github.com/huaweicloud/golangsdk/openstack/networking/v1/bandwidths github.com/huaweicloud/golangsdk/openstack/networking/v1/eips github.com/huaweicloud/golangsdk/openstack/networking/v1/subnets github.com/huaweicloud/golangsdk/openstack/networking/v1/vpcs +github.com/huaweicloud/golangsdk/openstack/networking/v2/bandwidths github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/elb github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/elb/backendecs github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/elb/healthcheck From 22834f685327aa94c95d730a74a4a48601d98830 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Mon, 9 Sep 2019 10:39:27 +0800 Subject: [PATCH 2/2] Add Shared Bandwidth V2 docs --- website/docs/r/vpc_bandwidth_v2.html.markdown | 52 +++++++++++++++++++ website/huaweicloud.erb | 3 ++ 2 files changed, 55 insertions(+) create mode 100644 website/docs/r/vpc_bandwidth_v2.html.markdown diff --git a/website/docs/r/vpc_bandwidth_v2.html.markdown b/website/docs/r/vpc_bandwidth_v2.html.markdown new file mode 100644 index 0000000000..0bb18dcb95 --- /dev/null +++ b/website/docs/r/vpc_bandwidth_v2.html.markdown @@ -0,0 +1,52 @@ +--- +layout: "huaweicloud" +page_title: "HuaweiCloud: huaweicloud_vpc_bandwidth_v2" +sidebar_current: "docs-huaweicloud-resource-vpc-bandwidth-v2" +description: |- + Manages a V2 Shared Bandwidth resource within HuaweiCloud. +--- + +# huaweicloud_vpc_bandwidth_v2 + +Manages a Shared Bandwidth resource within HuaweiCloud. + +## Example Usage + +```hcl +resource "huaweicloud_vpc_bandwidth_v2" "bandwidth_1" { + name = "bandwidth_1" + size = 5 +} + +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Shared Bandwidth. + +* `size` - (Required) The size of the Shared Bandwidth. The value ranges from 5 to 2000 G. + +* `enterprise_project_id` - (Optional) The enterprise project id of the Shared Bandwidth. Changing this creates a new bandwidth. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - ID of the Shared Bandwidth. + +* `name` - See Argument Reference above. + +* `size` - See Argument Reference above. + +* `enterprise_project_id` - See Argument Reference above. + +## Import + +Shared Bandwidths can be imported using the `id`, e.g. + +``` +$ terraform import huaweicloud_vpc_bandwidth_v2.bandwidth_1 7117d38e-4c8f-4624-a505-bd96b97d024c +``` diff --git a/website/huaweicloud.erb b/website/huaweicloud.erb index 6ca327d93d..f83c6ef753 100644 --- a/website/huaweicloud.erb +++ b/website/huaweicloud.erb @@ -521,6 +521,9 @@ > huaweicloud_networking_secgroup_rule_v2 + > + huaweicloud_vpc_bandwidth_v2 + > huaweicloud_vpc_eip_v1