From e1e71512219be56455ad3a031dcdc6b6669d02d1 Mon Sep 17 00:00:00 2001 From: shichangkuo Date: Thu, 30 Nov 2023 21:22:31 +0800 Subject: [PATCH] chore(iec): normalize methods in services and acceptance (#3761) 1. remove IEC or Iec in both functions and vars; 2. remove v1 in both functions and vars; 3. use DataSourceCheck for data source; --- huaweicloud/provider.go | 34 +- huaweicloud/resource_huaweicloud_iec_eip.go | 304 --------- .../resource_huaweicloud_iec_eip_test.go | 107 ---- .../resource_huaweicloud_iec_network_acl.go | 215 ------- ...source_huaweicloud_iec_network_acl_rule.go | 315 ---------- ...e_huaweicloud_iec_network_acl_rule_test.go | 138 ---- ...source_huaweicloud_iec_network_acl_test.go | 194 ------ .../resource_huaweicloud_iec_server.go | 587 ------------------ .../resource_huaweicloud_iec_server_test.go | 162 ----- huaweicloud/resource_huaweicloud_iec_vpc.go | 144 ----- .../resource_huaweicloud_iec_vpc_subnet.go | 253 -------- ...esource_huaweicloud_iec_vpc_subnet_test.go | 147 ----- .../resource_huaweicloud_iec_vpc_test.go | 182 ------ ..._source_huaweicloud_iec_bandwidths_test.go | 17 - .../data_source_huaweicloud_iec_eips_test.go | 29 +- ...ata_source_huaweicloud_iec_flavors_test.go | 45 +- ...data_source_huaweicloud_iec_images_test.go | 30 +- ...ata_source_huaweicloud_iec_keypair_test.go | 17 +- .../data_source_huaweicloud_iec_port_test.go | 10 +- ...rce_huaweicloud_iec_security_group_test.go | 16 +- ...data_source_huaweicloud_iec_server_test.go | 42 +- .../data_source_huaweicloud_iec_sites_test.go | 35 +- ...source_huaweicloud_iec_vpc_subnets_test.go | 14 +- .../data_source_huaweicloud_iec_vpc_test.go | 14 +- .../iec/resource_huaweicloud_iec_eip_test.go | 14 +- .../resource_huaweicloud_iec_keypair_test.go | 2 +- ...e_huaweicloud_iec_network_acl_rule_test.go | 6 +- ...source_huaweicloud_iec_network_acl_test.go | 28 +- ...uaweicloud_iec_security_group_rule_test.go | 48 +- ...rce_huaweicloud_iec_security_group_test.go | 14 +- .../resource_huaweicloud_iec_server_test.go | 15 +- .../iec/resource_huaweicloud_iec_vip_test.go | 40 +- ...esource_huaweicloud_iec_vpc_subnet_test.go | 24 +- .../iec/resource_huaweicloud_iec_vpc_test.go | 40 +- .../data_source_huaweicloud_iec_bandwidths.go | 2 +- .../iec/data_source_huaweicloud_iec_eips.go | 8 +- .../data_source_huaweicloud_iec_flavors.go | 6 +- .../iec/data_source_huaweicloud_iec_images.go | 6 +- .../data_source_huaweicloud_iec_keypair.go | 6 +- ...data_source_huaweicloud_iec_network_acl.go | 2 +- .../iec/data_source_huaweicloud_iec_port.go | 8 +- ...a_source_huaweicloud_iec_security_group.go | 8 +- .../iec/data_source_huaweicloud_iec_server.go | 16 +- .../iec/data_source_huaweicloud_iec_sites.go | 8 +- .../iec/data_source_huaweicloud_iec_vpc.go | 6 +- ...data_source_huaweicloud_iec_vpc_subnets.go | 6 +- .../iec/resource_huaweicloud_iec_eip.go | 28 +- .../iec/resource_huaweicloud_iec_keypair.go | 6 +- .../resource_huaweicloud_iec_network_acl.go | 8 +- ...resource_huaweicloud_iec_security_group.go | 16 +- ...rce_huaweicloud_iec_security_group_rule.go | 16 +- .../iec/resource_huaweicloud_iec_server.go | 38 +- .../iec/resource_huaweicloud_iec_vip.go | 42 +- .../iec/resource_huaweicloud_iec_vpc.go | 22 +- .../resource_huaweicloud_iec_vpc_subnet.go | 32 +- 55 files changed, 362 insertions(+), 3210 deletions(-) delete mode 100644 huaweicloud/resource_huaweicloud_iec_eip.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_eip_test.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_network_acl.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_network_acl_rule.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_network_acl_rule_test.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_network_acl_test.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_server.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_server_test.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_vpc.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_vpc_subnet.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_vpc_subnet_test.go delete mode 100644 huaweicloud/resource_huaweicloud_iec_vpc_test.go diff --git a/huaweicloud/provider.go b/huaweicloud/provider.go index 36ab5014d6..56436ca3a2 100644 --- a/huaweicloud/provider.go +++ b/huaweicloud/provider.go @@ -512,17 +512,17 @@ func Provider() *schema.Provider { "huaweicloud_identitycenter_users": identitycenter.DataSourceIdentityCenterUsers(), "huaweicloud_iec_bandwidths": iec.DataSourceBandWidths(), - "huaweicloud_iec_eips": iec.DataSourceNetworkEips(), - "huaweicloud_iec_flavors": iec.DataSourceIecFlavors(), - "huaweicloud_iec_images": iec.DataSourceIecImages(), - "huaweicloud_iec_keypair": iec.DataSourceIECKeypair(), + "huaweicloud_iec_eips": iec.DataSourceEips(), + "huaweicloud_iec_flavors": iec.DataSourceFlavors(), + "huaweicloud_iec_images": iec.DataSourceImages(), + "huaweicloud_iec_keypair": iec.DataSourceKeypair(), "huaweicloud_iec_network_acl": iec.DataSourceNetworkACL(), - "huaweicloud_iec_port": iec.DataSourceIECPort(), - "huaweicloud_iec_security_group": iec.DataSourceIECSecurityGroup(), - "huaweicloud_iec_server": iec.DataSourceIECServer(), - "huaweicloud_iec_sites": iec.DataSourceIecSites(), - "huaweicloud_iec_vpc": iec.DataSourceIECVpc(), - "huaweicloud_iec_vpc_subnets": iec.DataSourceIECVpcSubnets(), + "huaweicloud_iec_port": iec.DataSourcePort(), + "huaweicloud_iec_security_group": iec.DataSourceSecurityGroup(), + "huaweicloud_iec_server": iec.DataSourceServer(), + "huaweicloud_iec_sites": iec.DataSourceSites(), + "huaweicloud_iec_vpc": iec.DataSourceVpc(), + "huaweicloud_iec_vpc_subnets": iec.DataSourceVpcSubnets(), "huaweicloud_images_image": ims.DataSourceImagesImageV2(), "huaweicloud_images_images": ims.DataSourceImagesImages(), @@ -1001,16 +1001,16 @@ func Provider() *schema.Provider { "huaweicloud_identitycenter_custom_policy_attachment": identitycenter.ResourceCustomPolicyAttachment(), "huaweicloud_identitycenter_custom_role_attachment": identitycenter.ResourceCustomRoleAttachment(), - "huaweicloud_iec_eip": iec.ResourceIecNetworkEip(), + "huaweicloud_iec_eip": iec.ResourceEip(), "huaweicloud_iec_keypair": iec.ResourceKeypair(), "huaweicloud_iec_network_acl": iec.ResourceNetworkACL(), "huaweicloud_iec_network_acl_rule": iec.ResourceNetworkACLRule(), - "huaweicloud_iec_security_group_rule": iec.ResourceIecSecurityGroupRule(), - "huaweicloud_iec_security_group": iec.ResourceIecSecurityGroup(), - "huaweicloud_iec_server": iec.ResourceIecServer(), - "huaweicloud_iec_vip": iec.ResourceIecVip(), - "huaweicloud_iec_vpc": iec.ResourceIecVpc(), - "huaweicloud_iec_vpc_subnet": iec.ResourceIecSubnet(), + "huaweicloud_iec_security_group_rule": iec.ResourceSecurityGroupRule(), + "huaweicloud_iec_security_group": iec.ResourceSecurityGroup(), + "huaweicloud_iec_server": iec.ResourceServer(), + "huaweicloud_iec_vip": iec.ResourceVip(), + "huaweicloud_iec_vpc": iec.ResourceVpc(), + "huaweicloud_iec_vpc_subnet": iec.ResourceSubnet(), "huaweicloud_images_image": ims.ResourceImsImage(), "huaweicloud_images_image_copy": ims.ResourceImsImageCopy(), diff --git a/huaweicloud/resource_huaweicloud_iec_eip.go b/huaweicloud/resource_huaweicloud_iec_eip.go deleted file mode 100644 index b1d87a9b4a..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_eip.go +++ /dev/null @@ -1,304 +0,0 @@ -package huaweicloud - -import ( - "strconv" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/chnsz/golangsdk" - "github.com/chnsz/golangsdk/openstack/iec/v1/publicips" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/eip" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp" -) - -func resourceIecNetworkEip() *schema.Resource { - return &schema.Resource{ - Create: resourceIecEipV1Create, - Read: resourceIecEipV1Read, - Update: resourceIecEipV1Update, - Delete: resourceIecEipV1Delete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(3 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "region": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - "site_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "line_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - "ip_version": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ValidateFunc: validation.IntInSlice([]int{4}), - Description: "schema: Computed", - }, - "port_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "public_ip": { - Type: schema.TypeString, - Computed: true, - }, - "private_ip": { - Type: schema.TypeString, - Computed: true, - }, - "bandwidth_id": { - Type: schema.TypeString, - Computed: true, - }, - "bandwidth_name": { - Type: schema.TypeString, - Computed: true, - }, - "bandwidth_size": { - Type: schema.TypeInt, - Computed: true, - }, - "bandwidth_share_type": { - Type: schema.TypeString, - Computed: true, - }, - "site_info": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func resourceIecEipV1Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - eipClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - createOpts := publicips.CreateOpts{ - Publicip: publicips.PublicIPRequest{ - SiteID: d.Get("site_id").(string), - Type: d.Get("line_id").(string), - }, - } - - ipVersion := d.Get("ip_version").(int) - if ipVersion != 0 { - createOpts.Publicip.IPVersion = strconv.Itoa(ipVersion) - } - - logp.Printf("[DEBUG] Create Options: %#v", createOpts) - n, err := publicips.Create(eipClient, createOpts).Extract() - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC public ip: %s", err) - } - - logp.Printf("[DEBUG] IEC publicips ID: %s", n.ID) - d.SetId(n.ID) - - logp.Printf("[DEBUG] Waiting for public ip (%s) to become active", d.Id()) - stateConf := &resource.StateChangeConf{ - Target: []string{"ACTIVE", "UNBOUND"}, - Refresh: waitForIecEipStatus(eipClient, d.Id()), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 5 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, stateErr := stateConf.WaitForState() - if stateErr != nil { - return fmtp.Errorf( - "Error waiting for public ip (%s) to become ACTIVE: %s", - d.Id(), stateErr) - } - - if bindPort := d.Get("port_id").(string); bindPort != "" { - logp.Printf("[DEBUG] bind public ip %s to port %s", d.Id(), bindPort) - if err := operateOnPort(d, eipClient, bindPort); err != nil { - return err - } - } - - return resourceIecEipV1Read(d, config) -} - -func resourceIecEipV1Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - eipClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - n, err := publicips.Get(eipClient, d.Id()).Extract() - if err != nil { - if _, ok := err.(golangsdk.ErrDefault404); ok { - d.SetId("") - return nil - } - if _, ok := err.(golangsdk.ErrDefault400); ok { - d.SetId("") - return nil - } - - return fmtp.Errorf("Error retrieving Huaweicloud IEC public ip: %s", err) - } - - logp.Printf("[DEBUG] IEC public ip %s: %+v", d.Id(), n) - - d.Set("site_id", n.SiteID) - d.Set("line_id", n.Type) - d.Set("port_id", n.PortID) - d.Set("public_ip", n.PublicIpAddress) - d.Set("private_ip", n.PrivateIpAddress) - d.Set("ip_version", n.IPVersion) - d.Set("bandwidth_id", n.BandwidthID) - d.Set("bandwidth_name", n.BandwidthName) - d.Set("bandwidth_size", n.BandwidthSize) - d.Set("bandwidth_share_type", n.BandwidthShareType) - d.Set("site_info", n.SiteInfo) - d.Set("status", eip.NormalizeEipStatus(n.Status)) - - return nil -} - -func resourceIecEipV1Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - eipClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - if d.HasChange("port_id") { - var opErr error - oPort, nPort := d.GetChange("port_id") - if oldPort := oPort.(string); oldPort != "" { - logp.Printf("[DEBUG] unbind public ip %s from port %s", d.Id(), oldPort) - opErr = operateOnPort(d, eipClient, "") - } - - if newPort := nPort.(string); newPort != "" { - logp.Printf("[DEBUG] bind public ip %s to port %s", d.Id(), newPort) - opErr = operateOnPort(d, eipClient, newPort) - } - - if opErr != nil { - return opErr - } - } - - return resourceIecEipV1Read(d, meta) -} - -func resourceIecEipV1Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - eipClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - // unbound the port before deleting the publicips - if port := d.Get("port_id").(string); port != "" { - logp.Printf("[DEBUG] unbind public ip %s from port %s", d.Id(), port) - if err := operateOnPort(d, eipClient, ""); err != nil { - return err - } - } - - err = publicips.Delete(eipClient, d.Id()).ExtractErr() - if err != nil { - return CheckDeleted(d, err, "Error deleting Huaweicloud IEC public ip") - } - - // waiting for public ip to become deleted - stateConf := &resource.StateChangeConf{ - Target: []string{"DELETED"}, - Refresh: waitForIecEipStatus(eipClient, d.Id()), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 5 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, stateErr := stateConf.WaitForState() - if stateErr != nil { - return fmtp.Errorf( - "Error waiting for Subnet (%s) to become deleted: %s", - d.Id(), stateErr) - } - - d.SetId("") - return nil -} - -func operateOnPort(d *schema.ResourceData, client *golangsdk.ServiceClient, port string) error { - updateOpts := publicips.UpdateOpts{ - PortId: port, - } - _, err := publicips.Update(client, d.Id(), updateOpts).Extract() - if err != nil { - var action string = "binding" - if port == "" { - action = "unbinding" - } - return fmtp.Errorf("Error %s Huaweicloud IEC public ip: %s", action, err) - } - return nil -} - -func waitForIecEipStatus(subnetClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - n, err := publicips.Get(subnetClient, id).Extract() - if err != nil { - if _, ok := err.(golangsdk.ErrDefault400); ok { - logp.Printf("[INFO] Successfully deleted Huaweicloud IEC public ip %s", id) - return n, "DELETED", nil - } - if _, ok := err.(golangsdk.ErrDefault404); ok { - logp.Printf("[INFO] Successfully deleted Huaweicloud IEC public ip %s", id) - return n, "DELETED", nil - } - - return n, "ERROR", err - } - - if n.Status == "ERROR" || n.Status == "BIND_ERROR" { - return n, n.Status, fmtp.Errorf("got error status with the public ip") - } - - // "DOWN" means the publicips is active but unbound - if n.Status == "DOWN" { - return n, "UNBOUND", nil - } - - return n, n.Status, nil - } -} diff --git a/huaweicloud/resource_huaweicloud_iec_eip_test.go b/huaweicloud/resource_huaweicloud_iec_eip_test.go deleted file mode 100644 index e052604b60..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_eip_test.go +++ /dev/null @@ -1,107 +0,0 @@ -package huaweicloud - -import ( - "regexp" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - iec_common "github.com/chnsz/golangsdk/openstack/iec/v1/common" - "github.com/chnsz/golangsdk/openstack/iec/v1/publicips" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" -) - -func TestAccIecEIPResource_basic(t *testing.T) { - var iecEip iec_common.PublicIP - resourceName := "huaweicloud_iec_eip.eip_test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecEIPDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIecEIP_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckIecEIPExists(resourceName, &iecEip), - resource.TestCheckResourceAttr(resourceName, "ip_version", "4"), - resource.TestCheckResourceAttr(resourceName, "bandwidth_share_type", "WHOLE"), - resource.TestMatchResourceAttr(resourceName, "public_ip", regexp.MustCompile("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")), - resource.TestCheckResourceAttrSet(resourceName, "site_info"), - resource.TestCheckResourceAttrSet(resourceName, "site_id"), - resource.TestCheckResourceAttrSet(resourceName, "line_id"), - resource.TestCheckResourceAttrSet(resourceName, "bandwidth_id"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccCheckIecEIPDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "huaweicloud_iec_eip" { - continue - } - - _, err := publicips.Get(iecV1Client, rs.Primary.ID).Extract() - if err == nil { - return fmtp.Errorf("IEC EIP still exists") - } - } - - return nil -} - -func testAccCheckIecEIPExists(n string, resource *iec_common.PublicIP) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmtp.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmtp.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - found, err := publicips.Get(iecV1Client, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmtp.Errorf("IEC EIP not found") - } - - *resource = *found - - return nil - } -} - -var testAccIecEIP_basic string = ` -data "huaweicloud_iec_sites" "sites_test" {} - -resource "huaweicloud_iec_eip" "eip_test" { - site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id -} -` diff --git a/huaweicloud/resource_huaweicloud_iec_network_acl.go b/huaweicloud/resource_huaweicloud_iec_network_acl.go deleted file mode 100644 index 26f12c6327..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_network_acl.go +++ /dev/null @@ -1,215 +0,0 @@ -package huaweicloud - -import ( - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/chnsz/golangsdk/openstack/iec/v1/firewalls" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp" -) - -func resourceIecNetworkACL() *schema.Resource { - return &schema.Resource{ - Create: resourceIecNetworkACLCreate, - Read: resourceIecNetworkACLRead, - Update: resourceIecNetworkACLUpdate, - Delete: resourceIecNetworkACLDelete, - 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, - }, - "description": { - Type: schema.TypeString, - Optional: true, - }, - "networks": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "vpc_id": { - Type: schema.TypeString, - Required: true, - }, - "subnet_id": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - "inbound_rules": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "outbound_rules": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func resourceIecNetworkACLNetworks(d *schema.ResourceData) []firewalls.ReqSubnet { - rawNetworks := d.Get("networks").(*schema.Set).List() - networkOpts := make([]firewalls.ReqSubnet, len(rawNetworks)) - - for i, val := range rawNetworks { - raw := val.(map[string]interface{}) - networkOpts[i] = firewalls.ReqSubnet{ - ID: raw["subnet_id"].(string), - VpcID: raw["vpc_id"].(string), - } - } - return networkOpts -} - -func resourceIecNetworkACLCreate(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - createOpts := firewalls.CreateOpts{ - Name: d.Get("name").(string), - Description: d.Get("description").(string), - } - logp.Printf("[DEBUG] Create IEC network acl: %#v", createOpts) - group, err := firewalls.Create(iecClient, createOpts).Extract() - if err != nil { - return fmtp.Errorf("Error creating IEC network acl: %s", err) - } - d.SetId(group.ID) - - // associate subnets - subnetsOpts := resourceIecNetworkACLNetworks(d) - if len(subnetsOpts) > 0 { - updateOpts := firewalls.UpdateOpts{ - Name: d.Get("name").(string), - Subnets: &subnetsOpts, - } - logp.Printf("[DEBUG] attempt to associate IEC network acl with subnets: %#v", updateOpts) - _, err := firewalls.Update(iecClient, group.ID, updateOpts).Extract() - if err != nil { - return fmtp.Errorf("Error associating subnets with IEC network acl: %s", err) - } - } - - return resourceIecNetworkACLRead(d, meta) -} - -func resourceIecNetworkACLRead(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - fwGroup, err := firewalls.Get(iecClient, d.Id()).Extract() - if err != nil { - return CheckDeleted(d, err, "iec network acl") - } - - logp.Printf("[DEBUG] Read HuaweiCloud IEC network acl %s: %#v", d.Id(), fwGroup) - d.Set("name", fwGroup.Name) - d.Set("status", fwGroup.Status) - d.Set("description", fwGroup.Description) - d.Set("inbound_rules", getFirewallRuleIDs(fwGroup.IngressFWPolicy)) - d.Set("outbound_rules", getFirewallRuleIDs(fwGroup.EgressFWPolicy)) - var networkSet []map[string]interface{} - for _, val := range fwGroup.Subnets { - subnet := make(map[string]interface{}) - subnet["vpc_id"] = val.VpcID - subnet["subnet_id"] = val.ID - networkSet = append(networkSet, subnet) - } - if err = d.Set("networks", networkSet); err != nil { - return fmtp.Errorf("Saving iec networks failed: %s", err) - } - - return nil -} - -func resourceIecNetworkACLUpdate(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - if d.HasChanges("name", "description", "networks") { - opts := firewalls.UpdateOpts{ - Name: d.Get("name").(string), - } - - if d.HasChange("description") { - desc := d.Get("description").(string) - opts.Description = &desc - } - - if d.HasChange("networks") { - subnetsOpts := resourceIecNetworkACLNetworks(d) - opts.Subnets = &subnetsOpts - } - - logp.Printf("[DEBUG] Updating IEC network acl with id %s: %#v", d.Id(), opts) - _, err := firewalls.Update(iecClient, d.Id(), opts).Extract() - if err != nil { - return fmtp.Errorf("Error updating IEC network acl: %s", err) - } - } - - return resourceIecNetworkACLRead(d, meta) -} - -func resourceIecNetworkACLDelete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - // unbind subents before deleting the network acl - rawNetworks := d.Get("networks").(*schema.Set).List() - if len(rawNetworks) > 0 { - unbindSubnets := make([]firewalls.ReqSubnet, 0) - opts := firewalls.UpdateOpts{ - Name: d.Get("name").(string), - Subnets: &unbindSubnets, - } - err = firewalls.Update(iecClient, d.Id(), opts).Err - if err != nil { - return fmtp.Errorf("Error disassociating all subents with IEC network acl: %s", err) - } - } - - err = firewalls.Delete(iecClient, d.Id()).ExtractErr() - if err != nil { - return fmtp.Errorf("Error deleting HuaweiCloud iec firewall: %s", err) - } - - d.SetId("") - return nil -} diff --git a/huaweicloud/resource_huaweicloud_iec_network_acl_rule.go b/huaweicloud/resource_huaweicloud_iec_network_acl_rule.go deleted file mode 100644 index ae05dba58d..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_network_acl_rule.go +++ /dev/null @@ -1,315 +0,0 @@ -package huaweicloud - -import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/chnsz/golangsdk/openstack/iec/v1/firewalls" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp" -) - -func resourceIecNetworkACLRule() *schema.Resource { - return &schema.Resource{ - Create: resourceIecNetworkACLRuleCreate, - Read: resourceIecNetworkACLRuleRead, - Update: resourceIecNetworkACLRuleUpdate, - Delete: resourceIecNetworkACLRuleDelete, - - Schema: map[string]*schema.Schema{ - "network_acl_id": { - Type: schema.TypeString, - Required: true, - }, - "direction": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - "ingress", "egress", - }, true), - }, - "description": { - Type: schema.TypeString, - Optional: true, - }, - "protocol": { - Type: schema.TypeString, - Optional: true, - Default: "any", - ValidateFunc: validation.StringInSlice([]string{ - "tcp", "udp", "icmp", "any", - }, true), - }, - "action": { - Type: schema.TypeString, - Optional: true, - Default: "allow", - ValidateFunc: validation.StringInSlice([]string{ - "allow", "deny", - }, true), - }, - "ip_version": { - Type: schema.TypeInt, - Optional: true, - Default: 4, - Description: "schema: Computed", - }, - "source_ip_address": { - Type: schema.TypeString, - Optional: true, - Default: "0.0.0.0/0", - }, - "destination_ip_address": { - Type: schema.TypeString, - Optional: true, - Default: "0.0.0.0/0", - }, - "source_port": { - Type: schema.TypeString, - Optional: true, - }, - "destination_port": { - Type: schema.TypeString, - Optional: true, - }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "policy_id": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func buildNetworkACLRule(d *schema.ResourceData, operateType, ruleID string) firewalls.ReqFirewallRulesOpts { - enabled := d.Get("enabled").(bool) - ruleOpts := firewalls.ReqFirewallRulesOpts{ - Description: d.Get("description").(string), - Action: d.Get("action").(string), - IPVersion: d.Get("ip_version").(int), - Protocol: d.Get("protocol").(string), - SrcIPAddr: d.Get("source_ip_address").(string), - DstIPAddr: d.Get("destination_ip_address").(string), - SrcPort: d.Get("source_port").(string), - DstPort: d.Get("destination_port").(string), - Enabled: &enabled, - OperateType: operateType, - } - if operateType != "add" { - ruleOpts.ID = ruleID - } - return ruleOpts -} - -func resourceIecNetworkACLRuleCreate(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud fw client: %s", err) - } - - aclID := d.Get("network_acl_id").(string) - fwGroup, err := firewalls.Get(iecClient, aclID).Extract() - if err != nil { - return fmtp.Errorf("Error retrieving IEC network acl %s: %s", aclID, err) - } - - var oldRules, newRules []string - var opts firewalls.UpdateRuleOpts - var ruleOpts firewalls.ReqPolicyOpts - ruleOpts.FirewallRules = &[]firewalls.ReqFirewallRulesOpts{ - buildNetworkACLRule(d, "add", ""), - } - if d.Get("direction").(string) == "ingress" { - oldRules = getFirewallRuleIDs(fwGroup.IngressFWPolicy) - ruleOpts.PolicyID = fwGroup.IngressFWPolicy.ID - opts.ReqFirewallInPolicy = &ruleOpts - } else { - oldRules = getFirewallRuleIDs(fwGroup.EgressFWPolicy) - ruleOpts.PolicyID = fwGroup.EgressFWPolicy.ID - opts.ReqFirewallOutPolicy = &ruleOpts - } - - logp.Printf("[DEBUG] Create IEC Network ACL rule: %#v", opts) - fwGroup, err = firewalls.UpdateRule(iecClient, aclID, opts).Extract() - if err != nil { - return fmtp.Errorf("Error creating IEC Network ACL rule: %s", err) - } - - if d.Get("direction").(string) == "ingress" { - newRules = getFirewallRuleIDs(fwGroup.IngressFWPolicy) - } else { - newRules = getFirewallRuleIDs(fwGroup.EgressFWPolicy) - } - - ruleID := getNewFirewallRuleID(oldRules, newRules) - if ruleID == "" { - return fmtp.Errorf("Error creating IEC Network ACL rule: not found") - } - - logp.Printf("[DEBUG] Create Network IEC ACL rule with id %s", ruleID) - d.SetId(ruleID) - - return resourceIecNetworkACLRuleRead(d, meta) -} - -func resourceIecNetworkACLRuleRead(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - aclID := d.Get("network_acl_id").(string) - fwGroup, err := firewalls.Get(iecClient, aclID).Extract() - if err != nil { - return CheckDeleted(d, err, "iec network acl") - } - - var fwPolicy firewalls.RespPolicyEntity - if d.Get("direction").(string) == "ingress" { - fwPolicy = fwGroup.IngressFWPolicy - } else { - fwPolicy = fwGroup.EgressFWPolicy - } - - ruleID := d.Id() - ruleEntity := getFirewallRuleEntity(fwPolicy, ruleID) - if ruleEntity.ID == "" { - d.SetId("") - logp.Printf("[WARN] the IEC Network ACL rule: %s can not be found", ruleID) - return nil - } - - logp.Printf("[DEBUG] Retrieve IEC Network ACL rule %s: %#v", ruleID, ruleEntity) - d.Set("policy_id", fwPolicy.ID) - d.Set("description", ruleEntity.Description) - d.Set("enabled", ruleEntity.Enabled) - d.Set("action", ruleEntity.Action) - d.Set("ip_version", ruleEntity.IPVersion) - d.Set("source_ip_address", ruleEntity.SrcIPAddr) - d.Set("destination_ip_address", ruleEntity.DstIPAddr) - d.Set("source_port", ruleEntity.SrcPort) - d.Set("destination_port", ruleEntity.DstPort) - - if ruleEntity.Protocol == "" { - d.Set("protocol", "any") - } else { - d.Set("protocol", ruleEntity.Protocol) - } - - return nil -} - -func resourceIecNetworkACLRuleUpdate(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud fw client: %s", err) - } - - aclID := d.Get("network_acl_id").(string) - fwGroup, err := firewalls.Get(iecClient, aclID).Extract() - if err != nil { - return fmtp.Errorf("Error retrieving IEC network acl %s: %s", aclID, err) - } - - var opts firewalls.UpdateRuleOpts - var ruleOpts firewalls.ReqPolicyOpts - ruleOpts.FirewallRules = &[]firewalls.ReqFirewallRulesOpts{ - buildNetworkACLRule(d, "modify", d.Id()), - } - - if d.Get("direction").(string) == "ingress" { - ruleOpts.PolicyID = fwGroup.IngressFWPolicy.ID - opts.ReqFirewallInPolicy = &ruleOpts - } else { - ruleOpts.PolicyID = fwGroup.EgressFWPolicy.ID - opts.ReqFirewallOutPolicy = &ruleOpts - } - - logp.Printf("[DEBUG] Updating IEC Network ACL rule %s: %#v", d.Id(), opts) - _, err = firewalls.UpdateRule(iecClient, aclID, opts).Extract() - - if err != nil { - return fmtp.Errorf("Error updating IEC Network ACL rule: %s", err) - } - - return resourceIecNetworkACLRuleRead(d, meta) -} - -func resourceIecNetworkACLRuleDelete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud fw client: %s", err) - } - - aclID := d.Get("network_acl_id").(string) - fwGroup, err := firewalls.Get(iecClient, aclID).Extract() - if err != nil { - return fmtp.Errorf("Error retrieving IEC network acl %s: %s", aclID, err) - } - - var opts firewalls.UpdateRuleOpts - var ruleOpts firewalls.ReqPolicyOpts - ruleOpts.FirewallRules = &[]firewalls.ReqFirewallRulesOpts{ - buildNetworkACLRule(d, "delete", d.Id()), - } - if d.Get("direction").(string) == "ingress" { - ruleOpts.PolicyID = fwGroup.IngressFWPolicy.ID - opts.ReqFirewallInPolicy = &ruleOpts - - } else { - ruleOpts.PolicyID = fwGroup.EgressFWPolicy.ID - opts.ReqFirewallOutPolicy = &ruleOpts - } - - logp.Printf("[DEBUG] Destroy IEC Network ACL rule: %s", d.Id()) - _, err = firewalls.UpdateRule(iecClient, aclID, opts).Extract() - if err != nil { - return fmtp.Errorf("Error deleting IEC Network ACL rule: %s", err) - } - - d.SetId("") - return nil -} - -func getFirewallRuleIDs(fwPolicy firewalls.RespPolicyEntity) []string { - rawRules := fwPolicy.FirewallRules - ruleIDs := make([]string, len(rawRules)) - for i, val := range rawRules { - ruleIDs[i] = val.ID - } - return ruleIDs -} - -func getFirewallRuleEntity(fwPolicy firewalls.RespPolicyEntity, ruleID string) firewalls.RespFirewallRulesEntity { - for _, val := range fwPolicy.FirewallRules { - if val.ID == ruleID { - return val - } - } - return firewalls.RespFirewallRulesEntity{} -} - -func getNewFirewallRuleID(old []string, new []string) string { - ruleMap := make(map[string]int) - for _, v := range old { - ruleMap[v] = 1 - } - - for _, v := range new { - if ruleMap[v] == 0 { - return v - } - } - return "" -} diff --git a/huaweicloud/resource_huaweicloud_iec_network_acl_rule_test.go b/huaweicloud/resource_huaweicloud_iec_network_acl_rule_test.go deleted file mode 100644 index 4d4f79176b..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_network_acl_rule_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package huaweicloud - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - "github.com/chnsz/golangsdk/openstack/iec/v1/firewalls" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" -) - -func TestAccIecNetworkACLRuleResource_basic(t *testing.T) { - aclResourceName := "huaweicloud_iec_network_acl.acl_test" - aclRuleResourceName := "huaweicloud_iec_network_acl_rule.rule_test" - var fwGroup firewalls.RespFirewallRulesEntity - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecNetworkACLDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIecNetworkACLRule_basic(), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecNetworkACLRuleExists(aclResourceName, "ingress", &fwGroup), - resource.TestCheckResourceAttrPtr(aclRuleResourceName, "protocol", &fwGroup.Protocol), - resource.TestCheckResourceAttrPtr(aclRuleResourceName, "action", &fwGroup.Action), - resource.TestCheckResourceAttrPtr(aclRuleResourceName, "destination_port", &fwGroup.DstPort), - ), - }, - { - Config: testAccIecNetworkACLRule_basic_update(), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecNetworkACLRuleExists(aclResourceName, "ingress", &fwGroup), - resource.TestCheckResourceAttrPtr(aclRuleResourceName, "protocol", &fwGroup.Protocol), - resource.TestCheckResourceAttrPtr(aclRuleResourceName, "action", &fwGroup.Action), - resource.TestCheckResourceAttrPtr(aclRuleResourceName, "destination_port", &fwGroup.DstPort), - ), - }, - }, - }) -} - -func testAccCheckIecNetworkACLRuleDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "huaweicloud_iec_network_acl" { - continue - } - - _, err := firewalls.Get(iecV1Client, rs.Primary.ID).Extract() - if err == nil { - return fmtp.Errorf("IEC network acl still exists") - } - } - - return nil -} - -func testAccCheckIecNetworkACLRuleExists(n, direction string, resource *firewalls.RespFirewallRulesEntity) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmtp.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmtp.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - found, err := firewalls.Get(iecV1Client, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if direction == "ingress" { - *resource = found.IngressFWPolicy.FirewallRules[0] - } else if direction == "egress" { - *resource = found.EgressFWPolicy.FirewallRules[0] - } else { - return fmtp.Errorf("IEC Network ACL Rule not found") - } - - return nil - } -} - -func testAccIecNetworkACLRule_basic() string { - return ` -resource "huaweicloud_iec_network_acl" "acl_test" { - name = "iec-acl-basic" -} - -resource "huaweicloud_iec_network_acl_rule" "rule_test" { - network_acl_id = huaweicloud_iec_network_acl.acl_test.id - direction = "ingress" - protocol = "tcp" - action = "allow" - source_ip_address = "0.0.0.0/0" - destination_ip_address = "0.0.0.0/0" - destination_port = "445" - enabled = true -} -` -} - -func testAccIecNetworkACLRule_basic_update() string { - return ` -resource "huaweicloud_iec_network_acl" "acl_test" { - name = "iec-acl-update" -} - -resource "huaweicloud_iec_network_acl_rule" "rule_test" { - network_acl_id = huaweicloud_iec_network_acl.acl_test.id - direction = "ingress" - protocol = "udp" - action = "deny" - source_ip_address = "0.0.0.0/0" - destination_ip_address = "0.0.0.0/0" - destination_port = "23-30" - enabled = true -} -` -} diff --git a/huaweicloud/resource_huaweicloud_iec_network_acl_test.go b/huaweicloud/resource_huaweicloud_iec_network_acl_test.go deleted file mode 100644 index ce8ed10375..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_network_acl_test.go +++ /dev/null @@ -1,194 +0,0 @@ -package huaweicloud - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - "github.com/chnsz/golangsdk/openstack/iec/v1/firewalls" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" -) - -func TestAccIecNetworkACLResource_basic(t *testing.T) { - rName := fmt.Sprintf("iec-acl-%s", acctest.RandString(5)) - resourceKey := "huaweicloud_iec_network_acl.acl_demo" - var fwGroup firewalls.Firewall - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecNetworkACLDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIecNetworkACL_basic(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecNetworkACLExists(resourceKey, &fwGroup), - resource.TestCheckResourceAttr(resourceKey, "name", rName), - resource.TestCheckResourceAttr(resourceKey, "description", "Created by terraform test acc"), - testAccCheckIecNetworkACLNetBlockExists(&fwGroup), - ), - }, - { - ResourceName: resourceKey, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccIecNetworkACL_basic_update(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecNetworkACLExists(resourceKey, &fwGroup), - resource.TestCheckResourceAttr(resourceKey, "name", rName+"-update"), - resource.TestCheckResourceAttr(resourceKey, "description", "Updated by terraform test acc"), - testAccCheckIecNetworkACLNetBlockExists(&fwGroup), - ), - }, - }, - }) -} - -func TestAccIecNetworkACLResource_no_subnets(t *testing.T) { - rName := fmt.Sprintf("acc-fw-%s", acctest.RandString(5)) - resourceKey := "huaweicloud_iec_network_acl.acl_demo" - var fwGroup firewalls.Firewall - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecNetworkACLDestroy, - Steps: []resource.TestStep{ - { - Config: testAccIecNetworkACL_no_subnets(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecNetworkACLExists(resourceKey, &fwGroup), - resource.TestCheckResourceAttr(resourceKey, "name", rName+"-noSubnet"), - resource.TestCheckResourceAttr(resourceKey, "description", "Iec network acl without subents"), - resource.TestCheckResourceAttr(resourceKey, "status", "INACTIVE"), - ), - }, - }, - }) -} - -func testAccCheckIecNetworkACLDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "huaweicloud_iec_network_acl" { - continue - } - - _, err := firewalls.Get(iecV1Client, rs.Primary.ID).Extract() - if err == nil { - return fmtp.Errorf("IEC network acl still exists") - } - } - - return nil -} - -func testAccCheckIecNetworkACLExists(n string, resource *firewalls.Firewall) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmtp.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmtp.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - found, err := firewalls.Get(iecV1Client, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmtp.Errorf("IEC Network ACL not found") - } - - *resource = *found - - return nil - } -} - -func testAccCheckIecNetworkACLNetBlockExists(resource *firewalls.Firewall) resource.TestCheckFunc { - return func(s *terraform.State) error { - if len(resource.Subnets) == 0 { - return fmtp.Errorf("The Subnet of IEC Network ACL is not set.") - } - return nil - } -} - -var testAccIecNetworkACLRules string = ` -data "huaweicloud_iec_sites" "sites_test" {} - -resource "huaweicloud_iec_vpc" "vpc_test" { - name = "vpc_demo" - cidr = "192.168.0.0/16" - mode = "CUSTOMER" -} - -resource "huaweicloud_iec_vpc_subnet" "subnet_test" { - name = "subnet_demo" - cidr = "192.168.128.0/18" - vpc_id = huaweicloud_iec_vpc.vpc_test.id - site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id - gateway_ip = "192.168.128.3" -} -` - -func testAccIecNetworkACL_basic(rName string) string { - return fmt.Sprintf(` -%s - -resource "huaweicloud_iec_network_acl" "acl_demo" { - name = "%s" - description = "Created by terraform test acc" - networks { - vpc_id = huaweicloud_iec_vpc.vpc_test.id - subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id - } -} -`, testAccIecNetworkACLRules, rName) -} - -func testAccIecNetworkACL_basic_update(rName string) string { - return fmt.Sprintf(` -%s - -resource "huaweicloud_iec_network_acl" "acl_demo" { - name = "%s-update" - description = "Updated by terraform test acc" - networks { - vpc_id = huaweicloud_iec_vpc.vpc_test.id - subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id - } -} -`, testAccIecNetworkACLRules, rName) -} - -func testAccIecNetworkACL_no_subnets(rName string) string { - return fmt.Sprintf(` -resource "huaweicloud_iec_network_acl" "acl_demo" { - name = "%s-noSubnet" - description = "Iec network acl without subents" -} -`, rName) -} diff --git a/huaweicloud/resource_huaweicloud_iec_server.go b/huaweicloud/resource_huaweicloud_iec_server.go deleted file mode 100644 index da035030b9..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_server.go +++ /dev/null @@ -1,587 +0,0 @@ -package huaweicloud - -import ( - "time" - - "github.com/hashicorp/go-multierror" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - - "github.com/chnsz/golangsdk" - "github.com/chnsz/golangsdk/openstack/ecs/v1/cloudservers" - "github.com/chnsz/golangsdk/openstack/iec/v1/cloudvolumes" - "github.com/chnsz/golangsdk/openstack/iec/v1/common" - "github.com/chnsz/golangsdk/openstack/iec/v1/servers" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp" -) - -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, - Read: resourceIecServerV1Read, - Update: resourceIecServerV1Update, - Delete: resourceIecServerV1Delete, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: false, - }, - "flavor_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "image_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "system_disk_size": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - }, - "system_disk_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "vpc_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "subnet_ids": { - Type: schema.TypeList, - Required: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "security_groups": { - Type: schema.TypeSet, - Required: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "coverage_sites": { - Type: schema.TypeList, - Required: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "site_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "operator": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - }, - }, - }, - "admin_pass": { - Type: schema.TypeString, - Sensitive: true, - Optional: true, - ForceNew: true, - ExactlyOneOf: []string{"admin_pass", "key_pair"}, - }, - "key_pair": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "bind_eip": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - }, - "coverage_level": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "SITE", - }, - "coverage_policy": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "centralize", - ValidateFunc: validation.StringInSlice([]string{ - "centralize", "discrete", - }, true), - }, - "data_disks": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 2, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "size": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - }, - }, - }, - }, - "user_data": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - // just stash the hash for state & diff comparisons - StateFunc: utils.HashAndHexEncode, - }, - - // computed fields - "edgecloud_id": { - Type: schema.TypeString, - Computed: true, - }, - "edgecloud_name": { - Type: schema.TypeString, - Computed: true, - }, - "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, - }, - "origin_server_id": { - Type: schema.TypeString, - Computed: true, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func buildServerSecGroups(d *schema.ResourceData) []common.SecurityGroup { - rawSecGroups := d.Get("security_groups").(*schema.Set).List() - secgroups := make([]common.SecurityGroup, len(rawSecGroups)) - - for i, raw := range rawSecGroups { - secgroups[i] = common.SecurityGroup{ - ID: raw.(string), - } - } - return secgroups -} - -func buildNetworkConfig(d *schema.ResourceData) common.NetConfig { - netOpts := common.NetConfig{} - - rawSubnets := d.Get("subnet_ids").([]interface{}) - subents := make([]common.SubnetID, len(rawSubnets)) - for i, raw := range rawSubnets { - subents[i] = common.SubnetID{ - ID: raw.(string), - } - } - netOpts.Subnets = subents - netOpts.VpcID = d.Get("vpc_id").(string) - netOpts.NicNum = len(rawSubnets) - - return netOpts -} - -func buildServerRootVolume(d *schema.ResourceData) common.RootVolume { - rootVolume := common.RootVolume{ - VolumeType: d.Get("system_disk_type").(string), - Size: d.Get("system_disk_size").(int), - } - - return rootVolume -} - -func buildServerDataVolumes(d *schema.ResourceData) []common.DataVolume { - rawVols := d.Get("data_disks").([]interface{}) - volList := make([]common.DataVolume, len(rawVols)) - - for i, v := range rawVols { - vol := v.(map[string]interface{}) - volList[i] = common.DataVolume{ - VolumeType: vol["type"].(string), - Size: vol["size"].(int), - } - } - - return volList -} - -func buildServerCoverage(d *schema.ResourceData) common.Coverage { - rawSites := d.Get("coverage_sites").([]interface{}) - sitesList := make([]common.CoverageSite, len(rawSites)) - - for i, v := range rawSites { - site := v.(map[string]interface{}) - sitesList[i] = common.CoverageSite{ - Site: site["site_id"].(string), - Demands: []common.Demand{ - { - Operator: site["operator"].(string), - Count: 1, - }, - }, - } - } - - var coverageOpts = common.Coverage{ - CoveragePolicy: d.Get("coverage_policy").(string), - CoverageLevel: d.Get("coverage_level").(string), - CoverageSites: sitesList, - } - logp.Printf("[DEBUG] servers coverage options: %+v", coverageOpts) - - return coverageOpts -} - -func resourceIecServerV1Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - resourceOpts := common.ResourceOpts{ - Count: 1, - Name: d.Get("name").(string), - ImageRef: d.Get("image_id").(string), - FlavorRef: d.Get("flavor_id").(string), - NetConfig: buildNetworkConfig(d), - SecurityGroups: buildServerSecGroups(d), - RootVolume: buildServerRootVolume(d), - DataVolumes: buildServerDataVolumes(d), - } - if d.Get("bind_eip").(bool) { - resourceOpts.BandWidth = &common.BandWidth{ - ShareType: "WHOLE", - } - } - - createOpts := servers.CreateOpts{ - ResourceOpts: resourceOpts, - Coverage: buildServerCoverage(d), - } - logp.Printf("[DEBUG] Create IEC servers options: %#v", createOpts) - // Add password here so it wouldn't go in the above log entry - if v, ok := d.GetOk("admin_pass"); ok { - createOpts.AdminPass = v.(string) - } else { - createOpts.KeyName = d.Get("key_pair").(string) - } - - resp, err := servers.CreateServer(iecClient, createOpts) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC server: %s", err) - } - - jobID := resp.Job.Id - serverID := resp.ServerIDs.IDs[0] - logp.Printf("[INFO] job ID: %s, servers ID: %s", jobID, serverID) - // Store the ID now - d.SetId(serverID) - - // Wait for the servers to become running - logp.Printf("[DEBUG] waiting for IEC server (%s) to become running", serverID) - - // Pending state "DELETED" means the instance has not be ready - stateConf := &resource.StateChangeConf{ - Pending: []string{"DELETED", "BUILD"}, - Target: []string{"ACTIVE"}, - Refresh: serverStateRefreshFunc(iecClient, serverID), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 10 * time.Second, - MinTimeout: 5 * time.Second, - } - - _, err = stateConf.WaitForState() - if err != nil { - return fmtp.Errorf("Error waiting for IEC server (%s) to become ready: %s", serverID, err) - } - - // 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{ - Name: &serverName, - }, - } - _, err = servers.UpdateServer(iecClient, updateOpts, d.Id()).ExtractUpdateToServer() - if err != nil { - logp.Printf("[WARN] Updating name of HuaweiCloud IEC server (%s) failed: %s", serverID, err) - } - - return resourceIecServerV1Read(d, meta) -} - -func resourceIecServerV1Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - servers, err := servers.GetServer(iecClient, d.Id()).ExtractServerDetail() - if err != nil { - return CheckDeleted(d, err, "iec server") - } - - edgeServer := servers.Server - logp.Printf("[DEBUG] Retrieved server %s: %+v", d.Id(), edgeServer) - - 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 fmtp.Errorf("Error setting fields: %s", err) - } - - if vpcID := edgeServer.Metadata.VpcID; vpcID != "" { - d.Set("vpc_id", vpcID) - } - if imageID := edgeServer.Image.ID; imageID != "" { - d.Set("image_id", imageID) - } - - return nil -} - -func resourceIecServerV1Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - if d.HasChange("name") { - serverName := d.Get("name").(string) - updateOpts := servers.UpdateInstance{ - UpdateServer: servers.UpdateOpts{ - Name: &serverName, - }, - } - - _, err := servers.UpdateServer(iecClient, updateOpts, d.Id()).ExtractUpdateToServer() - if err != nil { - return fmtp.Errorf("Error updating HuaweiCloud IEC server: %s", err) - } - - return resourceIecServerV1Read(d, meta) - } - - return nil -} - -func resourceIecServerV1Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating HuaweiCloud IEC client: %s", err) - } - - logp.Printf("[DEBUG] Deleting HuaweiCloud servers %s", d.Id()) - deleteOpts := servers.DeleteOpts{ - Servers: []cloudservers.Server{ - { - Id: d.Id(), - }, - }, - } - err = servers.DeleteServers(iecClient, deleteOpts).ExtractErr() - if err != nil { - return fmtp.Errorf("Error deleting HuaweiCloud server: %s", err) - } - - // Wait for the servers to delete before moving on. - logp.Printf("[DEBUG] Waiting for servers (%s) to delete", d.Id()) - stateConf := &resource.StateChangeConf{ - Pending: []string{"ACTIVE", "SHUTOFF"}, - Target: []string{"DELETED", "SOFT_DELETED"}, - Refresh: serverStateRefreshFunc(iecClient, d.Id()), - Timeout: d.Timeout(schema.TimeoutDelete), - Delay: 10 * time.Second, - MinTimeout: 5 * time.Second, - } - - _, err = stateConf.WaitForState() - if err != nil { - return fmtp.Errorf("Error waiting for servers (%s) to delete: %s", d.Id(), err) - } - - d.SetId("") - return nil -} - -// serverStateRefreshFunc returns a resource.StateRefreshFunc that is used to watch -// an HuaweiCloud IEC servers. -func serverStateRefreshFunc(client *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - s, err := servers.GetServer(client, id).ExtractServerDetail() - if err != nil { - if _, ok := err.(golangsdk.ErrDefault404); ok { - return s, "DELETED", nil - } - return nil, "", err - } - - // get fault message when status is ERROR - if s.Server.Status == "ERROR" { - return s, "ERROR", fmtp.Errorf("the edge instance is error") - } - 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 { - logp.Printf("[WARN] failed to retrieve volume %s: %s", disk.ID, err) - continue - } - - logp.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 deleted file mode 100644 index d39857d405..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_server_test.go +++ /dev/null @@ -1,162 +0,0 @@ -package huaweicloud - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - "github.com/chnsz/golangsdk/openstack/ecs/v1/cloudservers" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" -) - -func TestAccIecServerResource_basic(t *testing.T) { - var cloudserver cloudservers.CloudServer - rName := fmt.Sprintf("iec-%s", acctest.RandString(5)) - resourceName := "huaweicloud_iec_server.server_test" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecServerDestory, - Steps: []resource.TestStep{ - { - Config: testAccIecServer_basic(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecServerExists(resourceName, &cloudserver), - resource.TestCheckResourceAttr(resourceName, "name", "server-"+rName), - 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"), - ), - }, - }, - }) -} - -func testAccCheckIecServerExists(n string, cloudserver *cloudservers.CloudServer) resource.TestCheckFunc { - - return func(state *terraform.State) error { - rs, ok := state.RootModule().Resources[n] - if !ok { - return fmtp.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmtp.Errorf("No ID has been seted") - } - - config := testAccProvider.Meta().(*config.Config) - iecClient, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - found, err := cloudservers.Get(iecClient, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmtp.Errorf("IEC Server not found") - } - *cloudserver = *found - - return nil - } -} - -func testAccCheckIecServerDestory(s *terraform.State) error { - - config := testAccProvider.Meta().(*config.Config) - iecClient, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "huaweicloud_iec_security_group" { - continue - } - _, err := cloudservers.Get(iecClient, rs.Primary.ID).Extract() - if err == nil { - return fmtp.Errorf("IEC Server still exists") - } - } - - return nil -} - -func testAccIecServer_basic(rName string) string { - return fmt.Sprintf(` -data "huaweicloud_iec_flavors" "flavors_test" {} - -data "huaweicloud_iec_images" "images_test" { - name = "Ubuntu 16.04 server 64bit" -} - -data "huaweicloud_iec_sites" "sites_test" {} - -resource "huaweicloud_iec_vpc" "vpc_test" { - name = "vpc-%s" - cidr = "192.168.0.0/16" - mode = "CUSTOMER" -} - -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 - site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id -} - -resource "huaweicloud_iec_keypair" "keypair_test" { - name = "keypair-%s" -} - -resource "huaweicloud_iec_security_group" "secgroup_test" { - name = "secgroup-%s" - description = "this is a test group" -} - -resource "huaweicloud_iec_security_group_rule" "rule_test" { - direction = "ingress" - port_range_min = 445 - port_range_max = 445 - protocol = "tcp" - security_group_id = huaweicloud_iec_security_group.secgroup_test.id - remote_ip_prefix = "0.0.0.0/0" -} - -resource "huaweicloud_iec_server" "server_test" { - name = "server-%s" - image_id = data.huaweicloud_iec_images.images_test.images[0].id - flavor_id = data.huaweicloud_iec_flavors.flavors_test.flavors[1].id - vpc_id = huaweicloud_iec_vpc.vpc_test.id - subnet_ids = [huaweicloud_iec_vpc_subnet.subnet_test.id] - security_groups = [huaweicloud_iec_security_group.secgroup_test.id] - - key_pair = huaweicloud_iec_keypair.keypair_test.name - bind_eip = true - system_disk_type = "SAS" - system_disk_size = 40 - - coverage_sites { - site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id - operator = data.huaweicloud_iec_sites.sites_test.sites[0].lines[0].operator - } -} -`, rName, rName, rName, rName, rName) -} diff --git a/huaweicloud/resource_huaweicloud_iec_vpc.go b/huaweicloud/resource_huaweicloud_iec_vpc.go deleted file mode 100644 index dd8ee8d429..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_vpc.go +++ /dev/null @@ -1,144 +0,0 @@ -package huaweicloud - -import ( - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/chnsz/golangsdk/openstack/iec/v1/vpcs" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp" -) - -func ResourceIecVpc() *schema.Resource { - return &schema.Resource{ - Create: resourceIecVpcV1Create, - Read: resourceIecVpcV1Read, - Update: resourceIecVpcV1Update, - Delete: resourceIecVpcV1Delete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(3 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "region": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "name": { - Type: schema.TypeString, - Required: true, - }, - "cidr": { - Type: schema.TypeString, - Required: true, - }, - "mode": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "SYSTEM", - }, - "subnet_num": { - Type: schema.TypeInt, - Computed: true, - }, - }, - } -} - -func resourceIecVpcV1Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecV1Client, err := config.IECV1Client(GetRegion(d, config)) - - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - createOpts := vpcs.CreateOpts{ - Name: d.Get("name").(string), - Cidr: d.Get("cidr").(string), - Mode: d.Get("mode").(string), - } - - n, err := vpcs.Create(iecV1Client, createOpts).Extract() - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC VPC: %s", err) - } - - logp.Printf("[INFO] IEC VPC ID: %s", n.ID) - d.SetId(n.ID) - - return resourceIecVpcV1Read(d, meta) -} - -func resourceIecVpcV1Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecV1Client, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - n, err := vpcs.Get(iecV1Client, d.Id()).Extract() - if err != nil { - return CheckDeleted(d, err, "Error retrieving Huaweicloud IEC VPC") - } - - d.Set("name", n.Name) - d.Set("cidr", n.Cidr) - d.Set("mode", n.Mode) - d.Set("subnet_num", n.SubnetNum) - - return nil -} - -func resourceIecVpcV1Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecV1Client, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - var updateOpts vpcs.UpdateOpts - - if d.HasChange("name") { - updateOpts.Name = d.Get("name").(string) - } - if d.HasChange("cidr") { - updateOpts.Cidr = d.Get("cidr").(string) - } - - _, err = vpcs.Update(iecV1Client, d.Id(), updateOpts).Extract() - if err != nil { - return fmtp.Errorf("Error updating Huaweicloud IEC VPC: %s", err) - } - - return resourceIecVpcV1Read(d, meta) -} - -func resourceIecVpcV1Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - iecV1Client, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - //lintignore:R018 - time.Sleep(3 * time.Second) // Prevent delete failure - - err = vpcs.Delete(iecV1Client, d.Id()).ExtractErr() - if err != nil { - return CheckDeleted(d, err, "Error retrieving Huaweicloud IEC VPC") - } - - d.SetId("") - return nil -} diff --git a/huaweicloud/resource_huaweicloud_iec_vpc_subnet.go b/huaweicloud/resource_huaweicloud_iec_vpc_subnet.go deleted file mode 100644 index eaac544cd9..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_vpc_subnet.go +++ /dev/null @@ -1,253 +0,0 @@ -package huaweicloud - -import ( - "time" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/chnsz/golangsdk" - "github.com/chnsz/golangsdk/openstack/iec/v1/subnets" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/logp" -) - -func resourceIecSubnetDNSListV1(d *schema.ResourceData) []string { - rawDNSN := d.Get("dns_list").([]interface{}) - - // set the default DNS if it was not specified - if len(rawDNSN) == 0 { - return []string{"114.114.114.114", "8.8.8.8"} - } - - dnsn := make([]string, len(rawDNSN)) - for i, raw := range rawDNSN { - dnsn[i] = raw.(string) - } - return dnsn -} - -func resourceIecSubnet() *schema.Resource { - return &schema.Resource{ - Create: resourceIecSubnetV1Create, - Read: resourceIecSubnetV1Read, - Update: resourceIecSubnetV1Update, - Delete: resourceIecSubnetV1Delete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(10 * time.Minute), - Delete: schema.DefaultTimeout(3 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "region": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "name": { - Type: schema.TypeString, - Required: true, - }, - "cidr": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "vpc_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "site_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "gateway_ip": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: utils.ValidateIP, - }, - "dhcp_enable": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - "dns_list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Computed: true, - }, - "site_info": { - Type: schema.TypeString, - Computed: true, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func resourceIecSubnetV1Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - subnetClient, err := config.IECV1Client(GetRegion(d, config)) - - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - dhcp := d.Get("dhcp_enable").(bool) - createOpts := subnets.CreateOpts{ - Name: d.Get("name").(string), - Cidr: d.Get("cidr").(string), - VpcID: d.Get("vpc_id").(string), - SiteID: d.Get("site_id").(string), - GatewayIP: d.Get("gateway_ip").(string), - DhcpEnable: &dhcp, - DNSList: resourceIecSubnetDNSListV1(d), - } - - logp.Printf("[DEBUG] Create Options: %#v", createOpts) - n, err := subnets.Create(subnetClient, createOpts).Extract() - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC subnets: %s", err) - } - - d.SetId(n.ID) - logp.Printf("[DEBUG] Waiting for IEC subnets (%s) to become active", n.ID) - - stateConf := &resource.StateChangeConf{ - Pending: []string{"UNKNOWN"}, - Target: []string{"ACTIVE"}, - Refresh: waitForIecSubnetStatus(subnetClient, n.ID), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 5 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, stateErr := stateConf.WaitForState() - if stateErr != nil { - return fmtp.Errorf( - "Error waiting for IEC subnets (%s) to become ACTIVE: %s", - n.ID, stateErr) - } - - return resourceIecSubnetV1Read(d, config) -} - -func resourceIecSubnetV1Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - subnetClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - n, err := subnets.Get(subnetClient, d.Id()).Extract() - if err != nil { - return CheckDeleted(d, err, "Error retrieving Huaweicloud IEC subnets") - } - - logp.Printf("[DEBUG] IEC subnets %s: %+v", d.Id(), n) - - d.Set("name", n.Name) - d.Set("cidr", n.Cidr) - d.Set("vpc_id", n.VpcID) - d.Set("site_id", n.SiteID) - d.Set("gateway_ip", n.GatewayIP) - d.Set("dhcp_enable", n.DhcpEnable) - d.Set("dns_list", n.DNSList) - d.Set("site_info", n.SiteInfo) - d.Set("status", n.Status) - - return nil -} - -func resourceIecSubnetV1Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - subnetClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - var updateOpts subnets.UpdateOpts - - // name is mandatory while updating subnets - updateOpts.Name = d.Get("name").(string) - - if d.HasChange("dhcp_enable") { - dhcp := d.Get("dhcp_enable").(bool) - updateOpts.DhcpEnable = &dhcp - } - if d.HasChange("dns_list") { - dnsList := utils.ExpandToStringList(d.Get("dns_list").([]interface{})) - updateOpts.DNSList = &dnsList - } - - _, err = subnets.Update(subnetClient, d.Id(), updateOpts).Extract() - if err != nil { - return fmtp.Errorf("Error updating Huaweicloud IEC subnets: %s", err) - } - - return resourceIecSubnetV1Read(d, meta) -} - -func resourceIecSubnetV1Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*config.Config) - subnetClient, err := config.IECV1Client(GetRegion(d, config)) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - err = subnets.Delete(subnetClient, d.Id()).ExtractErr() - if err != nil { - return CheckDeleted(d, err, "Error deleting Huaweicloud IEC subnets") - } - - // waiting for subnets to become deleted - stateConf := &resource.StateChangeConf{ - Pending: []string{"ACTIVE", "UNKNOWN"}, - Target: []string{"DELETED"}, - Refresh: waitForIecSubnetStatus(subnetClient, d.Id()), - Timeout: d.Timeout(schema.TimeoutCreate), - Delay: 5 * time.Second, - MinTimeout: 3 * time.Second, - } - - _, stateErr := stateConf.WaitForState() - if stateErr != nil { - return fmtp.Errorf( - "Error waiting for IEC subnets (%s) to become deleted: %s", - d.Id(), stateErr) - } - - d.SetId("") - return nil -} - -func waitForIecSubnetStatus(subnetClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - n, err := subnets.Get(subnetClient, id).Extract() - if err != nil { - if _, ok := err.(golangsdk.ErrDefault404); ok { - logp.Printf("[INFO] Successfully deleted Huaweicloud IEC subnets %s", id) - return n, "DELETED", nil - } - return n, "ERROR", err - } - - return n, n.Status, nil - } -} diff --git a/huaweicloud/resource_huaweicloud_iec_vpc_subnet_test.go b/huaweicloud/resource_huaweicloud_iec_vpc_subnet_test.go deleted file mode 100644 index 9c04b4407a..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_vpc_subnet_test.go +++ /dev/null @@ -1,147 +0,0 @@ -package huaweicloud - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - iec_common "github.com/chnsz/golangsdk/openstack/iec/v1/common" - "github.com/chnsz/golangsdk/openstack/iec/v1/subnets" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" -) - -func TestAccIecVPCSubnetV1_basic(t *testing.T) { - var iecSubnet iec_common.Subnet - - rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) - resourceName := "huaweicloud_iec_vpc_subnet.subnet_test" - rNameUpdate := rName + "-updated" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecVpcSubnetV1Destroy, - Steps: []resource.TestStep{ - { - Config: testAccIecVpcSubnetV1_customer(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcSubnetV1Exists(resourceName, &iecSubnet), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s-subnet", rName)), - resource.TestCheckResourceAttr(resourceName, "cidr", "192.168.128.0/18"), - resource.TestCheckResourceAttr(resourceName, "gateway_ip", "192.168.128.1"), - resource.TestCheckResourceAttr(resourceName, "dns_list.#", "2"), - ), - }, - { - Config: testAccIecVpcSubnetV1_customer_update(rName, rNameUpdate), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcSubnetV1Exists(resourceName, &iecSubnet), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s-subnet", rNameUpdate)), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccCheckIecVpcSubnetV1Destroy(s *terraform.State) error { - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "huaweicloud_iec_vpc_subnet" { - continue - } - - _, err := subnets.Get(iecV1Client, rs.Primary.ID).Extract() - if err == nil { - return fmtp.Errorf("IEC VPC still exists") - } - } - - return nil -} - -func testAccCheckIecVpcSubnetV1Exists(n string, resource *iec_common.Subnet) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmtp.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmtp.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - found, err := subnets.Get(iecV1Client, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmtp.Errorf("IEC VPC not found") - } - - *resource = *found - - return nil - } -} - -func testAccIecVpcSubnetV1_customer(rName string) string { - return fmt.Sprintf(` -data "huaweicloud_iec_sites" "sites_test" {} - -resource "huaweicloud_iec_vpc" "vpc_test" { - name = "%s-vpc" - cidr = "192.168.0.0/16" - mode = "CUSTOMER" -} - -resource "huaweicloud_iec_vpc_subnet" "subnet_test" { - name = "%s-subnet" - cidr = "192.168.128.0/18" - vpc_id = huaweicloud_iec_vpc.vpc_test.id - site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id - gateway_ip = "192.168.128.1" -} -`, rName, rName) -} - -func testAccIecVpcSubnetV1_customer_update(rName, rNameUpdate string) string { - return fmt.Sprintf(` -data "huaweicloud_iec_sites" "sites_test" {} - -resource "huaweicloud_iec_vpc" "vpc_test" { - name = "%s-vpc" - cidr = "192.168.0.0/16" - mode = "CUSTOMER" -} - -resource "huaweicloud_iec_vpc_subnet" "subnet_test" { - name = "%s-subnet" - cidr = "192.168.128.0/18" - vpc_id = huaweicloud_iec_vpc.vpc_test.id - site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id - gateway_ip = "192.168.128.1" -} -`, rName, rNameUpdate) -} diff --git a/huaweicloud/resource_huaweicloud_iec_vpc_test.go b/huaweicloud/resource_huaweicloud_iec_vpc_test.go deleted file mode 100644 index d57b8de613..0000000000 --- a/huaweicloud/resource_huaweicloud_iec_vpc_test.go +++ /dev/null @@ -1,182 +0,0 @@ -package huaweicloud - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - iec_common "github.com/chnsz/golangsdk/openstack/iec/v1/common" - "github.com/chnsz/golangsdk/openstack/iec/v1/vpcs" - - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" -) - -func TestAccIecVpcV1_basic(t *testing.T) { - var iecVPC iec_common.VPC - - rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) - resourceName := "huaweicloud_iec_vpc.test" - rNameUpdate := rName + "-updated" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecVpcV1Destroy, - Steps: []resource.TestStep{ - { - Config: testAccIecVpcV1_system(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), - resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestCheckResourceAttr(resourceName, "cidr", "192.168.0.0/16"), - resource.TestCheckResourceAttr(resourceName, "mode", "SYSTEM"), - ), - }, - { - Config: testAccIecVpcV1_system_update(rNameUpdate), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), - resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccIecVpcV1_customer(t *testing.T) { - var iecVPC iec_common.VPC - - rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) - resourceName := "huaweicloud_iec_vpc.customer" - rNameUpdate := rName + "-updated" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckIecVpcV1Destroy, - Steps: []resource.TestStep{ - { - Config: testAccIecVpcV1_customer(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), - resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestCheckResourceAttr(resourceName, "cidr", "172.16.0.0/16"), - resource.TestCheckResourceAttr(resourceName, "mode", "CUSTOMER"), - ), - }, - { - Config: testAccIecVpcV1_customer_update(rNameUpdate), - Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), - resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), - resource.TestCheckResourceAttr(resourceName, "cidr", "172.30.0.0/16"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccCheckIecVpcV1Destroy(s *terraform.State) error { - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "huaweicloud_iec_vpc" { - continue - } - - _, err := vpcs.Get(iecV1Client, rs.Primary.ID).Extract() - if err == nil { - return fmtp.Errorf("IEC VPC still exists") - } - } - - return nil -} - -func testAccCheckIecVpcV1Exists(n string, resource *iec_common.VPC) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmtp.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmtp.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*config.Config) - iecV1Client, err := config.IECV1Client(HW_REGION_NAME) - if err != nil { - return fmtp.Errorf("Error creating Huaweicloud IEC client: %s", err) - } - - found, err := vpcs.Get(iecV1Client, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmtp.Errorf("IEC VPC not found") - } - - *resource = *found - - return nil - } -} - -func testAccIecVpcV1_system(rName string) string { - return fmt.Sprintf(` -resource "huaweicloud_iec_vpc" "test" { - name = "%s" - cidr = "192.168.0.0/16" -} -`, rName) -} - -func testAccIecVpcV1_system_update(rName string) string { - return fmt.Sprintf(` -resource "huaweicloud_iec_vpc" "test" { - name = "%s" - cidr = "192.168.0.0/16" -} -`, rName) -} - -func testAccIecVpcV1_customer(rName string) string { - return fmt.Sprintf(` -resource "huaweicloud_iec_vpc" "customer" { - name = "%s" - cidr = "172.16.0.0/16" - mode = "CUSTOMER" -} -`, rName) -} - -func testAccIecVpcV1_customer_update(rName string) string { - return fmt.Sprintf(` -resource "huaweicloud_iec_vpc" "customer" { - name = "%s" - cidr = "172.30.0.0/16" - mode = "CUSTOMER" -} -`, rName) -} diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_bandwidths_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_bandwidths_test.go index ff7a9760f2..0fe969c9bc 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_bandwidths_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_bandwidths_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) @@ -30,7 +29,6 @@ func TestAccBandWidthsDataSource_basic(t *testing.T) { Config: testAccBWsDataSource_basic(), Check: resource.ComposeTestCheckFunc( dc.CheckResourceExists(), - testAccBandWidthsDataSourceID(dataSourceName), resource.TestMatchResourceAttr(dataSourceName, "bandwidths.#", regexp.MustCompile(`[1-9]\d*`)), resource.TestCheckResourceAttrSet(dataSourceName, "site_info"), resource.TestCheckResourceAttrSet(dataSourceName, "bandwidths.0.id"), @@ -44,21 +42,6 @@ func TestAccBandWidthsDataSource_basic(t *testing.T) { }) } -func testAccBandWidthsDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("can't find IEC public IPs data source: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("the ID of the IEC public IPs data source not set") - } - - return nil - } -} - var testAccBWsDataSource_config = ` data "huaweicloud_iec_sites" "sites_test" {} diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_eips_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_eips_test.go index 03d9cfde25..0cc9032e9d 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_eips_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_eips_test.go @@ -5,12 +5,11 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccPublicIPsDataSource_basic(t *testing.T) { +func TestAccEIPsDataSource_basic(t *testing.T) { var ( dataSourceName = "data.huaweicloud_iec_eips.test" dc = acceptance.InitDataSourceCheck(dataSourceName) @@ -23,13 +22,12 @@ func TestAccPublicIPsDataSource_basic(t *testing.T) { ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEipsDataSource_config, + Config: testAccEIPsDataSource_config, }, { - Config: testAccEipsDataSource_basic(), + Config: testAccEIPsDataSource_basic(), Check: resource.ComposeTestCheckFunc( dc.CheckResourceExists(), - testAccPublicIPsDataSourceID(dataSourceName), resource.TestCheckResourceAttr(dataSourceName, "eips.0.ip_version", "4"), resource.TestCheckResourceAttr(dataSourceName, "eips.0.bandwidth_share_type", "WHOLE"), resource.TestCheckResourceAttrSet(dataSourceName, "site_info"), @@ -45,22 +43,7 @@ func TestAccPublicIPsDataSource_basic(t *testing.T) { }) } -func testAccPublicIPsDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("can't find IEC public IPs data source: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("the ID of the IEC public IPs data source not set") - } - - return nil - } -} - -var testAccEipsDataSource_config = ` +var testAccEIPsDataSource_config = ` data "huaweicloud_iec_sites" "sites_test" {} resource "huaweicloud_iec_eip" "eip_test1" { @@ -72,7 +55,7 @@ resource "huaweicloud_iec_eip" "eip_test2" { } ` -func testAccEipsDataSource_basic() string { +func testAccEIPsDataSource_basic() string { return fmt.Sprintf(` %s @@ -84,5 +67,5 @@ data "huaweicloud_iec_eips" "test" { site_id = data.huaweicloud_iec_sites.sites_test.sites[0].id } -`, testAccEipsDataSource_config) +`, testAccEIPsDataSource_config) } diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_flavors_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_flavors_test.go index 7c3b41e560..0d9da48d92 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_flavors_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_flavors_test.go @@ -6,64 +6,51 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECFlavorsDataSource_basic(t *testing.T) { - resourceName := "data.huaweicloud_iec_flavors.flavors_test" +func TestAccFlavorsDataSource_basic(t *testing.T) { + dataSourceName := "data.huaweicloud_iec_flavors.flavors_test" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccIECFlavorsConfig(), + Config: testAccFlavorsConfig(), Check: resource.ComposeTestCheckFunc( - testAccCheckIECFlavorsDataSourceID(resourceName), - resource.TestMatchResourceAttr(resourceName, "flavors.#", regexp.MustCompile(`[1-9]\d*`)), - resource.TestCheckResourceAttr(resourceName, "region", acceptance.HW_REGION_NAME), + dc.CheckResourceExists(), + resource.TestMatchResourceAttr(dataSourceName, "flavors.#", regexp.MustCompile(`[1-9]\d*`)), + resource.TestCheckResourceAttr(dataSourceName, "region", acceptance.HW_REGION_NAME), ), }, }, }) } -func TestAccIECFlavorsDataSource_FilterName(t *testing.T) { - resourceName := "data.huaweicloud_iec_flavors.flavors_test" +func TestAccFlavorsDataSource_FilterName(t *testing.T) { + dataSourceName := "data.huaweicloud_iec_flavors.flavors_test" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccIECFlavorsWithName(), + Config: testAccFlavorsWithName(), Check: resource.ComposeTestCheckFunc( - testAccCheckIECFlavorsDataSourceID(resourceName), - resource.TestCheckResourceAttr(resourceName, "flavors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "region", acceptance.HW_REGION_NAME), + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "flavors.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "region", acceptance.HW_REGION_NAME), ), }, }, }) } -func testAccCheckIECFlavorsDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("root module has no resource called %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("IEC flavors data source ID not set") - } - return nil - } -} - -func testAccIECFlavorsConfig() string { +func testAccFlavorsConfig() string { return fmt.Sprintf(` data "huaweicloud_iec_flavors" "flavors_test" { region = "%s" @@ -71,7 +58,7 @@ data "huaweicloud_iec_flavors" "flavors_test" { `, acceptance.HW_REGION_NAME) } -func testAccIECFlavorsWithName() string { +func testAccFlavorsWithName() string { return fmt.Sprintf(` data "huaweicloud_iec_flavors" "flavors_test" { region = "%s" diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_images_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_images_test.go index f941c8024d..70918c3937 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_images_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_images_test.go @@ -6,45 +6,31 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECImagesDataSource_basic(t *testing.T) { - resourceName := "data.huaweicloud_iec_images.images_test" +func TestAccImagesDataSource_basic(t *testing.T) { + dataSourceName := "data.huaweicloud_iec_images.images_test" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccIECImagesConfig(), + Config: testAccImagesConfig(), Check: resource.ComposeTestCheckFunc( - testAccCheckIECImagesDataSourceID(resourceName), - resource.TestMatchResourceAttr(resourceName, "images.#", regexp.MustCompile(`[1-9]\d*`)), - resource.TestCheckResourceAttr(resourceName, "region", acceptance.HW_REGION_NAME), + dc.CheckResourceExists(), + resource.TestMatchResourceAttr(dataSourceName, "images.#", regexp.MustCompile(`[1-9]\d*`)), + resource.TestCheckResourceAttr(dataSourceName, "region", acceptance.HW_REGION_NAME), ), }, }, }) } -func testAccCheckIECImagesDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("root module has no resource called %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("IEC images data source ID not set") - } - return nil - } -} - -func testAccIECImagesConfig() string { +func testAccImagesConfig() string { return fmt.Sprintf(` data "huaweicloud_iec_images" "images_test" { region = "%s" diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_keypair_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_keypair_test.go index 0e5e1366df..98e31eaf88 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_keypair_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_keypair_test.go @@ -10,26 +10,29 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECKeypairDataSource_basic(t *testing.T) { +func TestAccKeypairDataSource_basic(t *testing.T) { rName := fmt.Sprintf("KeyPair-%s", acctest.RandString(4)) - resourceName := "data.huaweicloud_iec_keypair.by_name" + dataSourceName := "data.huaweicloud_iec_keypair.by_name" + dc := acceptance.InitDataSourceCheck(dataSourceName) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDataSourceIECKeypair_basic(rName), + Config: testAccDataSourceKeypair_basic(rName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestCheckResourceAttrSet(resourceName, "public_key"), - resource.TestCheckResourceAttrSet(resourceName, "fingerprint"), + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "name", rName), + resource.TestCheckResourceAttrSet(dataSourceName, "public_key"), + resource.TestCheckResourceAttrSet(dataSourceName, "fingerprint"), ), }, }, }) } -func testAccDataSourceIECKeypair_basic(rName string) string { +func testAccDataSourceKeypair_basic(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_keypair" "kp_1" { name = "%s" diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_port_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_port_test.go index a3bb0079a4..80a033e812 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_port_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_port_test.go @@ -11,13 +11,13 @@ import ( func TestAccPortDataSource_basic(t *testing.T) { rName := acceptance.RandomAccResourceName() - resourceName := "data.huaweicloud_iec_port.test" - dc := acceptance.InitDataSourceCheck(resourceName) + dataSourceName := "data.huaweicloud_iec_port.test" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVpcSubnetV1Destroy, + CheckDestroy: testAccCheckVpcSubnetDestroy, Steps: []resource.TestStep{ { Config: testAccIECNetworkConfig_base(rName), @@ -26,8 +26,8 @@ func TestAccPortDataSource_basic(t *testing.T) { Config: testAccIECPortDataSource_basic(rName), Check: resource.ComposeTestCheckFunc( dc.CheckResourceExists(), - resource.TestCheckResourceAttrSet(resourceName, "mac_address"), - resource.TestCheckResourceAttrSet(resourceName, "site_id"), + resource.TestCheckResourceAttrSet(dataSourceName, "mac_address"), + resource.TestCheckResourceAttrSet(dataSourceName, "site_id"), ), }, }, diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_security_group_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_security_group_test.go index 360c15596a..a214a3618d 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_security_group_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_security_group_test.go @@ -10,30 +10,30 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECSecurityGroupDataSource_basic(t *testing.T) { +func TestAccSecurityGroupDataSource_basic(t *testing.T) { rName := fmt.Sprintf("iec-secgroup-%s", acctest.RandString(5)) description := "This is a test of iec security group" - resourceName := "data.huaweicloud_iec_security_group.by_name" - rc := acceptance.InitDataSourceCheck(resourceName) + dataSourceName := "data.huaweicloud_iec_security_group.by_name" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, Steps: []resource.TestStep{ { - Config: testAccDataSourceIECSecurityGroup_basic(rName, description), + Config: testAccDataSourceSecurityGroup_basic(rName, description), Check: resource.ComposeTestCheckFunc( - rc.CheckResourceExists(), - resource.TestCheckResourceAttr(resourceName, "name", rName), - resource.TestCheckResourceAttr(resourceName, "description", description), + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "name", rName), + resource.TestCheckResourceAttr(dataSourceName, "description", description), ), }, }, }) } -func testAccDataSourceIECSecurityGroup_basic(rName, description string) string { +func testAccDataSourceSecurityGroup_basic(rName, description string) string { return fmt.Sprintf(` resource "huaweicloud_iec_security_group" "my_group" { name = "%s" diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_server_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_server_test.go index a9b83fff60..f037df411a 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_server_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_server_test.go @@ -10,46 +10,48 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECServerDataSource_basic(t *testing.T) { +func TestAccServerDataSource_basic(t *testing.T) { rName := fmt.Sprintf("iec-%s", acctest.RandString(5)) - resourceName := "data.huaweicloud_iec_server.server_1" + dataSourceName := "data.huaweicloud_iec_server.server_1" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecServerDestory, + CheckDestroy: testAccCheckServerDestory, Steps: []resource.TestStep{ { - Config: testAccIecServer_basic(rName), + Config: testAccServer_basic(rName), }, { - Config: testAccIECServerDataSource_basic(rName), + Config: testAccServerDataSource_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", "GPSSD"), - 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"), + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "name", "server-"+rName), + resource.TestCheckResourceAttr(dataSourceName, "image_name", "Ubuntu 16.04 server 64bit"), + resource.TestCheckResourceAttr(dataSourceName, "nics.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "security_groups.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "volume_attached.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "volume_attached.0.boot_index", "0"), + resource.TestCheckResourceAttr(dataSourceName, "volume_attached.0.type", "GPSSD"), + resource.TestCheckResourceAttr(dataSourceName, "volume_attached.0.size", "40"), + resource.TestCheckResourceAttr(dataSourceName, "status", "ACTIVE"), + resource.TestCheckResourceAttrSet(dataSourceName, "system_disk_id"), + resource.TestCheckResourceAttrSet(dataSourceName, "public_ip"), + resource.TestCheckResourceAttrSet(dataSourceName, "coverage_sites.0.site_id"), + resource.TestCheckResourceAttrSet(dataSourceName, "coverage_sites.0.site_info"), ), }, }, }) } -func testAccIECServerDataSource_basic(rName string) string { +func testAccServerDataSource_basic(rName string) string { return fmt.Sprintf(` %s data "huaweicloud_iec_server" "server_1" { name = huaweicloud_iec_server.server_test.name } -`, testAccIecServer_basic(rName)) +`, testAccServer_basic(rName)) } diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_sites_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_sites_test.go index 22ac6ecffd..867953b7e9 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_sites_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_sites_test.go @@ -1,51 +1,36 @@ package iec import ( - "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECSitesDataSource_basic(t *testing.T) { - resourceName := "data.huaweicloud_iec_sites.sites_test" +func TestAccSitesDataSource_basic(t *testing.T) { + dataSourceName := "data.huaweicloud_iec_sites.sites_test" + dc := acceptance.InitDataSourceCheck(dataSourceName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecServerDestory, + CheckDestroy: testAccCheckServerDestory, Steps: []resource.TestStep{ { - Config: testAccIECSitesConfig_basic(), + Config: testAccSitesConfig_basic(), Check: resource.ComposeTestCheckFunc( - testAccCheckIECSitesDataSourceID(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "sites.#"), - resource.TestCheckResourceAttr(resourceName, "sites.0.area", "east"), - resource.TestCheckResourceAttrSet(resourceName, "sites.0.lines.#"), + dc.CheckResourceExists(), + resource.TestCheckResourceAttrSet(dataSourceName, "sites.#"), + resource.TestCheckResourceAttr(dataSourceName, "sites.0.area", "east"), + resource.TestCheckResourceAttrSet(dataSourceName, "sites.0.lines.#"), ), }, }, }) } -func testAccCheckIECSitesDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Root module has no resource called %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("IEC sites data source ID not set") - } - return nil - } -} - -func testAccIECSitesConfig_basic() string { +func testAccSitesConfig_basic() string { return ` data "huaweicloud_iec_sites" "sites_test" { area = "east" diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_subnets_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_subnets_test.go index 8ab79dd4fd..7f6bfc27fd 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_subnets_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_subnets_test.go @@ -11,7 +11,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECSubnetsDataSource_basic(t *testing.T) { +func TestAccVpcSubnetsDataSource_basic(t *testing.T) { rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) allSubnets := "data.huaweicloud_iec_vpc_subnets.all" siteSubnets := "data.huaweicloud_iec_vpc_subnets.site" @@ -19,16 +19,16 @@ func TestAccIECSubnetsDataSource_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVpcSubnetV1Destroy, + CheckDestroy: testAccCheckVpcSubnetDestroy, Steps: []resource.TestStep{ { Config: testAccNetworkConfig_base(rName), }, { - Config: testAccIECSubnetsDataSource_basic(rName), + Config: testAccSubnetsDataSource_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccIECSubnetsDataSourceID(allSubnets), - testAccIECSubnetsDataSourceID(siteSubnets), + testAccSubnetsDataSourceID(allSubnets), + testAccSubnetsDataSourceID(siteSubnets), resource.TestCheckResourceAttr(allSubnets, "subnets.#", "2"), resource.TestCheckResourceAttr(siteSubnets, "subnets.#", "1"), resource.TestCheckResourceAttrSet(siteSubnets, "subnets.0.id"), @@ -40,7 +40,7 @@ func TestAccIECSubnetsDataSource_basic(t *testing.T) { }) } -func testAccIECSubnetsDataSourceID(n string) resource.TestCheckFunc { +func testAccSubnetsDataSourceID(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -83,7 +83,7 @@ resource "huaweicloud_iec_vpc_subnet" "subnet_2" { `, rName, rName, rName) } -func testAccIECSubnetsDataSource_basic(rName string) string { +func testAccSubnetsDataSource_basic(rName string) string { return fmt.Sprintf(` %s diff --git a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_test.go b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_test.go index 036a5c5c75..7e53da394a 100644 --- a/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_test.go +++ b/huaweicloud/services/acceptance/iec/data_source_huaweicloud_iec_vpc_test.go @@ -11,19 +11,19 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIECVpcDataSource_basic(t *testing.T) { +func TestAccVpcDataSource_basic(t *testing.T) { rName := fmt.Sprintf("tf-acc-vpc-%s", acctest.RandString(5)) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVpcV1Destroy, + CheckDestroy: testAccCheckVpcDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceIECVpc_basic(rName), + Config: testAccVpcDataSource_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccDataSourceIECVpcCheck("data.huaweicloud_iec_vpc.by_id", rName), - testAccDataSourceIECVpcCheck("data.huaweicloud_iec_vpc.by_name", rName), + testAccVpcDataSourceCheck("data.huaweicloud_iec_vpc.by_id", rName), + testAccVpcDataSourceCheck("data.huaweicloud_iec_vpc.by_name", rName), resource.TestCheckResourceAttr( "data.huaweicloud_iec_vpc.by_id", "mode", "SYSTEM"), resource.TestCheckResourceAttr( @@ -34,7 +34,7 @@ func TestAccIECVpcDataSource_basic(t *testing.T) { }) } -func testAccDataSourceIECVpcCheck(n, rName string) resource.TestCheckFunc { +func testAccVpcDataSourceCheck(n, rName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -64,7 +64,7 @@ func testAccDataSourceIECVpcCheck(n, rName string) resource.TestCheckFunc { } } -func testAccDataSourceIECVpc_basic(rName string) string { +func testAccVpcDataSource_basic(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_vpc" "test" { name = "%s" diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_eip_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_eip_test.go index 259697dac9..23ec942ac1 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_eip_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_eip_test.go @@ -15,19 +15,19 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecEIPResource_basic(t *testing.T) { +func TestAccEIPResource_basic(t *testing.T) { var iecEip common.PublicIP resourceName := "huaweicloud_iec_eip.eip_test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecEIPDestroy, + CheckDestroy: testAccCheckEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccIecEIP_basic, + Config: testAccEIP_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckIecEIPExists(resourceName, &iecEip), + testAccCheckEIPExists(resourceName, &iecEip), resource.TestCheckResourceAttr(resourceName, "ip_version", "4"), resource.TestCheckResourceAttr(resourceName, "bandwidth_share_type", "WHOLE"), resource.TestMatchResourceAttr(resourceName, "public_ip", @@ -47,7 +47,7 @@ func TestAccIecEIPResource_basic(t *testing.T) { }) } -func testAccCheckIecEIPDestroy(s *terraform.State) error { +func testAccCheckEIPDestroy(s *terraform.State) error { cfg := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := cfg.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { @@ -68,7 +68,7 @@ func testAccCheckIecEIPDestroy(s *terraform.State) error { return nil } -func testAccCheckIecEIPExists(n string, ipResource *common.PublicIP) resource.TestCheckFunc { +func testAccCheckEIPExists(n string, ipResource *common.PublicIP) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -100,7 +100,7 @@ func testAccCheckIecEIPExists(n string, ipResource *common.PublicIP) resource.Te } } -var testAccIecEIP_basic = ` +var testAccEIP_basic = ` data "huaweicloud_iec_sites" "sites_test" {} resource "huaweicloud_iec_eip" "eip_test" { diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_keypair_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_keypair_test.go index b3b4967802..d30d152856 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_keypair_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_keypair_test.go @@ -17,7 +17,7 @@ import ( func getKeypairResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) { c, err := cfg.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return nil, fmt.Errorf("error creating IEC v1 client: %s", err) + return nil, fmt.Errorf("error creating IEC client: %s", err) } return keypairs.Get(c, state.Primary.ID).Extract() } diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_rule_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_rule_test.go index f7688fa0f0..09cd14f95d 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_rule_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_rule_test.go @@ -15,12 +15,12 @@ import ( ) func getNetworkACLRuleResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) { - iecV1Client, err := conf.IECV1Client(acceptance.HW_REGION_NAME) + iecClient, err := conf.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return nil, fmt.Errorf("error creating IEC v1 client: %s", err) + return nil, fmt.Errorf("error creating IEC client: %s", err) } - fwGroup, err := firewalls.Get(iecV1Client, state.Primary.ID).Extract() + fwGroup, err := firewalls.Get(iecClient, state.Primary.ID).Extract() if err != nil { return nil, err } diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_test.go index 5e49eab01f..253fbf394d 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_network_acl_test.go @@ -16,12 +16,12 @@ import ( ) func getNetworkACLResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) { - iecV1Client, err := conf.IECV1Client(acceptance.HW_REGION_NAME) + iecClient, err := conf.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return nil, fmt.Errorf("error creating IEC v1 client: %s", err) + return nil, fmt.Errorf("error creating IEC client: %s", err) } - fwGroup, err := firewalls.Get(iecV1Client, state.Primary.ID).Extract() + fwGroup, err := firewalls.Get(iecClient, state.Primary.ID).Extract() if err != nil { return nil, golangsdk.ErrDefault404{} } @@ -47,7 +47,7 @@ func TestAccNetworkACLResource_basic(t *testing.T) { CheckDestroy: rc.CheckResourceDestroy(), Steps: []resource.TestStep{ { - Config: testAccIecNetworkACL_basic(name), + Config: testAccNetworkACL_basic(name), Check: resource.ComposeTestCheckFunc( rc.CheckResourceExists(), resource.TestCheckResourceAttr(rName, "name", name), @@ -61,7 +61,7 @@ func TestAccNetworkACLResource_basic(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccIecNetworkACL_basic_update(name), + Config: testAccNetworkACL_basic_update(name), Check: resource.ComposeTestCheckFunc( rc.CheckResourceExists(), resource.TestCheckResourceAttr(rName, "name", name+"-update"), @@ -90,11 +90,11 @@ func TestAccNetworkACLResource_no_subnets(t *testing.T) { CheckDestroy: rc.CheckResourceDestroy(), Steps: []resource.TestStep{ { - Config: testAccIecNetworkACL_no_subnets(name), + Config: testAccNetworkACL_no_subnets(name), Check: resource.ComposeTestCheckFunc( rc.CheckResourceExists(), resource.TestCheckResourceAttr(rName, "name", name+"-noSubnet"), - resource.TestCheckResourceAttr(rName, "description", "Iec network acl without subents"), + resource.TestCheckResourceAttr(rName, "description", " network acl without subents"), resource.TestCheckResourceAttr(rName, "status", "INACTIVE"), ), }, @@ -111,7 +111,7 @@ func testAccCheckNetworkACLNetBlockExists(r *firewalls.Firewall) resource.TestCh } } -var testAccIecNetworkACLRules = ` +var testAccNetworkACLRules = ` data "huaweicloud_iec_sites" "sites_test" {} resource "huaweicloud_iec_vpc" "vpc_test" { @@ -129,7 +129,7 @@ resource "huaweicloud_iec_vpc_subnet" "subnet_test" { } ` -func testAccIecNetworkACL_basic(rName string) string { +func testAccNetworkACL_basic(rName string) string { return fmt.Sprintf(` %s @@ -141,10 +141,10 @@ resource "huaweicloud_iec_network_acl" "acl_demo" { subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id } } -`, testAccIecNetworkACLRules, rName) +`, testAccNetworkACLRules, rName) } -func testAccIecNetworkACL_basic_update(rName string) string { +func testAccNetworkACL_basic_update(rName string) string { return fmt.Sprintf(` %s @@ -156,14 +156,14 @@ resource "huaweicloud_iec_network_acl" "acl_demo" { subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id } } -`, testAccIecNetworkACLRules, rName) +`, testAccNetworkACLRules, rName) } -func testAccIecNetworkACL_no_subnets(rName string) string { +func testAccNetworkACL_no_subnets(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_network_acl" "acl_demo" { name = "%s-noSubnet" - description = "Iec network acl without subents" + description = " network acl without subents" } `, rName) } diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_rule_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_rule_test.go index 3b4240f79e..87f0a952ff 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_rule_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_rule_test.go @@ -15,7 +15,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecSecurityGroupRuleResource_Basic(t *testing.T) { +func TestAccSecurityGroupRuleResource_Basic(t *testing.T) { groupName := "huaweicloud_iec_security_group.my_group" ruleName1 := "huaweicloud_iec_security_group_rule.rule_1" ruleName2 := "huaweicloud_iec_security_group_rule.rule_2" @@ -27,18 +27,18 @@ func TestAccIecSecurityGroupRuleResource_Basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecSecurityGroupRuleV1Destory, + CheckDestroy: testAccCheckSecurityGroupRuleDestory, Steps: []resource.TestStep{ { - Config: testAccIecSecurityGroupRuleV1_Basic(rName), + Config: testAccSecurityGroupRule_Basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecSecGroupV1Exists(groupName, &group), - testAccCheckIecSecurityGroupRuleV1Exists(ruleName1, &rule1), + testAccCheckSecurityGroupExists(groupName, &group), + testAccCheckSecurityGroupRuleExists(ruleName1, &rule1), resource.TestCheckResourceAttr(ruleName1, "direction", "egress"), resource.TestCheckResourceAttr(ruleName1, "protocol", "tcp"), resource.TestCheckResourceAttr(ruleName1, "port_range_min", "445"), resource.TestCheckResourceAttr(ruleName1, "port_range_max", "445"), - testAccCheckIecSecurityGroupRuleV1Exists(ruleName2, &rule2), + testAccCheckSecurityGroupRuleExists(ruleName2, &rule2), resource.TestCheckResourceAttr(ruleName2, "direction", "ingress"), resource.TestCheckResourceAttr(ruleName2, "protocol", "udp"), resource.TestCheckResourceAttr(ruleName2, "port_range_min", "20"), @@ -49,37 +49,7 @@ func TestAccIecSecurityGroupRuleResource_Basic(t *testing.T) { }) } -func testAccCheckIecSecGroupV1Exists(n string, group *groups.RespSecurityGroupEntity) resource.TestCheckFunc { - return func(state *terraform.State) error { - rs, ok := state.RootModule().Resources[n] - if !ok { - return fmt.Errorf("not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("no ID has been seted") - } - - cfg := acceptance.TestAccProvider.Meta().(*config.Config) - iecClient, err := cfg.IECV1Client(acceptance.HW_REGION_NAME) - if err != nil { - return fmt.Errorf("error creating IEC client: %s", err) - } - - found, err := groups.Get(iecClient, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmt.Errorf("IEC Security group not found") - } - *group = *found - return nil - } -} - -func testAccCheckIecSecurityGroupRuleV1Exists(n string, rule *rules.RespSecurityGroupRule) resource.TestCheckFunc { +func testAccCheckSecurityGroupRuleExists(n string, rule *rules.RespSecurityGroupRule) resource.TestCheckFunc { return func(state *terraform.State) error { rs, ok := state.RootModule().Resources[n] if !ok { @@ -108,7 +78,7 @@ func testAccCheckIecSecurityGroupRuleV1Exists(n string, rule *rules.RespSecurity } } -func testAccCheckIecSecurityGroupRuleV1Destory(state *terraform.State) error { +func testAccCheckSecurityGroupRuleDestory(state *terraform.State) error { cfg := acceptance.TestAccProvider.Meta().(*config.Config) iecClient, err := cfg.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { @@ -129,7 +99,7 @@ func testAccCheckIecSecurityGroupRuleV1Destory(state *terraform.State) error { return nil } -func testAccIecSecurityGroupRuleV1_Basic(rName string) string { +func testAccSecurityGroupRule_Basic(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_security_group" "my_group" { name = "%s" diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_test.go index 7667647f6d..5a14a2042a 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_security_group_test.go @@ -14,7 +14,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecSecurityGroupResource_basic(t *testing.T) { +func TestAccSecurityGroupResource_basic(t *testing.T) { resourceName := "huaweicloud_iec_security_group.my_group" rName := fmt.Sprintf("iec-secgroup-%s", acctest.RandString(5)) description := "This is a test of iec security group" @@ -24,12 +24,12 @@ func TestAccIecSecurityGroupResource_basic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecSecurityGroupV1Destory, + CheckDestroy: testAccCheckSecurityGroupDestory, Steps: []resource.TestStep{ { - Config: testAccIecSecurityGroupV1_Basic(rName, description), + Config: testAccSecurityGroup_Basic(rName, description), Check: resource.ComposeTestCheckFunc( - testAccCheckIecSecurityGroupV1Exists(resourceName, &group), + testAccCheckSecurityGroupExists(resourceName, &group), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "description", description), resource.TestCheckResourceAttr(resourceName, "security_group_rules.#", "0"), @@ -44,7 +44,7 @@ func TestAccIecSecurityGroupResource_basic(t *testing.T) { }) } -func testAccCheckIecSecurityGroupV1Exists(n string, group *groups.RespSecurityGroupEntity) resource.TestCheckFunc { +func testAccCheckSecurityGroupExists(n string, group *groups.RespSecurityGroupEntity) resource.TestCheckFunc { return func(state *terraform.State) error { rs, ok := state.RootModule().Resources[n] if !ok { @@ -74,7 +74,7 @@ func testAccCheckIecSecurityGroupV1Exists(n string, group *groups.RespSecurityGr } } -func testAccCheckIecSecurityGroupV1Destory(s *terraform.State) error { +func testAccCheckSecurityGroupDestory(s *terraform.State) error { cfg := acceptance.TestAccProvider.Meta().(*config.Config) iecClient, err := cfg.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { @@ -94,7 +94,7 @@ func testAccCheckIecSecurityGroupV1Destory(s *terraform.State) error { return nil } -func testAccIecSecurityGroupV1_Basic(rName, description string) string { +func testAccSecurityGroup_Basic(rName, description string) string { return fmt.Sprintf(` resource "huaweicloud_iec_security_group" "my_group" { name = "%s" diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_server_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_server_test.go index b95169c04a..21c96a2cbd 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_server_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_server_test.go @@ -14,19 +14,20 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecServerResource_basic(t *testing.T) { +func TestAccServerResource_basic(t *testing.T) { var cloudserver cloudservers.CloudServer rName := fmt.Sprintf("iec-%s", acctest.RandString(5)) resourceName := "huaweicloud_iec_server.server_test" + resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecServerDestory, + CheckDestroy: testAccCheckServerDestory, Steps: []resource.TestStep{ { - Config: testAccIecServer_basic(rName), + Config: testAccServer_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecServerExists(resourceName, &cloudserver), + testAccCheckServerExists(resourceName, &cloudserver), resource.TestCheckResourceAttr(resourceName, "name", "server-"+rName), resource.TestCheckResourceAttr(resourceName, "image_name", "Ubuntu 16.04 server 64bit"), resource.TestCheckResourceAttr(resourceName, "nics.#", "1"), @@ -53,7 +54,7 @@ func TestAccIecServerResource_basic(t *testing.T) { }) } -func testAccCheckIecServerExists(n string, cloudserver *cloudservers.CloudServer) resource.TestCheckFunc { +func testAccCheckServerExists(n string, cloudserver *cloudservers.CloudServer) resource.TestCheckFunc { return func(state *terraform.State) error { rs, ok := state.RootModule().Resources[n] if !ok { @@ -84,7 +85,7 @@ func testAccCheckIecServerExists(n string, cloudserver *cloudservers.CloudServer } } -func testAccCheckIecServerDestory(s *terraform.State) error { +func testAccCheckServerDestory(s *terraform.State) error { cfg := acceptance.TestAccProvider.Meta().(*config.Config) iecClient, err := cfg.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { @@ -104,7 +105,7 @@ func testAccCheckIecServerDestory(s *terraform.State) error { return nil } -func testAccIecServer_basic(rName string) string { +func testAccServer_basic(rName string) string { return fmt.Sprintf(` data "huaweicloud_iec_flavors" "flavors_test" {} diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vip_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vip_test.go index 0f14085758..5dd2b25f84 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vip_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vip_test.go @@ -15,7 +15,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecVipResource_basic(t *testing.T) { +func TestAccVipResource_basic(t *testing.T) { var iecPort ieccommon.Port rName := fmt.Sprintf("iec-%s", acctest.RandString(5)) resourceName := "huaweicloud_iec_vip.vip_test" @@ -23,12 +23,12 @@ func TestAccIecVipResource_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVipDestroy, + CheckDestroy: testAccCheckVipDestroy, Steps: []resource.TestStep{ { - Config: testAccIecVip_basic(rName), + Config: testAccVip_basic(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVipExists(resourceName, &iecPort), + testAccCheckVipExists(resourceName, &iecPort), resource.TestCheckResourceAttr(resourceName, "ip_address", "192.168.0.100"), resource.TestCheckResourceAttrSet(resourceName, "mac_address"), ), @@ -42,7 +42,7 @@ func TestAccIecVipResource_basic(t *testing.T) { }) } -func TestAccIecVipResource_associate(t *testing.T) { +func TestAccVipResource_associate(t *testing.T) { var iecPort ieccommon.Port rName := fmt.Sprintf("iec-%s", acctest.RandString(5)) resourceName := "huaweicloud_iec_vip.vip_test" @@ -50,18 +50,18 @@ func TestAccIecVipResource_associate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVipDestroy, + CheckDestroy: testAccCheckVipDestroy, Steps: []resource.TestStep{ { - Config: testAccIecVip_associate(rName), + Config: testAccVip_associate(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVipExists(resourceName, &iecPort), + testAccCheckVipExists(resourceName, &iecPort), resource.TestCheckResourceAttrSet(resourceName, "mac_address"), resource.TestCheckResourceAttr(resourceName, "allowed_addresses.#", "1"), ), }, { - Config: testAccIecVip_disassociate(rName), + Config: testAccVip_disassociate(rName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "mac_address"), resource.TestCheckResourceAttr(resourceName, "allowed_addresses.#", "0"), @@ -71,11 +71,11 @@ func TestAccIecVipResource_associate(t *testing.T) { }) } -func testAccCheckIecVipDestroy(s *terraform.State) error { +func testAccCheckVipDestroy(s *terraform.State) error { conf := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := conf.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return fmt.Errorf("Error creating IEC client: %s", err) + return fmt.Errorf("error creating IEC client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -92,7 +92,7 @@ func testAccCheckIecVipDestroy(s *terraform.State) error { return nil } -func testAccCheckIecVipExists(n string, vipResource *ieccommon.Port) resource.TestCheckFunc { +func testAccCheckVipExists(n string, vipResource *ieccommon.Port) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -106,7 +106,7 @@ func testAccCheckIecVipExists(n string, vipResource *ieccommon.Port) resource.Te config := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := config.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return fmt.Errorf("Error creating IEC client: %s", err) + return fmt.Errorf("error creating IEC client: %s", err) } found, err := ports.Get(iecV1Client, rs.Primary.ID).Extract() @@ -124,7 +124,7 @@ func testAccCheckIecVipExists(n string, vipResource *ieccommon.Port) resource.Te } } -func testAccIecVip_base(rName string) string { +func testAccVip_base(rName string) string { return fmt.Sprintf(` data "huaweicloud_iec_sites" "sites_test" {} @@ -144,7 +144,7 @@ resource "huaweicloud_iec_vpc_subnet" "subnet_test" { `, rName, rName) } -func testAccIecVip_basic(rName string) string { +func testAccVip_basic(rName string) string { return fmt.Sprintf(` %s @@ -152,10 +152,10 @@ resource "huaweicloud_iec_vip" "vip_test" { subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id ip_address = "192.168.0.100" } -`, testAccIecVip_base(rName)) +`, testAccVip_base(rName)) } -func testAccIecVip_associate(rName string) string { +func testAccVip_associate(rName string) string { return fmt.Sprintf(` %s @@ -163,15 +163,15 @@ resource "huaweicloud_iec_vip" "vip_test" { subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id port_ids = [huaweicloud_iec_server.server_test.nics[0].port] } -`, testAccIecServer_basic(rName)) +`, testAccServer_basic(rName)) } -func testAccIecVip_disassociate(rName string) string { +func testAccVip_disassociate(rName string) string { return fmt.Sprintf(` %s resource "huaweicloud_iec_vip" "vip_test" { subnet_id = huaweicloud_iec_vpc_subnet.subnet_test.id } -`, testAccIecServer_basic(rName)) +`, testAccServer_basic(rName)) } diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_subnet_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_subnet_test.go index a1d1a72a6d..d2a74c840f 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_subnet_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_subnet_test.go @@ -15,7 +15,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecVPCSubnetV1_basic(t *testing.T) { +func TestAccVpcSubnet_basic(t *testing.T) { var iecSubnet ieccommon.Subnet rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) @@ -25,12 +25,12 @@ func TestAccIecVPCSubnetV1_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVpcSubnetV1Destroy, + CheckDestroy: testAccCheckVpcSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccIecVpcSubnetV1_customer(rName), + Config: testAccVpcSubnet_customer(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcSubnetV1Exists(resourceName, &iecSubnet), + testAccCheckVpcSubnetExists(resourceName, &iecSubnet), resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s-subnet", rName)), resource.TestCheckResourceAttr(resourceName, "cidr", "192.168.128.0/18"), resource.TestCheckResourceAttr(resourceName, "gateway_ip", "192.168.128.1"), @@ -38,9 +38,9 @@ func TestAccIecVPCSubnetV1_basic(t *testing.T) { ), }, { - Config: testAccIecVpcSubnetV1_customer_update(rName, rNameUpdate), + Config: testAccVpcSubnet_customer_update(rName, rNameUpdate), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcSubnetV1Exists(resourceName, &iecSubnet), + testAccCheckVpcSubnetExists(resourceName, &iecSubnet), resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("%s-subnet", rNameUpdate)), ), }, @@ -53,11 +53,11 @@ func TestAccIecVPCSubnetV1_basic(t *testing.T) { }) } -func testAccCheckIecVpcSubnetV1Destroy(s *terraform.State) error { +func testAccCheckVpcSubnetDestroy(s *terraform.State) error { conf := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := conf.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return fmt.Errorf("Error creating IEC client: %s", err) + return fmt.Errorf("error creating IEC client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -74,7 +74,7 @@ func testAccCheckIecVpcSubnetV1Destroy(s *terraform.State) error { return nil } -func testAccCheckIecVpcSubnetV1Exists(n string, subnetResource *ieccommon.Subnet) resource.TestCheckFunc { +func testAccCheckVpcSubnetExists(n string, subnetResource *ieccommon.Subnet) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -88,7 +88,7 @@ func testAccCheckIecVpcSubnetV1Exists(n string, subnetResource *ieccommon.Subnet config := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := config.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return fmt.Errorf("Error creating Huaweicloud IEC client: %s", err) + return fmt.Errorf("error creating Huaweicloud IEC client: %s", err) } found, err := subnets.Get(iecV1Client, rs.Primary.ID).Extract() @@ -106,7 +106,7 @@ func testAccCheckIecVpcSubnetV1Exists(n string, subnetResource *ieccommon.Subnet } } -func testAccIecVpcSubnetV1_customer(rName string) string { +func testAccVpcSubnet_customer(rName string) string { return fmt.Sprintf(` data "huaweicloud_iec_sites" "sites_test" {} @@ -126,7 +126,7 @@ resource "huaweicloud_iec_vpc_subnet" "subnet_test" { `, rName, rName) } -func testAccIecVpcSubnetV1_customer_update(rName, rNameUpdate string) string { +func testAccVpcSubnet_customer_update(rName, rNameUpdate string) string { return fmt.Sprintf(` data "huaweicloud_iec_sites" "sites_test" {} diff --git a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_test.go b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_test.go index 0981a61691..5bab6a66b6 100644 --- a/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_test.go +++ b/huaweicloud/services/acceptance/iec/resource_huaweicloud_iec_vpc_test.go @@ -15,7 +15,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" ) -func TestAccIecVpcV1_basic(t *testing.T) { +func TestAccVpc_basic(t *testing.T) { var iecVPC ieccommon.VPC rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) @@ -25,21 +25,21 @@ func TestAccIecVpcV1_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVpcV1Destroy, + CheckDestroy: testAccCheckVpcDestroy, Steps: []resource.TestStep{ { - Config: testAccIecVpcV1_system(rName), + Config: testAccVpc_system(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), + testAccCheckVpcExists(resourceName, &iecVPC), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "cidr", "192.168.0.0/16"), resource.TestCheckResourceAttr(resourceName, "mode", "SYSTEM"), ), }, { - Config: testAccIecVpcV1_system_update(rNameUpdate), + Config: testAccVpc_system_update(rNameUpdate), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), + testAccCheckVpcExists(resourceName, &iecVPC), resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), ), }, @@ -52,7 +52,7 @@ func TestAccIecVpcV1_basic(t *testing.T) { }) } -func TestAccIecVpcV1_customer(t *testing.T) { +func TestAccVpc_customer(t *testing.T) { var iecVPC ieccommon.VPC rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) @@ -62,21 +62,21 @@ func TestAccIecVpcV1_customer(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.TestAccPreCheck(t) }, ProviderFactories: acceptance.TestAccProviderFactories, - CheckDestroy: testAccCheckIecVpcV1Destroy, + CheckDestroy: testAccCheckVpcDestroy, Steps: []resource.TestStep{ { - Config: testAccIecVpcV1_customer(rName), + Config: testAccVpc_customer(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), + testAccCheckVpcExists(resourceName, &iecVPC), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "cidr", "172.16.0.0/16"), resource.TestCheckResourceAttr(resourceName, "mode", "CUSTOMER"), ), }, { - Config: testAccIecVpcV1_customer_update(rNameUpdate), + Config: testAccVpc_customer_update(rNameUpdate), Check: resource.ComposeTestCheckFunc( - testAccCheckIecVpcV1Exists(resourceName, &iecVPC), + testAccCheckVpcExists(resourceName, &iecVPC), resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), resource.TestCheckResourceAttr(resourceName, "cidr", "172.30.0.0/16"), ), @@ -90,11 +90,11 @@ func TestAccIecVpcV1_customer(t *testing.T) { }) } -func testAccCheckIecVpcV1Destroy(s *terraform.State) error { +func testAccCheckVpcDestroy(s *terraform.State) error { conf := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := conf.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return fmt.Errorf("Error creating IEC client: %s", err) + return fmt.Errorf("error creating IEC client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -111,7 +111,7 @@ func testAccCheckIecVpcV1Destroy(s *terraform.State) error { return nil } -func testAccCheckIecVpcV1Exists(n string, vpcResource *ieccommon.VPC) resource.TestCheckFunc { +func testAccCheckVpcExists(n string, vpcResource *ieccommon.VPC) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -125,7 +125,7 @@ func testAccCheckIecVpcV1Exists(n string, vpcResource *ieccommon.VPC) resource.T conf := acceptance.TestAccProvider.Meta().(*config.Config) iecV1Client, err := conf.IECV1Client(acceptance.HW_REGION_NAME) if err != nil { - return fmt.Errorf("Error creating IEC client: %s", err) + return fmt.Errorf("error creating IEC client: %s", err) } found, err := vpcs.Get(iecV1Client, rs.Primary.ID).Extract() @@ -143,7 +143,7 @@ func testAccCheckIecVpcV1Exists(n string, vpcResource *ieccommon.VPC) resource.T } } -func testAccIecVpcV1_system(rName string) string { +func testAccVpc_system(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_vpc" "test" { name = "%s" @@ -152,7 +152,7 @@ resource "huaweicloud_iec_vpc" "test" { `, rName) } -func testAccIecVpcV1_system_update(rName string) string { +func testAccVpc_system_update(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_vpc" "test" { name = "%s" @@ -161,7 +161,7 @@ resource "huaweicloud_iec_vpc" "test" { `, rName) } -func testAccIecVpcV1_customer(rName string) string { +func testAccVpc_customer(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_vpc" "customer" { name = "%s" @@ -171,7 +171,7 @@ resource "huaweicloud_iec_vpc" "customer" { `, rName) } -func testAccIecVpcV1_customer_update(rName string) string { +func testAccVpc_customer_update(rName string) string { return fmt.Sprintf(` resource "huaweicloud_iec_vpc" "customer" { name = "%s" diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_bandwidths.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_bandwidths.go index 574b566fda..d61c090ccb 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_bandwidths.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_bandwidths.go @@ -73,7 +73,7 @@ func dataSourceBandWidthsRead(_ context.Context, d *schema.ResourceData, meta in cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } listOpts := bandwidths.ListOpts{ diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_eips.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_eips.go index 7dd6992c9a..202702f40d 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_eips.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_eips.go @@ -14,9 +14,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/eip" ) -func DataSourceNetworkEips() *schema.Resource { +func DataSourceEips() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceNetworkEipsRead, + ReadContext: dataSourceEipsRead, Schema: map[string]*schema.Schema{ "site_id": { @@ -84,11 +84,11 @@ func DataSourceNetworkEips() *schema.Resource { } } -func dataSourceNetworkEipsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceEipsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) eipClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } listpts := publicips.ListOpts{ diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_flavors.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_flavors.go index 052c783b81..90d1b7117a 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_flavors.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_flavors.go @@ -13,9 +13,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIecFlavors() *schema.Resource { +func DataSourceFlavors() *schema.Resource { return &schema.Resource{ - Read: dataSourceIecFlavorsRead, + Read: dataSourceFlavorsRead, Schema: map[string]*schema.Schema{ "region": { @@ -75,7 +75,7 @@ func DataSourceIecFlavors() *schema.Resource { } } -func dataSourceIecFlavorsRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceFlavorsRead(d *schema.ResourceData, meta interface{}) error { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_images.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_images.go index eab2142c72..4ab4047d79 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_images.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_images.go @@ -13,9 +13,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIecImages() *schema.Resource { +func DataSourceImages() *schema.Resource { return &schema.Resource{ - Read: dataSourceIecImagesRead, + Read: dataSourceImagesRead, Schema: map[string]*schema.Schema{ "region": { @@ -62,7 +62,7 @@ func DataSourceIecImages() *schema.Resource { } } -func dataSourceIecImagesRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceImagesRead(d *schema.ResourceData, meta interface{}) error { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_keypair.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_keypair.go index 8ef4dc182c..ae00b9dfaf 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_keypair.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_keypair.go @@ -14,9 +14,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIECKeypair() *schema.Resource { +func DataSourceKeypair() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIECKeypairRead, + ReadContext: dataSourceKeypairRead, Schema: map[string]*schema.Schema{ "name": { @@ -35,7 +35,7 @@ func DataSourceIECKeypair() *schema.Resource { } } -func dataSourceIECKeypairRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceKeypairRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_network_acl.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_network_acl.go index 5ec94cb87b..2bd701811a 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_network_acl.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_network_acl.go @@ -75,7 +75,7 @@ func dataSourceNetworkACLRead(_ context.Context, d *schema.ResourceData, meta in cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } listOpts := firewalls.ListOpts{ diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_port.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_port.go index f2f6e5a448..0d756b793a 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_port.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_port.go @@ -15,9 +15,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIECPort() *schema.Resource { +func DataSourcePort() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIECPortRead, + ReadContext: dataSourcePortRead, Schema: map[string]*schema.Schema{ "region": { @@ -64,11 +64,11 @@ func DataSourceIECPort() *schema.Resource { } } -func dataSourceIECPortRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourcePortRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } listOpts := ports.ListOpts{ diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_security_group.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_security_group.go index b31716cba3..6e3561d2f1 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_security_group.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_security_group.go @@ -14,9 +14,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIECSecurityGroup() *schema.Resource { +func DataSourceSecurityGroup() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIECSecurityGroupRead, + ReadContext: dataSourceSecurityGroupRead, Schema: map[string]*schema.Schema{ "name": { @@ -81,11 +81,11 @@ func DataSourceIECSecurityGroup() *schema.Resource { } } -func dataSourceIECSecurityGroupRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceSecurityGroupRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } allSecGroups, err := groups.List(iecClient, nil).Extract() diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_server.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_server.go index 71d3e6b5fd..dc900c1754 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_server.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_server.go @@ -14,9 +14,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIECServer() *schema.Resource { +func DataSourceServer() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIECServerRead, + ReadContext: dataSourceServerRead, Schema: map[string]*schema.Schema{ "name": { @@ -92,8 +92,8 @@ func DataSourceIECServer() *schema.Resource { }, }, - "nics": iecServerNicsSchema, - "volume_attached": iecVolumeAttachedSchema, + "nics": serverNicsSchema, + "volume_attached": volumeAttachedSchema, "public_ip": { Type: schema.TypeString, Computed: true, @@ -106,11 +106,11 @@ func DataSourceIECServer() *schema.Resource { } } -func dataSourceIECServerRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceServerRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } listOpts := &servers.ListOpts{ @@ -140,9 +140,9 @@ func dataSourceIECServerRead(_ context.Context, d *schema.ResourceData, meta int d.SetId(server.ID) - allNics, eip := expandIecServerNics(&server) + allNics, eip := expandServerNics(&server) // set volume fields - allVolumes, sysDiskID := expandIecServerVolumeAttached(iecClient, &server) + allVolumes, sysDiskID := expandServerVolumeAttached(iecClient, &server) mErr := multierror.Append(nil, d.Set("name", server.Name), diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_sites.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_sites.go index 788f64e483..f7671431ce 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_sites.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_sites.go @@ -14,9 +14,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIecSites() *schema.Resource { +func DataSourceSites() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIecSitesV1Read, + ReadContext: dataSourceSitesV1Read, Schema: map[string]*schema.Schema{ "area": { @@ -91,11 +91,11 @@ func DataSourceIecSites() *schema.Resource { } } -func dataSourceIecSitesV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceSitesV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } listOpts := sites.ListSiteOpts{ diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc.go index 07e6519672..8b872535d6 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc.go @@ -13,9 +13,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func DataSourceIECVpc() *schema.Resource { +func DataSourceVpc() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIECVpcRead, + ReadContext: dataSourceVpcRead, Schema: map[string]*schema.Schema{ "region": { @@ -50,7 +50,7 @@ func DataSourceIECVpc() *schema.Resource { } } -func dataSourceIECVpcRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceVpcRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) region := cfg.GetRegion(d) iecClient, err := cfg.IECV1Client(region) diff --git a/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc_subnets.go b/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc_subnets.go index 01e630d067..a170a2038e 100644 --- a/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc_subnets.go +++ b/huaweicloud/services/iec/data_source_huaweicloud_iec_vpc_subnets.go @@ -13,9 +13,9 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/hashcode" ) -func DataSourceIECVpcSubnets() *schema.Resource { +func DataSourceVpcSubnets() *schema.Resource { return &schema.Resource{ - ReadContext: dataSourceIECVpcSubnetIdsRead, + ReadContext: dataSourceVpcSubnetsRead, Schema: map[string]*schema.Schema{ "region": { @@ -79,7 +79,7 @@ func DataSourceIECVpcSubnets() *schema.Resource { } } -func dataSourceIECVpcSubnetIdsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceVpcSubnetsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) region := cfg.GetRegion(d) iecClient, err := cfg.IECV1Client(region) diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_eip.go b/huaweicloud/services/iec/resource_huaweicloud_iec_eip.go index 5c3fb1fae1..9f35ca51d3 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_eip.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_eip.go @@ -21,12 +21,12 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/eip" ) -func ResourceIecNetworkEip() *schema.Resource { +func ResourceEip() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecEipCreate, - ReadContext: resourceIecEipRead, - UpdateContext: resourceIecEipUpdate, - DeleteContext: resourceIecEipDelete, + CreateContext: resourceEipCreate, + ReadContext: resourceEipRead, + UpdateContext: resourceEipUpdate, + DeleteContext: resourceEipDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -102,7 +102,7 @@ func ResourceIecNetworkEip() *schema.Resource { } } -func resourceIecEipCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceEipCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) eipClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -133,7 +133,7 @@ func resourceIecEipCreate(ctx context.Context, d *schema.ResourceData, meta inte log.Printf("[DEBUG] waiting for public IP (%s) to become active", d.Id()) stateConf := &resource.StateChangeConf{ Target: []string{"ACTIVE", "UNBOUND"}, - Refresh: waitForIecEipStatus(eipClient, d.Id()), + Refresh: waitForEipStatus(eipClient, d.Id()), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, @@ -153,10 +153,10 @@ func resourceIecEipCreate(ctx context.Context, d *schema.ResourceData, meta inte } } - return resourceIecEipRead(ctx, d, cfg) + return resourceEipRead(ctx, d, cfg) } -func resourceIecEipRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceEipRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) eipClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -200,7 +200,7 @@ func resourceIecEipRead(_ context.Context, d *schema.ResourceData, meta interfac return nil } -func resourceIecEipUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceEipUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) eipClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -225,10 +225,10 @@ func resourceIecEipUpdate(ctx context.Context, d *schema.ResourceData, meta inte } } - return resourceIecEipRead(ctx, d, meta) + return resourceEipRead(ctx, d, meta) } -func resourceIecEipDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceEipDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) eipClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -251,7 +251,7 @@ func resourceIecEipDelete(ctx context.Context, d *schema.ResourceData, meta inte // waiting for public IP to become deleted stateConf := &resource.StateChangeConf{ Target: []string{"DELETED"}, - Refresh: waitForIecEipStatus(eipClient, d.Id()), + Refresh: waitForEipStatus(eipClient, d.Id()), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, @@ -283,7 +283,7 @@ func operateOnPort(d *schema.ResourceData, client *golangsdk.ServiceClient, port return nil } -func waitForIecEipStatus(client *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { +func waitForEipStatus(client *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { n, err := publicips.Get(client, id).Extract() if err != nil { diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_keypair.go b/huaweicloud/services/iec/resource_huaweicloud_iec_keypair.go index 01ece473dd..46e26efc88 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_keypair.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_keypair.go @@ -53,7 +53,7 @@ func resourceKeypairCreate(ctx context.Context, d *schema.ResourceData, meta int cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } createOpts := keypairs.CreateOpts{ @@ -76,7 +76,7 @@ func resourceKeypairRead(_ context.Context, d *schema.ResourceData, meta interfa cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } kp, err := keypairs.Get(iecClient, d.Id()).Extract() @@ -100,7 +100,7 @@ func resourceKeypairDelete(_ context.Context, d *schema.ResourceData, meta inter cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } err = keypairs.Delete(iecClient, d.Id()).ExtractErr() diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_network_acl.go b/huaweicloud/services/iec/resource_huaweicloud_iec_network_acl.go index 7426e1b9f4..1b92e6be26 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_network_acl.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_network_acl.go @@ -93,7 +93,7 @@ func resourceNetworkACLCreate(ctx context.Context, d *schema.ResourceData, meta conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } createOpts := firewalls.CreateOpts{ @@ -129,7 +129,7 @@ func resourceNetworkACLRead(_ context.Context, d *schema.ResourceData, meta inte iecClient, err := conf.IECV1Client(conf.GetRegion(d)) var mErr *multierror.Error if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } fwGroup, err := firewalls.Get(iecClient, d.Id()).Extract() @@ -164,7 +164,7 @@ func resourceNetworkACLUpdate(ctx context.Context, d *schema.ResourceData, meta conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } if d.HasChanges("name", "description", "networks") { @@ -196,7 +196,7 @@ func resourceNetworkACLDelete(_ context.Context, d *schema.ResourceData, meta in conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { - return diag.Errorf("error creating IEC v1 client: %s", err) + return diag.Errorf("error creating IEC client: %s", err) } // Unbind subents before deleting the network acl. diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_security_group.go b/huaweicloud/services/iec/resource_huaweicloud_iec_security_group.go index 4c6e1a2e84..2b1a8f009d 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_security_group.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_security_group.go @@ -18,11 +18,11 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func ResourceIecSecurityGroup() *schema.Resource { +func ResourceSecurityGroup() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecSecurityGroupV1Create, - ReadContext: resourceIecSecurityGroupV1Read, - DeleteContext: resourceIecSecurityGroupV1Delete, + CreateContext: resourceSecurityGroupCreate, + ReadContext: resourceSecurityGroupRead, + DeleteContext: resourceSecurityGroupDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, @@ -96,7 +96,7 @@ func ResourceIecSecurityGroup() *schema.Resource { } } -func resourceIecSecurityGroupV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSecurityGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -114,10 +114,10 @@ func resourceIecSecurityGroupV1Create(ctx context.Context, d *schema.ResourceDat } d.SetId(group.ID) - return resourceIecSecurityGroupV1Read(ctx, d, meta) + return resourceSecurityGroupRead(ctx, d, meta) } -func resourceIecSecurityGroupV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSecurityGroupRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -163,7 +163,7 @@ func resourceIecSecurityGroupV1Read(_ context.Context, d *schema.ResourceData, m return nil } -func resourceIecSecurityGroupV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSecurityGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_security_group_rule.go b/huaweicloud/services/iec/resource_huaweicloud_iec_security_group_rule.go index 305d5c4431..632d185c7b 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_security_group_rule.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_security_group_rule.go @@ -20,11 +20,11 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func ResourceIecSecurityGroupRule() *schema.Resource { +func ResourceSecurityGroupRule() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecSecurityGroupRuleV1Create, - ReadContext: resourceIecSecurityGroupRuleV1Read, - DeleteContext: resourceIecSecurityGroupRuleV1Delete, + CreateContext: resourceSecurityGroupRuleCreate, + ReadContext: resourceSecurityGroupRuleRead, + DeleteContext: resourceSecurityGroupRuleDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -96,7 +96,7 @@ func ResourceIecSecurityGroupRule() *schema.Resource { } } -func resourceIecSecurityGroupRuleV1Create(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSecurityGroupRuleCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -132,10 +132,10 @@ func resourceIecSecurityGroupRuleV1Create(ctx context.Context, d *schema.Resourc } d.SetId(rule.SecurityGroupRule.ID) - return resourceIecSecurityGroupRuleV1Read(ctx, d, meta) + return resourceSecurityGroupRuleRead(ctx, d, meta) } -func resourceIecSecurityGroupRuleV1Read(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSecurityGroupRuleRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -171,7 +171,7 @@ func resourceIecSecurityGroupRuleV1Read(_ context.Context, d *schema.ResourceDat return nil } -func resourceIecSecurityGroupRuleV1Delete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSecurityGroupRuleDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_server.go b/huaweicloud/services/iec/resource_huaweicloud_iec_server.go index aa50b3e280..b9fdd4a596 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_server.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_server.go @@ -23,7 +23,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" ) -var iecServerNicsSchema = &schema.Schema{ +var serverNicsSchema = &schema.Schema{ Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ @@ -44,7 +44,7 @@ var iecServerNicsSchema = &schema.Schema{ }, } -var iecVolumeAttachedSchema = &schema.Schema{ +var volumeAttachedSchema = &schema.Schema{ Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ @@ -73,12 +73,12 @@ var iecVolumeAttachedSchema = &schema.Schema{ }, } -func ResourceIecServer() *schema.Resource { +func ResourceServer() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecServerCreate, - ReadContext: resourceIecServerRead, - UpdateContext: resourceIecServerUpdate, - DeleteContext: resourceIecServerDelete, + CreateContext: resourceServerCreate, + ReadContext: resourceServerRead, + UpdateContext: resourceServerUpdate, + DeleteContext: resourceServerDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -228,8 +228,8 @@ func ResourceIecServer() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "nics": iecServerNicsSchema, - "volume_attached": iecVolumeAttachedSchema, + "nics": serverNicsSchema, + "volume_attached": volumeAttachedSchema, "public_ip": { Type: schema.TypeString, Computed: true, @@ -330,7 +330,7 @@ func buildServerCoverage(d *schema.ResourceData) ieccommon.Coverage { return coverageOpts } -func resourceIecServerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceServerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -406,10 +406,10 @@ func resourceIecServerCreate(ctx context.Context, d *schema.ResourceData, meta i log.Printf("[WARN] updating name of IEC server (%s) failed: %s", serverID, err) } - return resourceIecServerRead(ctx, d, meta) + return resourceServerRead(ctx, d, meta) } -func resourceIecServerRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceServerRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -424,8 +424,8 @@ func resourceIecServerRead(_ context.Context, d *schema.ResourceData, meta inter edgeServer := iecServers.Server log.Printf("[DEBUG] retrieved server %s: %+v", d.Id(), edgeServer) - allNics, eip := expandIecServerNics(edgeServer) - allVolumes, sysDiskID := expandIecServerVolumeAttached(iecClient, edgeServer) + allNics, eip := expandServerNics(edgeServer) + allVolumes, sysDiskID := expandServerVolumeAttached(iecClient, edgeServer) mErr := multierror.Append( d.Set("name", edgeServer.Name), @@ -455,7 +455,7 @@ func resourceIecServerRead(_ context.Context, d *schema.ResourceData, meta inter return nil } -func resourceIecServerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceServerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -475,13 +475,13 @@ func resourceIecServerUpdate(ctx context.Context, d *schema.ResourceData, meta i return diag.Errorf("error updating IEC server: %s", err) } - return resourceIecServerRead(ctx, d, meta) + return resourceServerRead(ctx, d, meta) } return nil } -func resourceIecServerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceServerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { cfg := meta.(*config.Config) iecClient, err := cfg.IECV1Client(cfg.GetRegion(d)) if err != nil { @@ -541,7 +541,7 @@ func serverStateRefreshFunc(client *golangsdk.ServiceClient, id string) resource } } -func expandIecServerNics(edgeServer *servers.Server) ([]map[string]interface{}, string) { +func expandServerNics(edgeServer *servers.Server) ([]map[string]interface{}, string) { var publicIP string allNics := make([]map[string]interface{}, 0) @@ -563,7 +563,7 @@ func expandIecServerNics(edgeServer *servers.Server) ([]map[string]interface{}, return allNics, publicIP } -func expandIecServerVolumeAttached(client *golangsdk.ServiceClient, edgeServer *servers.Server) ([]map[string]interface{}, string) { +func expandServerVolumeAttached(client *golangsdk.ServiceClient, edgeServer *servers.Server) ([]map[string]interface{}, string) { var sysDiskID string allVolumes := make([]map[string]interface{}, 0, len(edgeServer.VolumeAttached)) diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_vip.go b/huaweicloud/services/iec/resource_huaweicloud_iec_vip.go index 78323a3465..784157b108 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_vip.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_vip.go @@ -20,12 +20,12 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func ResourceIecVip() *schema.Resource { +func ResourceVip() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecVIPCreate, - UpdateContext: resourceIecVIPUpdate, - ReadContext: resourceIecVIPRead, - DeleteContext: resourceIecVIPDelete, + CreateContext: resourceVipCreate, + UpdateContext: resourceVipUpdate, + ReadContext: resourceVipRead, + DeleteContext: resourceVipDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, @@ -66,7 +66,7 @@ func ResourceIecVip() *schema.Resource { } } -func getIecVipPortIDs(d *schema.ResourceData) []string { +func getVipPortIDs(d *schema.ResourceData) []string { rawPortIDs := d.Get("port_ids").([]interface{}) portids := make([]string, len(rawPortIDs)) for i, raw := range rawPortIDs { @@ -75,7 +75,7 @@ func getIecVipPortIDs(d *schema.ResourceData) []string { return portids } -func resourceIecVIPCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVipCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) region := conf.GetRegion(d) iecClient, err := conf.IECV1Client(region) @@ -124,17 +124,17 @@ func resourceIecVIPCreate(ctx context.Context, d *schema.ResourceData, meta inte } // associate ports with the vip - portids := getIecVipPortIDs(d) + portids := getVipPortIDs(d) if len(portids) > 0 { - if err = updateIecVipAssociate(iecClient, p.ID, portids); err != nil { + if err = updateVipAssociate(iecClient, p.ID, portids); err != nil { return diag.FromErr(err) } } - return resourceIecVIPRead(ctx, d, meta) + return resourceVipRead(ctx, d, meta) } -func resourceIecVIPRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVipRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) region := conf.GetRegion(d) iecClient, err := conf.IECV1Client(region) @@ -167,7 +167,7 @@ func resourceIecVIPRead(_ context.Context, d *schema.ResourceData, meta interfac return diag.FromErr(mErr.ErrorOrNil()) } -func resourceIecVIPUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVipUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) region := conf.GetRegion(d) iecClient, err := conf.IECV1Client(region) @@ -175,15 +175,15 @@ func resourceIecVIPUpdate(ctx context.Context, d *schema.ResourceData, meta inte return diag.Errorf("error creating IEC client: %s", err) } - portids := getIecVipPortIDs(d) - if err = updateIecVipAssociate(iecClient, d.Id(), portids); err != nil { - return diag.Errorf("error updateIecVipAssociate: %s", err) + portids := getVipPortIDs(d) + if err = updateVipAssociate(iecClient, d.Id(), portids); err != nil { + return diag.Errorf("error updateVipAssociate: %s", err) } - return resourceIecVIPRead(ctx, d, meta) + return resourceVipRead(ctx, d, meta) } -func resourceIecVIPDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVipDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) region := conf.GetRegion(d) iecClient, err := conf.IECV1Client(region) @@ -191,10 +191,10 @@ func resourceIecVIPDelete(ctx context.Context, d *schema.ResourceData, meta inte return diag.Errorf("error creating IEC client: %s", err) } - if len(getIecVipPortIDs(d)) > 0 { + if len(getVipPortIDs(d)) > 0 { // disassociate ports - if err := updateIecVipAssociate(iecClient, d.Id(), []string{}); err != nil { - return diag.Errorf("error updateIecVipAssociate: %s", err) + if err := updateVipAssociate(iecClient, d.Id(), []string{}); err != nil { + return diag.Errorf("error updateVipAssociate: %s", err) } } @@ -255,7 +255,7 @@ func waitingForIECVIPDelete(client *golangsdk.ServiceClient, portID string) reso } } -func updateIecVipAssociate(client *golangsdk.ServiceClient, vipID string, portIDs []string) error { +func updateVipAssociate(client *golangsdk.ServiceClient, vipID string, portIDs []string) error { allAddrs := make([]string, len(portIDs)) action := "associate" if len(portIDs) == 0 { diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_vpc.go b/huaweicloud/services/iec/resource_huaweicloud_iec_vpc.go index 80a05a820d..2c7391c430 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_vpc.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_vpc.go @@ -15,12 +15,12 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func ResourceIecVpc() *schema.Resource { +func ResourceVpc() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecVpcCreate, - ReadContext: resourceIecVpcRead, - UpdateContext: resourceIecVpcUpdate, - DeleteContext: resourceIecVpcDelete, + CreateContext: resourceVpcCreate, + ReadContext: resourceVpcRead, + UpdateContext: resourceVpcUpdate, + DeleteContext: resourceVpcDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, @@ -58,7 +58,7 @@ func ResourceIecVpc() *schema.Resource { } } -func resourceIecVpcCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVpcCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) @@ -80,10 +80,10 @@ func resourceIecVpcCreate(ctx context.Context, d *schema.ResourceData, meta inte log.Printf("[INFO] IEC VPC ID: %s", n.ID) d.SetId(n.ID) - return resourceIecVpcRead(ctx, d, meta) + return resourceVpcRead(ctx, d, meta) } -func resourceIecVpcRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVpcRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { @@ -104,7 +104,7 @@ func resourceIecVpcRead(_ context.Context, d *schema.ResourceData, meta interfac return diag.FromErr(mErr.ErrorOrNil()) } -func resourceIecVpcUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVpcUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { @@ -125,10 +125,10 @@ func resourceIecVpcUpdate(ctx context.Context, d *schema.ResourceData, meta inte return diag.Errorf("error updating IEC VPC: %s", err) } - return resourceIecVpcRead(ctx, d, meta) + return resourceVpcRead(ctx, d, meta) } -func resourceIecVpcDelete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceVpcDelete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) iecClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { diff --git a/huaweicloud/services/iec/resource_huaweicloud_iec_vpc_subnet.go b/huaweicloud/services/iec/resource_huaweicloud_iec_vpc_subnet.go index 298dcca247..5384bb7879 100644 --- a/huaweicloud/services/iec/resource_huaweicloud_iec_vpc_subnet.go +++ b/huaweicloud/services/iec/resource_huaweicloud_iec_vpc_subnet.go @@ -18,7 +18,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" ) -func buildIecSubnetDNSList(d *schema.ResourceData) []string { +func buildSubnetDNSList(d *schema.ResourceData) []string { rawDNSN := d.Get("dns_list").([]interface{}) // set the default DNS if it was not specified @@ -33,12 +33,12 @@ func buildIecSubnetDNSList(d *schema.ResourceData) []string { return dnsn } -func ResourceIecSubnet() *schema.Resource { +func ResourceSubnet() *schema.Resource { return &schema.Resource{ - CreateContext: resourceIecSubnetCreate, - ReadContext: resourceIecSubnetRead, - UpdateContext: resourceIecSubnetUpdate, - DeleteContext: resourceIecSubnetDelete, + CreateContext: resourceSubnetCreate, + ReadContext: resourceSubnetRead, + UpdateContext: resourceSubnetUpdate, + DeleteContext: resourceSubnetDelete, Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, @@ -104,7 +104,7 @@ func ResourceIecSubnet() *schema.Resource { } } -func resourceIecSubnetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSubnetCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) subnetClient, err := conf.IECV1Client(conf.GetRegion(d)) @@ -120,7 +120,7 @@ func resourceIecSubnetCreate(ctx context.Context, d *schema.ResourceData, meta i SiteID: d.Get("site_id").(string), GatewayIP: d.Get("gateway_ip").(string), DhcpEnable: &dhcp, - DNSList: buildIecSubnetDNSList(d), + DNSList: buildSubnetDNSList(d), } log.Printf("[DEBUG] Create Options: %#v", createOpts) @@ -135,7 +135,7 @@ func resourceIecSubnetCreate(ctx context.Context, d *schema.ResourceData, meta i stateConf := &resource.StateChangeConf{ Pending: []string{"UNKNOWN"}, Target: []string{"ACTIVE"}, - Refresh: waitForIecSubnetStatus(subnetClient, n.ID), + Refresh: waitForSubnetStatus(subnetClient, n.ID), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, @@ -148,10 +148,10 @@ func resourceIecSubnetCreate(ctx context.Context, d *schema.ResourceData, meta i n.ID, stateErr) } - return resourceIecSubnetRead(ctx, d, conf) + return resourceSubnetRead(ctx, d, conf) } -func resourceIecSubnetRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSubnetRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) subnetClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { @@ -179,7 +179,7 @@ func resourceIecSubnetRead(_ context.Context, d *schema.ResourceData, meta inter return diag.FromErr(mErr.ErrorOrNil()) } -func resourceIecSubnetUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSubnetUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) subnetClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { @@ -205,10 +205,10 @@ func resourceIecSubnetUpdate(ctx context.Context, d *schema.ResourceData, meta i return diag.Errorf("error updating IEC subnets: %s", err) } - return resourceIecSubnetRead(ctx, d, meta) + return resourceSubnetRead(ctx, d, meta) } -func resourceIecSubnetDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func resourceSubnetDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conf := meta.(*config.Config) subnetClient, err := conf.IECV1Client(conf.GetRegion(d)) if err != nil { @@ -224,7 +224,7 @@ func resourceIecSubnetDelete(ctx context.Context, d *schema.ResourceData, meta i stateConf := &resource.StateChangeConf{ Pending: []string{"ACTIVE", "UNKNOWN"}, Target: []string{"DELETED"}, - Refresh: waitForIecSubnetStatus(subnetClient, d.Id()), + Refresh: waitForSubnetStatus(subnetClient, d.Id()), Timeout: d.Timeout(schema.TimeoutCreate), Delay: 5 * time.Second, MinTimeout: 3 * time.Second, @@ -240,7 +240,7 @@ func resourceIecSubnetDelete(ctx context.Context, d *schema.ResourceData, meta i return nil } -func waitForIecSubnetStatus(subnetClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { +func waitForSubnetStatus(subnetClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { n, err := subnets.Get(subnetClient, id).Extract() if err != nil {