This is an automated email from the ASF dual-hosted git repository.

vishesh pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/cloudstack-terraform-provider.git


The following commit(s) were added to refs/heads/main by this push:
     new e5955fd  Fixup acceptance tests (#96)
e5955fd is described below

commit e5955fd3036658308e7f46f62de29fde6151a986
Author: Vishesh <vishes...@gmail.com>
AuthorDate: Thu Mar 7 17:31:50 2024 +0530

    Fixup acceptance tests (#96)
---
 .github/workflows/testacc.yml                      |  2 ++
 cloudstack/data_source_cloudstack_instance_test.go |  5 ++--
 .../data_source_cloudstack_ipaddress_test.go       |  4 +--
 ...data_source_cloudstack_service_offering_test.go | 28 ++++++++---------
 cloudstack/data_source_cloudstack_volume_test.go   | 35 ++++++++++++++--------
 cloudstack/data_source_cloudstack_vpc_test.go      |  2 +-
 cloudstack/resource_cloudstack_instance_test.go    |  4 +--
 cloudstack/resource_cloudstack_private_gateway.go  |  2 +-
 .../resource_cloudstack_private_gateway_test.go    |  2 ++
 cloudstack/resource_cloudstack_template.go         | 28 ++++++++++-------
 cloudstack/resource_cloudstack_template_test.go    | 12 ++++----
 11 files changed, 72 insertions(+), 52 deletions(-)

diff --git a/.github/workflows/testacc.yml b/.github/workflows/testacc.yml
index fa364f8..e2adc43 100644
--- a/.github/workflows/testacc.yml
+++ b/.github/workflows/testacc.yml
@@ -65,6 +65,7 @@ jobs:
 
           echo "CLOUDSTACK_API_KEY=$CLOUDSTACK_API_KEY" >> $GITHUB_ENV
           echo "CLOUDSTACK_SECRET_KEY=$CLOUDSTACK_SECRET_KEY" >> $GITHUB_ENV
+          echo 
"CLOUDSTACK_TEMPLATE_URL=http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-xen.vhd.bz2";
 >> $GITHUB_ENV
       - name: Install CMK
         run: |
           curl -sfL 
https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64
 -o /usr/local/bin/cmk
@@ -81,6 +82,7 @@ jobs:
         ports:
           - 8080:5050
     strategy:
+      fail-fast: false
       matrix:
         cloudstack_version:
           - 4.17.2.0
diff --git a/cloudstack/data_source_cloudstack_instance_test.go 
b/cloudstack/data_source_cloudstack_instance_test.go
index f9d531a..1461648 100644
--- a/cloudstack/data_source_cloudstack_instance_test.go
+++ b/cloudstack/data_source_cloudstack_instance_test.go
@@ -50,9 +50,8 @@ const testAccInstanceDataSourceConfig_basic = `
        resource "cloudstack_instance" "my_instance" {
                name             = "server-a"
                service_offering = "Small Instance"
-               network_id       = "b9c953a0-8686-4240-b8a4-43849f7079ff"
-               template         = "CentOS 5.5(64-bit) no GUI (KVM)"
-               zone             = "DC"
+               template         = "CentOS 5.6 (64-bit) no GUI (Simulator)"
+               zone             = "Sandbox-simulator"
          }
          data "cloudstack_instance" "my_instance_test" {
                filter {
diff --git a/cloudstack/data_source_cloudstack_ipaddress_test.go 
b/cloudstack/data_source_cloudstack_ipaddress_test.go
index ad98201..2e32b61 100644
--- a/cloudstack/data_source_cloudstack_ipaddress_test.go
+++ b/cloudstack/data_source_cloudstack_ipaddress_test.go
@@ -46,13 +46,13 @@ func TestAccIPAddressDataSource_basic(t *testing.T) {
 
 const testIPAddressDataSourceConfig_basic = `
 resource "cloudstack_ipaddress" "ipaddress-resource" {
-       zone         = "DC"
+       zone         = "Sandbox-simulator"
   }
   
   data "cloudstack_ipaddress" "ipaddress-data-source"{
          filter{
          name = "zone_name"
-         value= "DC"
+         value= "Sandbox-simulator"
          }
          depends_on = [
                cloudstack_ipaddress.ipaddress-resource
diff --git a/cloudstack/data_source_cloudstack_service_offering_test.go 
b/cloudstack/data_source_cloudstack_service_offering_test.go
index fbc3faa..d745539 100644
--- a/cloudstack/data_source_cloudstack_service_offering_test.go
+++ b/cloudstack/data_source_cloudstack_service_offering_test.go
@@ -27,7 +27,7 @@ import (
 
 func TestAccServiceOfferingDataSource_basic(t *testing.T) {
        resourceName := "cloudstack_service_offering.service-offering-resource"
-       datasourceName := 
"cloudstack_service_offering.service-offering-data-source"
+       datasourceName := 
"data.cloudstack_service_offering.service-offering-data-source"
 
        resource.Test(t, resource.TestCase{
                PreCheck:  func() { testAccPreCheck(t) },
@@ -45,18 +45,16 @@ func TestAccServiceOfferingDataSource_basic(t *testing.T) {
 }
 
 const testServiceOfferingDataSourceConfig_basic = `
-resource "cloudstack_service_offering" "service-offering-resource"{
-       name       = "TestServiceUpdate"
-  display_text = "DisplayService"
-  }
+resource "cloudstack_service_offering" "service-offering-resource" {
+       name                    = "TestServiceUpdate"
+       display_text    = "DisplayService"
+}
 
- data "cloudstack_service_offering" "service-offering-data-source"{
-    filter{
-    name = "name"
-    value="TestServiceUpdate"
-    }
-         depends_on = [
-         cloudstack_service_offering.service-resource
-       ] 
-  }
-  `
+data "cloudstack_service_offering" "service-offering-data-source" {
+       filter {
+               name    = "name"
+               value   = "TestServiceUpdate"
+       }
+       depends_on = [cloudstack_service_offering.service-offering-resource]
+}
+`
diff --git a/cloudstack/data_source_cloudstack_volume_test.go 
b/cloudstack/data_source_cloudstack_volume_test.go
index 147a701..810ecdf 100644
--- a/cloudstack/data_source_cloudstack_volume_test.go
+++ b/cloudstack/data_source_cloudstack_volume_test.go
@@ -45,19 +45,30 @@ func TestAccVolumeDataSource_basic(t *testing.T) {
 }
 
 const testVolumeDataSourceConfig_basic = `
+resource "cloudstack_disk_offering" "disk-offering" {
+       name                    =       "TestDiskOffering"
+       display_text    =       "TestDiskOffering"
+       disk_size               =       1
+}
+
+data "cloudstack_zone" "zone-data-source" {
+       filter {
+               name    =       "name"
+               value   =       "Sandbox-simulator"
+       }
+}
+
 resource "cloudstack_volume" "volume-resource"{
-       name       = "TestVolume"
-  disk_offering_id = "0038adec-5e3e-47df-b4b4-77b5dc8e3338"
-  zone_id = "9a7002b2-09a2-44dc-a332-f2e4e7f01539"
+       name                            =       "TestVolume"
+       disk_offering_id        =       
"${cloudstack_disk_offering.disk-offering.id}"
+       zone_id                         =       
"${data.cloudstack_zone.zone-data-source.id}"
   }
 
-  data "cloudstack_volume" "volume-data-source"{
-    filter{
-    name = "name"
-    value="TestVolume"
+data "cloudstack_volume" "volume-data-source"{
+       filter {
+               name    =       "name"
+               value   =       "TestVolume"
     }
-         depends_on = [
-         cloudstack_volume.volume-resource
-       ]
-  }
-  `
+       depends_on      =       [cloudstack_volume.volume-resource]
+}
+`
diff --git a/cloudstack/data_source_cloudstack_vpc_test.go 
b/cloudstack/data_source_cloudstack_vpc_test.go
index 3920f02..40d3f86 100644
--- a/cloudstack/data_source_cloudstack_vpc_test.go
+++ b/cloudstack/data_source_cloudstack_vpc_test.go
@@ -49,7 +49,7 @@ resource "cloudstack_vpc" "vpc-resource" {
 name         = "test-vpc"
 cidr         = "10.0.0.0/16"
 vpc_offering = "Default VPC Offering"
-zone         = "DC"
+zone         = "Sandbox-simulator"
 }
 
 data "cloudstack_vpc" "vpc-data-source"{
diff --git a/cloudstack/resource_cloudstack_instance_test.go 
b/cloudstack/resource_cloudstack_instance_test.go
index fb313af..86e8fbc 100644
--- a/cloudstack/resource_cloudstack_instance_test.go
+++ b/cloudstack/resource_cloudstack_instance_test.go
@@ -185,7 +185,7 @@ func TestAccCloudStackInstance_import(t *testing.T) {
                                ResourceName:            
"cloudstack_instance.foobar",
                                ImportState:             true,
                                ImportStateVerify:       true,
-                               ImportStateVerifyIgnore: []string{"expunge", 
"user_data"},
+                               ImportStateVerifyIgnore: []string{"expunge", 
"user_data", "uefi"},
                        },
                },
        })
@@ -206,7 +206,7 @@ func TestAccCloudStackInstance_importProject(t *testing.T) {
                                ImportState:             true,
                                ImportStateIdPrefix:     "terraform/",
                                ImportStateVerify:       true,
-                               ImportStateVerifyIgnore: []string{"expunge", 
"user_data"},
+                               ImportStateVerifyIgnore: []string{"expunge", 
"user_data", "uefi"},
                        },
                },
        })
diff --git a/cloudstack/resource_cloudstack_private_gateway.go 
b/cloudstack/resource_cloudstack_private_gateway.go
index ec5b935..c4b6c82 100644
--- a/cloudstack/resource_cloudstack_private_gateway.go
+++ b/cloudstack/resource_cloudstack_private_gateway.go
@@ -148,7 +148,7 @@ func resourceCloudStackPrivateGatewayRead(d 
*schema.ResourceData, meta interface
        d.Set("gateway", gw.Gateway)
        d.Set("ip_address", gw.Ipaddress)
        d.Set("netmask", gw.Netmask)
-       d.Set("vlan", gw.Vlan)
+       d.Set("vlan", strings.Replace(gw.Vlan, "vlan://", "", -1))
        d.Set("acl_id", gw.Aclid)
        d.Set("vpc_id", gw.Vpcid)
 
diff --git a/cloudstack/resource_cloudstack_private_gateway_test.go 
b/cloudstack/resource_cloudstack_private_gateway_test.go
index a7cd6fe..66af8c3 100644
--- a/cloudstack/resource_cloudstack_private_gateway_test.go
+++ b/cloudstack/resource_cloudstack_private_gateway_test.go
@@ -148,6 +148,7 @@ resource "cloudstack_vpc" "foo" {
 resource "cloudstack_network_acl" "foo" {
   name = "terraform-acl"
   vpc_id = "${cloudstack_vpc.foo.id}"
+  depends_on = ["cloudstack_vpc.foo"]
 }
 
 resource "cloudstack_private_gateway" "foo" {
@@ -157,4 +158,5 @@ resource "cloudstack_private_gateway" "foo" {
   vlan = "1"
   vpc_id = "${cloudstack_vpc.foo.id}"
   acl_id = "${cloudstack_network_acl.foo.id}"
+  depends_on = ["cloudstack_vpc.foo","cloudstack_network_acl.foo"]
 }`
diff --git a/cloudstack/resource_cloudstack_template.go 
b/cloudstack/resource_cloudstack_template.go
index 967dcf1..c1a4f87 100644
--- a/cloudstack/resource_cloudstack_template.go
+++ b/cloudstack/resource_cloudstack_template.go
@@ -243,22 +243,30 @@ func resourceCloudStackTemplateRead(d 
*schema.ResourceData, meta interface{}) er
        p := cs.Template.NewListTemplatesParams("executable")
        p.SetId(d.Id())
        p.SetShowunique(true)
-       p.SetProjectid(d.Get("project").(string))
+       project := d.Get("project").(string)
+       if project != "" {
+               if !cloudstack.IsID(project) {
+                       id, _, err := cs.Project.GetProjectID(project)
+                       if err != nil {
+                               return err
+                       }
+                       project = id
+               }
+               p.SetProjectid(project)
+       }
 
        r, err := cs.Template.ListTemplates(p)
-       count := r.Count
-       t := r.Templates[0]
        if err != nil {
-               if count == 0 {
-                       log.Printf(
-                               "[DEBUG] Template %s no longer exists", 
d.Get("name").(string))
-                       d.SetId("")
-                       return nil
-               }
-
                return err
+       } else if r.Count == 0 {
+               log.Printf(
+                       "[DEBUG] Template %s no longer exists", 
d.Get("name").(string))
+               d.SetId("")
+               return nil
        }
 
+       t := r.Templates[0]
+
        d.Set("name", t.Name)
        d.Set("display_text", t.Displaytext)
        d.Set("format", t.Format)
diff --git a/cloudstack/resource_cloudstack_template_test.go 
b/cloudstack/resource_cloudstack_template_test.go
index 9265c8f..da18552 100644
--- a/cloudstack/resource_cloudstack_template_test.go
+++ b/cloudstack/resource_cloudstack_template_test.go
@@ -125,7 +125,7 @@ func testAccCheckCloudStackTemplateBasicAttributes(
                        return fmt.Errorf("Bad name: %s", template.Name)
                }
 
-               if template.Format != "QCOW2" {
+               if template.Format != "VHD" {
                        return fmt.Errorf("Bad format: %s", template.Format)
                }
 
@@ -133,7 +133,7 @@ func testAccCheckCloudStackTemplateBasicAttributes(
                        return fmt.Errorf("Bad hypervisor: %s", 
template.Hypervisor)
                }
 
-               if template.Ostypename != "Centos 5.6 (64-bit)" {
+               if template.Ostypename != "CentOS 5.6 (64-bit)" {
                        return fmt.Errorf("Bad os type: %s", 
template.Ostypename)
                }
 
@@ -189,9 +189,9 @@ func testAccCheckCloudStackTemplateDestroy(s 
*terraform.State) error {
 var testAccCloudStackTemplate_basic = fmt.Sprintf(`
 resource "cloudstack_template" "foo" {
   name = "terraform-test"
-  format = "QCOW2"
+  format = "VHD"
   hypervisor = "Simulator"
-  os_type = "Centos 5.6 (64-bit)"
+  os_type = "CentOS 5.6 (64-bit)"
   url = "%s"
   zone = "Sandbox-simulator"
   tags = {
@@ -203,9 +203,9 @@ var testAccCloudStackTemplate_update = fmt.Sprintf(`
 resource "cloudstack_template" "foo" {
   name = "terraform-test"
   display_text = "terraform-updated"
-  format = "QCOW2"
+  format = "VHD"
   hypervisor = "Simulator"
-  os_type = "Centos 5.6 (64-bit)"
+  os_type = "CentOS 5.6 (64-bit)"
   url = "%s"
   is_dynamically_scalable = true
   password_enabled = true

Reply via email to