From e1fe2e3932b0dd3ab8647783f8158f215ec55400 Mon Sep 17 00:00:00 2001 From: shichangkuo Date: Fri, 28 May 2021 11:35:46 +0800 Subject: [PATCH] add iec server data source and volume_attached block into iec server resource (#1169) * add volume_attached block into iec server resource * add iec server data source and docs --- docs/data-sources/iec_server.md | 64 ++++++ docs/resources/iec_server.md | 34 ++-- .../data_source_huaweicloud_iec_server.go | 183 +++++++++++++++++ ...data_source_huaweicloud_iec_server_test.go | 53 +++++ huaweicloud/provider.go | 1 + .../resource_huaweicloud_iec_server.go | 187 ++++++++++++++---- .../resource_huaweicloud_iec_server_test.go | 14 +- .../openstack/iec/v1/cloudvolumes/requests.go | 61 ++++++ .../openstack/iec/v1/cloudvolumes/results.go | 52 +++++ .../openstack/iec/v1/cloudvolumes/urls.go | 17 ++ vendor/modules.txt | 1 + 11 files changed, 612 insertions(+), 55 deletions(-) create mode 100644 docs/data-sources/iec_server.md create mode 100644 huaweicloud/data_source_huaweicloud_iec_server.go create mode 100644 huaweicloud/data_source_huaweicloud_iec_server_test.go create mode 100644 vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/requests.go create mode 100644 vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/results.go create mode 100644 vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/urls.go diff --git a/docs/data-sources/iec_server.md b/docs/data-sources/iec_server.md new file mode 100644 index 0000000000..35b9532548 --- /dev/null +++ b/docs/data-sources/iec_server.md @@ -0,0 +1,64 @@ +--- +subcategory: "Intelligent EdgeCloud (IEC)" +--- + +# huaweicloud_iec_server + +Use this data source to get the details of a specified IEC server. + +## Example Usage + +```hcl +variable "server_name" { } + +data "huaweicloud_iec_server" "demo" { + name = var.server_name +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required, String) Specifies the IEC server name, which can be queried with a regular expression. + +* `status` - (Optional, String) Specifies the status of IEC server. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The IEC server ID in UUID format. +* `edgecloud_id` - The ID of the edgecloud service. +* `edgecloud_name` - The Name of the edgecloud service. +* `coverage_sites` - An array of site ID and operator for the IEC server. + The object structure is documented below. +* `flavor_id` - The flavor ID of the IEC server. +* `flavor_name` - The flavor name of the IEC server. +* `image_name` - The image name of the IEC server. +* `vpc_id` - The ID of vpc for the IEC server. +* `security_groups` - An array of one or more security group IDs to associate with the IEC server. +* `nics` - An array of one or more networks to attach to the IEC server. + The object structure is documented below. +* `volume_attached` - An array of one or more disks to attach to the IEC server. + The object structure is documented below. +* `public_ip` - The EIP address that is associted to the IEC server. +* `system_disk_id` - The system disk voume ID. + +The `coverage_sites` block supports: + * `site_id` - The ID of IEC site. + * `site_info` - The located information of the IEC site. It contains area, province and city. + * `operator` - The operator of the IEC site. + +The `nics` block supports: + * `port` - The port ID corresponding to the IP address on that network. + * `mac` - The MAC address of the NIC on that network. + * `address` - The IPv4 address of the server on that network. + +The `volume_attached` block supports: + + * `volume_id` - The volume ID on that attachment. + * `boot_index` - The volume boot index on that attachment. + * `size` - The volume size on that attachment. + * `type` - The volume type on that attachment. + * `device` - The device name in the IEC server. diff --git a/docs/resources/iec_server.md b/docs/resources/iec_server.md index 13f269a8a3..fa2bf50178 100644 --- a/docs/resources/iec_server.md +++ b/docs/resources/iec_server.md @@ -43,9 +43,6 @@ resource "huaweicloud_iec_server" "server_test" { ### Server Instance With Multiple Data Disks -It's possible to specify multiple `data_disks` entries to create an server -with multiple data disks. - ```hcl variable "iec_server_name" {} variable "iec_iamge_id" {} @@ -164,12 +161,12 @@ The following arguments are supported: The `coverage_sites` block supports: - * `site_id` -(Required, String, ForceNew) Specifies the ID of IEC site. - * `operator` -(Required, String, ForceNew) Specifies the operator of the IEC site. + * `site_id` - (Required, String, ForceNew) Specifies the ID of IEC site. + * `operator` - (Required, String, ForceNew) Specifies the operator of the IEC site. The `data_disks` block supports: - * `type` -(Required, String, ForceNew) Specifies the type of data disk for the + * `type` - (Required, String, ForceNew) Specifies the type of data disk for the IEC server binding. Valid value is *SAS*(high I/O disk type). Changing this parameter creates a new IEC server resource. * `size` - (Required, String, ForceNew) Specifies the size of data disk for the @@ -182,14 +179,29 @@ In addition to all arguments above, the following attributes are exported: * `edgecloud_id` - The ID of the edgecloud service. * `edgecloud_name` - The Name of the edgecloud service. -* `nics` - An array of one or more network configuration for IEC server. -* `origin_server_id` : The ID of origin server. +* `image_name` - The image name of the IEC server. +* `flavor_name` - The flavor name of the IEC server. +* `nics` - An array of one or more networks to attach to the IEC server. + The object structure is documented below. +* `volume_attached` - An array of one or more disks to attach to the IEC server. + The object structure is documented below. +* `public_ip` - The EIP address that is associted to the IEC server. +* `system_disk_id` - The system disk voume ID. +* `origin_server_id` - The ID of origin server. * `status` - The status of IEC server. The `nics` block supports: - * `port` - The port of IEC server. - * `mac` - The mac address of IEC server. - * `address` - The address of EIP or VIP. + * `port` - The port ID corresponding to the IP address on that network. + * `mac` - The MAC address of the NIC on that network. + * `address` - The IPv4 address of the server on that network. + +The `volume_attached` block supports: + + * `volume_id` - The volume ID on that attachment. + * `boot_index` - The volume boot index on that attachment. + * `size` - The volume size on that attachment. + * `type` - The volume type on that attachment. + * `device` - The device name in the IEC server. ## Timeouts This resource provides the following timeouts configuration options: diff --git a/huaweicloud/data_source_huaweicloud_iec_server.go b/huaweicloud/data_source_huaweicloud_iec_server.go new file mode 100644 index 0000000000..48d53fe979 --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_iec_server.go @@ -0,0 +1,183 @@ +package huaweicloud + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/huaweicloud/golangsdk/openstack/iec/v1/servers" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" +) + +func dataSourceIECServer() *schema.Resource { + return &schema.Resource{ + Read: dataSourceIECServerRead, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + "edgecloud_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "status": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + + "flavor_id": { + Type: schema.TypeString, + Computed: true, + }, + "flavor_name": { + Type: schema.TypeString, + Computed: true, + }, + "image_id": { + Type: schema.TypeString, + Computed: true, + }, + "image_name": { + Type: schema.TypeString, + Computed: true, + }, + "key_pair": { + Type: schema.TypeString, + Computed: true, + }, + "user_data": { + Type: schema.TypeString, + Computed: true, + }, + "vpc_id": { + Type: schema.TypeString, + Computed: true, + }, + "security_groups": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "edgecloud_name": { + Type: schema.TypeString, + Computed: true, + }, + "coverage_sites": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "site_id": { + Type: schema.TypeString, + Computed: true, + }, + "site_info": { + Type: schema.TypeString, + Computed: true, + }, + "operator": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "nics": iecServerNicsSchema, + "volume_attached": iecVolumeAttachedSchema, + "public_ip": { + Type: schema.TypeString, + Computed: true, + }, + "system_disk_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceIECServerRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*config.Config) + iecClient, err := config.IECV1Client(GetRegion(d, config)) + if err != nil { + return fmt.Errorf("Error creating HuaweiCloud IEC client: %s", err) + } + + listOpts := &servers.ListOpts{ + Name: d.Get("name").(string), + Status: d.Get("status").(string), + EdgeCloudID: d.Get("edgecloud_id").(string), + } + + log.Printf("[DEBUG] searching the IEC server by filter: %#v", listOpts) + allServers, err := servers.List(iecClient, listOpts).Extract() + if err != nil { + return err + } + + total := len(allServers.Servers) + if total < 1 { + return fmt.Errorf("Your query returned no results. " + + "Please change your search criteria and try again.") + } + if total > 1 { + return fmt.Errorf("Your query returned more than one result. " + + "Please try a more specific search criteria.") + } + + server := allServers.Servers[0] + log.Printf("[DEBUG] fetching the IEC server: %#v", server) + + d.SetId(server.ID) + d.Set("name", server.Name) + d.Set("status", server.Status) + + flavorInfo := server.Flavor + d.Set("flavor_id", flavorInfo.ID) + d.Set("flavor_name", flavorInfo.Name) + d.Set("image_id", server.Image.ID) + d.Set("image_name", server.Metadata.ImageName) + + if server.KeyName != "" { + d.Set("key_pair", server.KeyName) + } + if server.UserData != "" { + d.Set("user_data", server.UserData) + } + + // set networking fields + d.Set("vpc_id", server.Metadata.VpcID) + secGrpIDs := make([]string, len(server.SecurityGroups)) + for i, sg := range server.SecurityGroups { + secGrpIDs[i] = sg.ID + } + d.Set("security_groups", secGrpIDs) + + allNics, eip := expandIecServerNics(&server) + d.Set("nics", allNics) + d.Set("public_ip", eip) + + // set volume fields + allVolumes, sysDiskID := expandIecServerVolumeAttached(iecClient, &server) + d.Set("volume_attached", allVolumes) + d.Set("system_disk_id", sysDiskID) + + // set IEC fields + location := server.Location + siteInfo := fmt.Sprintf("%s/%s/%s/%s", location.Country, location.Area, location.Province, location.City) + siteItem := map[string]interface{}{ + "site_id": location.ID, + "site_info": siteInfo, + "operator": server.Operator.Name, + } + d.Set("coverage_sites", []map[string]interface{}{siteItem}) + d.Set("edgecloud_id", server.EdgeCloudID) + d.Set("edgecloud_name", server.EdgeCloudName) + + return nil +} diff --git a/huaweicloud/data_source_huaweicloud_iec_server_test.go b/huaweicloud/data_source_huaweicloud_iec_server_test.go new file mode 100644 index 0000000000..c07b6cf0a4 --- /dev/null +++ b/huaweicloud/data_source_huaweicloud_iec_server_test.go @@ -0,0 +1,53 @@ +package huaweicloud + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccIECServerDataSource_basic(t *testing.T) { + rName := fmt.Sprintf("iec-%s", acctest.RandString(5)) + resourceName := "data.huaweicloud_iec_server.server_1" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckIecServerDestory, + Steps: []resource.TestStep{ + { + Config: testAccIecServer_basic(rName), + }, + { + Config: testAccIECServerDataSource_basic(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "name", "server-"+rName), + resource.TestCheckResourceAttr(resourceName, "image_name", "Ubuntu 16.04 server 64bit"), + resource.TestCheckResourceAttr(resourceName, "nics.#", "1"), + resource.TestCheckResourceAttr(resourceName, "security_groups.#", "1"), + resource.TestCheckResourceAttr(resourceName, "volume_attached.#", "1"), + resource.TestCheckResourceAttr(resourceName, "volume_attached.0.boot_index", "0"), + resource.TestCheckResourceAttr(resourceName, "volume_attached.0.type", "SAS"), + resource.TestCheckResourceAttr(resourceName, "volume_attached.0.size", "40"), + resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"), + resource.TestCheckResourceAttrSet(resourceName, "system_disk_id"), + resource.TestCheckResourceAttrSet(resourceName, "public_ip"), + resource.TestCheckResourceAttrSet(resourceName, "coverage_sites.0.site_id"), + resource.TestCheckResourceAttrSet(resourceName, "coverage_sites.0.site_info"), + ), + }, + }, + }) +} + +func testAccIECServerDataSource_basic(rName string) string { + return fmt.Sprintf(` +%s + +data "huaweicloud_iec_server" "server_1" { + name = huaweicloud_iec_server.server_test.name +} +`, testAccIecServer_basic(rName)) +} diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 05de045486..784764c59c 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -292,6 +292,7 @@ func Provider() terraform.ResourceProvider { "huaweicloud_iec_network_acl": dataSourceIECNetworkACL(), "huaweicloud_iec_port": DataSourceIECPort(), "huaweicloud_iec_security_group": dataSourceIECSecurityGroup(), + "huaweicloud_iec_server": dataSourceIECServer(), "huaweicloud_iec_sites": dataSourceIecSites(), "huaweicloud_iec_vpc": DataSourceIECVpc(), "huaweicloud_iec_vpc_subnets": DataSourceIECVpcSubnets(), diff --git a/huaweicloud/resource_huaweicloud_iec_server.go b/huaweicloud/resource_huaweicloud_iec_server.go index 71f664e2ac..9509b233e2 100644 --- a/huaweicloud/resource_huaweicloud_iec_server.go +++ b/huaweicloud/resource_huaweicloud_iec_server.go @@ -7,16 +7,68 @@ import ( "log" "time" + "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/huaweicloud/golangsdk" "github.com/huaweicloud/golangsdk/openstack/ecs/v1/cloudservers" + "github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes" "github.com/huaweicloud/golangsdk/openstack/iec/v1/common" "github.com/huaweicloud/golangsdk/openstack/iec/v1/servers" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) +var iecServerNicsSchema = &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "port": { + Type: schema.TypeString, + Computed: true, + }, + "mac": { + Type: schema.TypeString, + Computed: true, + }, + "address": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, +} + +var iecVolumeAttachedSchema = &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "volume_id": { + Type: schema.TypeString, + Computed: true, + }, + "boot_index": { + Type: schema.TypeString, + Computed: true, + }, + "device": { + Type: schema.TypeString, + Computed: true, + }, + "type": { + Type: schema.TypeString, + Computed: true, + }, + "size": { + Type: schema.TypeInt, + Computed: true, + }, + }, + }, +} + func resourceIecServer() *schema.Resource { return &schema.Resource{ Create: resourceIecServerV1Create, @@ -159,6 +211,8 @@ func resourceIecServer() *schema.Resource { } }, }, + + // computed fields "edgecloud_id": { Type: schema.TypeString, Computed: true, @@ -167,25 +221,23 @@ func resourceIecServer() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "nics": { - Type: schema.TypeList, + "flavor_name": { + Type: schema.TypeString, + Computed: true, + }, + "image_name": { + Type: schema.TypeString, + Computed: true, + }, + "nics": iecServerNicsSchema, + "volume_attached": iecVolumeAttachedSchema, + "public_ip": { + Type: schema.TypeString, + Computed: true, + }, + "system_disk_id": { + Type: schema.TypeString, Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "port": { - Type: schema.TypeString, - Computed: true, - }, - "mac": { - Type: schema.TypeString, - Computed: true, - }, - "address": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, }, "origin_server_id": { Type: schema.TypeString, @@ -252,7 +304,7 @@ func buildServerDataVolumes(d *schema.ResourceData) []common.DataVolume { return volList } -func resourceServerCoverage(d *schema.ResourceData) common.Coverage { +func buildServerCoverage(d *schema.ResourceData) common.Coverage { rawSites := d.Get("coverage_sites").([]interface{}) sitesList := make([]common.CoverageSite, len(rawSites)) @@ -304,7 +356,7 @@ func resourceIecServerV1Create(d *schema.ResourceData, meta interface{}) error { createOpts := servers.CreateOpts{ ResourceOpts: resourceOpts, - Coverage: resourceServerCoverage(d), + Coverage: buildServerCoverage(d), } log.Printf("[DEBUG] Create IEC servers options: %#v", createOpts) // Add password here so it wouldn't go in the above log entry @@ -343,7 +395,7 @@ func resourceIecServerV1Create(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error waiting for IEC server (%s) to become ready: %s", serverID, err) } - // CreateServer will add an prefix "IEC-CITY-" for the instance name, we should update it. + // CreateServer will add an prefix "IEC-xxx-" for the instance name, we should update it. serverName := d.Get("name").(string) updateOpts := servers.UpdateInstance{ UpdateServer: servers.UpdateOpts{ @@ -373,26 +425,32 @@ func resourceIecServerV1Read(d *schema.ResourceData, meta interface{}) error { edgeServer := servers.Server log.Printf("[DEBUG] Retrieved server %s: %+v", d.Id(), edgeServer) - d.Set("name", edgeServer.Name) - d.Set("status", edgeServer.Status) - d.Set("edgecloud_id", edgeServer.EdgeCloudID) - d.Set("edgecloud_name", edgeServer.EdgeCloudName) - d.Set("origin_server_id", edgeServer.ServerID) + allNics, eip := expandIecServerNics(edgeServer) + allVolumes, sysDiskID := expandIecServerVolumeAttached(iecClient, edgeServer) + + mErr := multierror.Append( + d.Set("name", edgeServer.Name), + d.Set("status", edgeServer.Status), + d.Set("edgecloud_id", edgeServer.EdgeCloudID), + d.Set("edgecloud_name", edgeServer.EdgeCloudName), + d.Set("origin_server_id", edgeServer.ServerID), + d.Set("flavor_id", edgeServer.Flavor.ID), + d.Set("flavor_name", edgeServer.Flavor.Name), + d.Set("image_name", edgeServer.Metadata.ImageName), + d.Set("nics", allNics), + d.Set("public_ip", eip), + d.Set("volume_attached", allVolumes), + d.Set("system_disk_id", sysDiskID), + ) + if err := mErr.ErrorOrNil(); err != nil { + return fmt.Errorf("Error setting fields: %s", err) + } - allNics := make([]map[string]interface{}, 0) - for _, val := range edgeServer.Addresses { - for _, nicRaw := range val { - nicItem := map[string]interface{}{ - "port": nicRaw.PortID, - "mac": nicRaw.MacAddr, - "address": nicRaw.Addr, - } - allNics = append(allNics, nicItem) - } + if vpcID := edgeServer.Metadata.VpcID; vpcID != "" { + d.Set("vpc_id", vpcID) } - log.Printf("[DEBUG] Retrieved all nic of server: %+v", allNics) - if err := d.Set("nics", allNics); err != nil { - return fmt.Errorf("Error setting nics of IEC server: %s", err) + if imageID := edgeServer.Image.ID; imageID != "" { + d.Set("image_id", imageID) } return nil @@ -483,3 +541,54 @@ func serverStateRefreshFunc(client *golangsdk.ServiceClient, id string) resource return s, s.Server.Status, nil } } + +func expandIecServerNics(edgeServer *servers.Server) ([]map[string]interface{}, string) { + var publicIP string + allNics := make([]map[string]interface{}, 0) + + for _, val := range edgeServer.Addresses { + for _, nicRaw := range val { + if nicRaw.Type == "floating" { + publicIP = nicRaw.Addr + continue + } + + nicItem := map[string]interface{}{ + "port": nicRaw.PortID, + "mac": nicRaw.MacAddr, + "address": nicRaw.Addr, + } + allNics = append(allNics, nicItem) + } + } + return allNics, publicIP +} + +func expandIecServerVolumeAttached(client *golangsdk.ServiceClient, edgeServer *servers.Server) ([]map[string]interface{}, string) { + var sysDiskID string + allVolumes := make([]map[string]interface{}, 0, len(edgeServer.VolumeAttached)) + + for _, disk := range edgeServer.VolumeAttached { + if disk.BootIndex == "0" { + sysDiskID = disk.ID + } + + volumeInfo, err := cloudvolumes.Get(client, disk.ID).Extract() + if err != nil { + log.Printf("[WARN] failed to retrieve volume %s: %s", disk.ID, err) + continue + } + + log.Printf("[DEBUG] Retrieved volume %s: %#v", disk.ID, volumeInfo) + volumeItem := map[string]interface{}{ + "volume_id": disk.ID, + "boot_index": disk.BootIndex, + "device": disk.Device, + "size": volumeInfo.Volume.Size, + "type": volumeInfo.Volume.VolumeType, + } + allVolumes = append(allVolumes, volumeItem) + } + + return allVolumes, sysDiskID +} diff --git a/huaweicloud/resource_huaweicloud_iec_server_test.go b/huaweicloud/resource_huaweicloud_iec_server_test.go index b43070cef5..a17c3c6261 100644 --- a/huaweicloud/resource_huaweicloud_iec_server_test.go +++ b/huaweicloud/resource_huaweicloud_iec_server_test.go @@ -26,12 +26,16 @@ func TestAccIecServerResource_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckIecServerExists(resourceName, &cloudserver), resource.TestCheckResourceAttr(resourceName, "name", "server-"+rName), - resource.TestCheckResourceAttr(resourceName, "nics.#", "2"), + resource.TestCheckResourceAttr(resourceName, "image_name", "Ubuntu 16.04 server 64bit"), + resource.TestCheckResourceAttr(resourceName, "nics.#", "1"), resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"), resource.TestCheckResourceAttr(resourceName, "security_groups.#", "1"), + resource.TestCheckResourceAttr(resourceName, "volume_attached.#", "1"), resource.TestCheckResourceAttr(resourceName, "system_disk_type", "SAS"), resource.TestCheckResourceAttr(resourceName, "system_disk_size", "40"), resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"), + resource.TestCheckResourceAttrSet(resourceName, "system_disk_id"), + resource.TestCheckResourceAttrSet(resourceName, "public_ip"), ), }, }, @@ -111,7 +115,7 @@ resource "huaweicloud_iec_vpc_subnet" "subnet_test" { name = "subnet-%s" cidr = "192.168.0.0/16" gateway_ip = "192.168.0.1" - vpc_id = huaweicloud_iec_vpc.vpc_test.id + vpc_id = huaweicloud_iec_vpc.vpc_test.id site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id } @@ -120,15 +124,15 @@ resource "huaweicloud_iec_keypair" "keypair_test" { } resource "huaweicloud_iec_security_group" "secgroup_test" { - name = "secgroup-%s" + name = "secgroup-%s" description = "this is a test group" } resource "huaweicloud_iec_security_group_rule" "rule_test" { - direction = "ingress" + direction = "ingress" port_range_min = 445 port_range_max = 445 - protocol = "tcp" + protocol = "tcp" security_group_id = huaweicloud_iec_security_group.secgroup_test.id remote_ip_prefix = "0.0.0.0/0" } diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/requests.go new file mode 100644 index 0000000000..a5820fd361 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/requests.go @@ -0,0 +1,61 @@ +package cloudvolumes + +import ( + "net/http" + + "github.com/huaweicloud/golangsdk" +) + +func Get(client *golangsdk.ServiceClient, CloudVolumeID string) (r GetResult) { + url := GetURL(client, CloudVolumeID) + _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{http.StatusOK}, + }) + return +} + +func ListVolumeType(client *golangsdk.ServiceClient) (r GetResult) { + url := ListVolumeTypeURL(client) + _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{http.StatusOK}, + }) + return +} + +// ListOpts holds options for listing Voulmes. It is passed to the List +// function. +type ListOpts struct { + Limit int `q:"limit"` + Offset int `q:"offset"` + Name string `q:"name"` + Status string `q:"status"` +} + +type ListOptsBuilder interface { + ToListVolumesQuery() (string, error) +} + +func (opts ListOpts) ToListVolumesQuery() (string, error) { + b, err := golangsdk.BuildQueryString(&opts) + if err != nil { + return "", err + } + return b.String(), nil +} + +func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) { + listURL := rootURL(client) + if opts != nil { + query, err := opts.ToListVolumesQuery() + if err != nil { + r.Err = err + return r + } + listURL += query + } + + _, r.Err = client.Get(listURL, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{http.StatusOK}, + }) + return +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/results.go new file mode 100644 index 0000000000..380956080e --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/results.go @@ -0,0 +1,52 @@ +package cloudvolumes + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/openstack/iec/v1/common" +) + +type commonResult struct { + golangsdk.Result +} + +type GetResult struct { + commonResult +} + +// EdgeVolume 云磁盘 +type EdgeVolume struct { + Volume *common.Volume `json:"volume"` +} + +func (r GetResult) Extract() (*EdgeVolume, error) { + var entity EdgeVolume + err := r.ExtractIntoStructPtr(&entity, "") + return &entity, err +} + +type VolumeType struct { + VolumeTypes []common.VolumeType `json:"volume_types"` +} + +func (r GetResult) ExtractVolumeType() (*VolumeType, error) { + var entity VolumeType + err := r.ExtractIntoStructPtr(&entity, "") + return &entity, err +} + +// Volumes 卷列表对象 +type Volumes struct { + Volumes []common.Volume `json:"volumes"` + Count int `json:"count"` +} + +type ListResult struct { + commonResult +} + +func (r ListResult) Extract() (*Volumes, error) { + var entity Volumes + + err := r.ExtractInto(&entity) + return &entity, err +} diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/urls.go b/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/urls.go new file mode 100644 index 0000000000..6fd96bee60 --- /dev/null +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes/urls.go @@ -0,0 +1,17 @@ +package cloudvolumes + +import ( + "github.com/huaweicloud/golangsdk" +) + +func rootURL(c *golangsdk.ServiceClient) string { + return c.ServiceURL("cloudvolumes") +} + +func GetURL(c *golangsdk.ServiceClient, CloudVolumeID string) string { + return c.ServiceURL("cloudvolumes", CloudVolumeID) +} + +func ListVolumeTypeURL(c *golangsdk.ServiceClient) string { + return c.ServiceURL("cloudvolumes", "volume-types") +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 1c8dc9df6c..2667ebd85b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -369,6 +369,7 @@ github.com/huaweicloud/golangsdk/openstack/identity/v3/projects github.com/huaweicloud/golangsdk/openstack/identity/v3/roles github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens github.com/huaweicloud/golangsdk/openstack/identity/v3/users +github.com/huaweicloud/golangsdk/openstack/iec/v1/cloudvolumes github.com/huaweicloud/golangsdk/openstack/iec/v1/common github.com/huaweicloud/golangsdk/openstack/iec/v1/firewalls github.com/huaweicloud/golangsdk/openstack/iec/v1/flavors