diff --git a/nutanix/data_source_nutanix_access_control_policy_test.go b/nutanix/data_source_nutanix_access_control_policy_test.go index c1a34b396..4c175d286 100644 --- a/nutanix/data_source_nutanix_access_control_policy_test.go +++ b/nutanix/data_source_nutanix_access_control_policy_test.go @@ -12,13 +12,14 @@ import ( func TestAccNutanixAccessControlPolicyDataSourceByID_basic(t *testing.T) { name := acctest.RandomWithPrefix("accest-access-policy") description := "Description of my access control policy" + roleName := acctest.RandomWithPrefix("test-acc-role") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccAccessControlPolicyDataSourceByIDConfig(name, description), + Config: testAccAccessControlPolicyDataSourceByIDConfig(name, description, roleName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.nutanix_access_control_policy.test", "name", name), @@ -34,13 +35,14 @@ func TestAccNutanixAccessControlPolicyDataSourceByID_basic(t *testing.T) { func TestAccNutanixAccessControlPolicyDataSourceByName_basic(t *testing.T) { name := acctest.RandomWithPrefix("accest-access-policy") description := "Description of my access control policy" + roleName := acctest.RandomWithPrefix("test-acc-role") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccAccessControlPolicyDataSourceByNameConfig(name, description), + Config: testAccAccessControlPolicyDataSourceByNameConfig(name, description, roleName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "data.nutanix_access_control_policy.test", "name", name), @@ -53,10 +55,10 @@ func TestAccNutanixAccessControlPolicyDataSourceByName_basic(t *testing.T) { }) } -func testAccAccessControlPolicyDataSourceByIDConfig(name, description string) string { +func testAccAccessControlPolicyDataSourceByIDConfig(name, description, roleName string) string { return fmt.Sprintf(` resource "nutanix_role" "test" { - name = "test role" + name = "%[3]s" description = "description role" permission_reference_list { kind = "permission" @@ -75,13 +77,13 @@ resource "nutanix_access_control_policy" "test" { data "nutanix_access_control_policy" "test" { access_control_policy_id = nutanix_access_control_policy.test.id } -`, name, description) +`, name, description, roleName) } -func testAccAccessControlPolicyDataSourceByNameConfig(name, description string) string { +func testAccAccessControlPolicyDataSourceByNameConfig(name, description, roleName string) string { return fmt.Sprintf(` resource "nutanix_role" "test" { - name = "test role 2" + name = "%[3]s" description = "description role" permission_reference_list { kind = "permission" @@ -100,5 +102,5 @@ resource "nutanix_access_control_policy" "test" { data "nutanix_access_control_policy" "test" { access_control_policy_name = nutanix_access_control_policy.test.name } -`, name, description) +`, name, description, roleName) } diff --git a/nutanix/data_source_nutanix_permission.go b/nutanix/data_source_nutanix_permission.go index bfa4ca0a1..303119065 100644 --- a/nutanix/data_source_nutanix_permission.go +++ b/nutanix/data_source_nutanix_permission.go @@ -167,7 +167,7 @@ func dataSourceNutanixPermissionRead(d *schema.ResourceData, meta interface{}) e if rnOk { resp, err = findPermissionByName(conn, permissionName.(string)) } - utils.PrintToJSON(resp, "Permission: ") + if err != nil { return err } diff --git a/nutanix/data_source_nutanix_permissions_test.go b/nutanix/data_source_nutanix_permissions_test.go index 01a98555c..a543cf7ac 100644 --- a/nutanix/data_source_nutanix_permissions_test.go +++ b/nutanix/data_source_nutanix_permissions_test.go @@ -15,8 +15,8 @@ func TestAccNutanixPermissionsDataSource_basic(t *testing.T) { Config: testAccPermissionsDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("data.nutanix_permissions.test", "entities.#"), - resource.TestCheckResourceAttr( - "data.nutanix_permissions.test", "entities.#", "485"), + resource.TestCheckResourceAttrSet( + "data.nutanix_permissions.test", "entities.#"), ), }, }, diff --git a/nutanix/data_source_nutanix_user.go b/nutanix/data_source_nutanix_user.go index 111db795f..0903809ae 100644 --- a/nutanix/data_source_nutanix_user.go +++ b/nutanix/data_source_nutanix_user.go @@ -301,7 +301,6 @@ func dataSourceNutanixUserRead(d *schema.ResourceData, meta interface{}) error { } refe := flattenArrayReferenceValues(resp.Status.Resources.AccessControlPolicyReferenceList) - utils.PrintToJSON(refe, "acceess") if err := d.Set("access_control_policy_reference_list", refe); err != nil { return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err) diff --git a/nutanix/data_source_nutanix_user_groups_test.go b/nutanix/data_source_nutanix_user_groups_test.go index 32c5faa8b..987059799 100644 --- a/nutanix/data_source_nutanix_user_groups_test.go +++ b/nutanix/data_source_nutanix_user_groups_test.go @@ -15,8 +15,6 @@ func TestAccNutanixUserGroupsDataSource_basic(t *testing.T) { Config: testAccUserGroupsDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("data.nutanix_user_groups.test", "entities.#"), - resource.TestCheckResourceAttr( - "data.nutanix_user_groups.test", "entities.#", "3"), ), }, }, diff --git a/nutanix/data_source_nutanix_user_test.go b/nutanix/data_source_nutanix_user_test.go index 074a85020..b0125422e 100644 --- a/nutanix/data_source_nutanix_user_test.go +++ b/nutanix/data_source_nutanix_user_test.go @@ -8,9 +8,9 @@ import ( ) func TestAccNutanixUserDataSource_basic(t *testing.T) { - principalName := "dou-user@ntnxlab.local" - expectedDisplayName := "dou-user" - directoryServiceUUID := "dd19a896-8e72-4158-b716-98455ceda220" + principalName := "dou-user-3@ntnxlab.local" + expectedDisplayName := "dou-user-3" + directoryServiceUUID := "542d7921-1385-4b6e-ab10-09f2ca4f054d" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -49,7 +49,7 @@ data "nutanix_user" "user" { func TestAccNutanixUserDataSource_byName(t *testing.T) { principalName := "dou-user@ntnxlab.local" expectedDisplayName := "dou-user" - directoryServiceUUID := "dd19a896-8e72-4158-b716-98455ceda220" + directoryServiceUUID := "542d7921-1385-4b6e-ab10-09f2ca4f054d" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/nutanix/data_source_nutanix_virtual_machine_test.go b/nutanix/data_source_nutanix_virtual_machine_test.go index c98bacf0f..d1954b343 100644 --- a/nutanix/data_source_nutanix_virtual_machine_test.go +++ b/nutanix/data_source_nutanix_virtual_machine_test.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -47,13 +48,14 @@ func TestAccNutanixVirtualMachineDataSource_WithDisk(t *testing.T) { func TestAccNutanixVirtualMachineDataSource_withDiskContainer(t *testing.T) { datasourceName := "data.nutanix_virtual_machine.nutanix_virtual_machine" vmName := acctest.RandomWithPrefix("test-dou-vm") + containerUUID := os.Getenv("NUTANIX_STORAGE_CONTAINER") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccVMDataSourceWithDiskContainer(vmName), + Config: testAccVMDataSourceWithDiskContainer(vmName, containerUUID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(datasourceName, "vm_id"), resource.TestCheckResourceAttrSet(datasourceName, "disk_list.#"), @@ -70,7 +72,7 @@ func TestAccNutanixVirtualMachineDataSource_withDiskContainer(t *testing.T) { }) } -func testAccVMDataSourceWithDiskContainer(vmName string) string { +func testAccVMDataSourceWithDiskContainer(vmName, containerUUID string) string { return fmt.Sprintf(` data "nutanix_clusters" "clusters" {} @@ -96,7 +98,7 @@ func testAccVMDataSourceWithDiskContainer(vmName string) string { storage_config { storage_container_reference { kind = "storage_container" - uuid = "2bbe77bc-fd14-4697-8de1-6369757f9219" + uuid = "%s" } } } @@ -105,7 +107,7 @@ func testAccVMDataSourceWithDiskContainer(vmName string) string { data "nutanix_virtual_machine" "nutanix_virtual_machine" { vm_id = nutanix_virtual_machine.vm-disk.id } - `, vmName) + `, vmName, containerUUID) } func testAccVMDataSourceConfig(r int) string { diff --git a/nutanix/helpers.go b/nutanix/helpers.go index 25f7365ef..494627504 100644 --- a/nutanix/helpers.go +++ b/nutanix/helpers.go @@ -147,7 +147,7 @@ func expandReference(ref map[string]interface{}) *v3.Reference { r.UUID = utils.StringPtr(v.(string)) hasValue = true } - if v, ok := ref["name"]; ok { + if v, ok := ref["name"]; ok && v.(string) != "" { r.Name = utils.StringPtr(v.(string)) hasValue = true } diff --git a/nutanix/provider_test.go b/nutanix/provider_test.go index bd08ff328..36676b883 100644 --- a/nutanix/provider_test.go +++ b/nutanix/provider_test.go @@ -37,8 +37,9 @@ func testAccPreCheck(t *testing.T) { os.Getenv("NUTANIX_PASSWORD") == "" || os.Getenv("NUTANIX_INSECURE") == "" || os.Getenv("NUTANIX_PORT") == "" || - os.Getenv("NUTANIX_ENDPOINT") == "" { - t.Fatal("`NUTANIX_USERNAME`,`NUTANIX_PASSWORD`,`NUTANIX_INSECURE`,`NUTANIX_PORT`,`NUTANIX_ENDPOINT` must be set for acceptance testing") + os.Getenv("NUTANIX_ENDPOINT") == "" || + os.Getenv("NUTANIX_STORAGE_CONTAINER") == "" { + t.Fatal("`NUTANIX_USERNAME`,`NUTANIX_PASSWORD`,`NUTANIX_INSECURE`,`NUTANIX_PORT`,`NUTANIX_ENDPOINT`, `NUTANIX_STORAGE_CONTAINER` must be set for acceptance testing") } } diff --git a/nutanix/resource_nutanix_access_control_policy_test.go b/nutanix/resource_nutanix_access_control_policy_test.go index e268ba08f..3e40ca4c5 100644 --- a/nutanix/resource_nutanix_access_control_policy_test.go +++ b/nutanix/resource_nutanix_access_control_policy_test.go @@ -1,7 +1,6 @@ package nutanix import ( - "encoding/json" "fmt" "strings" "testing" @@ -16,6 +15,7 @@ const resourceAccessPolicy = "nutanix_access_control_policy.test" func TestAccNutanixAccessControlPolicy_basic(t *testing.T) { name := acctest.RandomWithPrefix("accest-access-policy") + roleName := acctest.RandomWithPrefix("test-acc-role") description := "Description of my access control policy" nameUpdated := acctest.RandomWithPrefix("accest-access-policy") descriptionUpdated := "Description of my access control policy updated" @@ -26,7 +26,7 @@ func TestAccNutanixAccessControlPolicy_basic(t *testing.T) { CheckDestroy: testAccCheckNutanixAccessControlPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccNutanixAccessControlPolicyConfig(name, description), + Config: testAccNutanixAccessControlPolicyConfig(name, description, roleName), Check: resource.ComposeTestCheckFunc( testAccCheckNutanixAccessControlPolicyExists(), resource.TestCheckResourceAttr(resourceAccessPolicy, "name", name), @@ -34,7 +34,7 @@ func TestAccNutanixAccessControlPolicy_basic(t *testing.T) { ), }, { - Config: testAccNutanixAccessControlPolicyConfig(nameUpdated, descriptionUpdated), + Config: testAccNutanixAccessControlPolicyConfig(nameUpdated, descriptionUpdated, roleName), Check: resource.ComposeTestCheckFunc( testAccCheckNutanixAccessControlPolicyExists(), resource.TestCheckResourceAttr(resourceAccessPolicy, "name", nameUpdated), @@ -52,7 +52,10 @@ func TestAccNutanixAccessControlPolicy_basic(t *testing.T) { func TestAccNutanixAccessControlPolicy_WithUser(t *testing.T) { name := acctest.RandomWithPrefix("accest-access-policy") + roleName := acctest.RandomWithPrefix("test-acc-role-") description := "Description of my access control policy" + nameUpdated := acctest.RandomWithPrefix("accest-access-policy") + descriptionUpdated := "Description of my access control policy updated" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -60,13 +63,21 @@ func TestAccNutanixAccessControlPolicy_WithUser(t *testing.T) { CheckDestroy: testAccCheckNutanixAccessControlPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccNutanixAccessControlPolicyConfigWithUser(name, description), + Config: testAccNutanixAccessControlPolicyConfigWithUser(name, description, roleName), Check: resource.ComposeTestCheckFunc( testAccCheckNutanixAccessControlPolicyExists(), resource.TestCheckResourceAttr(resourceAccessPolicy, "name", name), resource.TestCheckResourceAttr(resourceAccessPolicy, "description", description), ), }, + { + Config: testAccNutanixAccessControlPolicyConfigWithUser(nameUpdated, descriptionUpdated, roleName), + Check: resource.ComposeTestCheckFunc( + testAccCheckNutanixAccessControlPolicyExists(), + resource.TestCheckResourceAttr(resourceAccessPolicy, "name", nameUpdated), + resource.TestCheckResourceAttr(resourceAccessPolicy, "description", descriptionUpdated), + ), + }, { ResourceName: resourceAccessPolicy, ImportState: true, @@ -78,6 +89,7 @@ func TestAccNutanixAccessControlPolicy_WithUser(t *testing.T) { func TestAccNutanixAccessControlPolicy_WithCategory(t *testing.T) { name := acctest.RandomWithPrefix("accest-access-policy") + roleName := acctest.RandomWithPrefix("test-acc-role-") description := "Description of my access control policy" nameUpdated := acctest.RandomWithPrefix("accest-access-policy") descriptionUpdated := "Description of my access control policy updated" @@ -88,7 +100,7 @@ func TestAccNutanixAccessControlPolicy_WithCategory(t *testing.T) { CheckDestroy: testAccCheckNutanixAccessControlPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccNutanixAccessControlPolicyConfigWithCategory(name, description, "Production"), + Config: testAccNutanixAccessControlPolicyConfigWithCategory(name, description, "Production", roleName), Check: resource.ComposeTestCheckFunc( testAccCheckNutanixAccessControlPolicyExists(), testAccCheckNutanixCategories(resourceAccessPolicy), @@ -100,7 +112,7 @@ func TestAccNutanixAccessControlPolicy_WithCategory(t *testing.T) { ), }, { - Config: testAccNutanixAccessControlPolicyConfigWithCategory(nameUpdated, descriptionUpdated, "Staging"), + Config: testAccNutanixAccessControlPolicyConfigWithCategory(nameUpdated, descriptionUpdated, "Staging", roleName), Check: resource.ComposeTestCheckFunc( testAccCheckNutanixAccessControlPolicyExists(), resource.TestCheckResourceAttr(resourceAccessPolicy, "categories.#", "1"), @@ -126,9 +138,6 @@ func testAccCheckNutanixAccessControlPolicyExists() resource.TestCheckFunc { return fmt.Errorf("not found: %s", resourceAccessPolicy) } - pretty, _ := json.MarshalIndent(rs, "", " ") - fmt.Print("\n\n[DEBUG] State of AccessControlPolicy", string(pretty)) - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } @@ -155,10 +164,10 @@ func testAccCheckNutanixAccessControlPolicyDestroy(s *terraform.State) error { return nil } -func testAccNutanixAccessControlPolicyConfig(name, description string) string { +func testAccNutanixAccessControlPolicyConfig(name, description, roleName string) string { return fmt.Sprintf(` resource "nutanix_role" "test" { - name = "test role" + name = "%[3]s" description = "description role" permission_reference_list { kind = "permission" @@ -173,13 +182,13 @@ resource "nutanix_access_control_policy" "test" { uuid = nutanix_role.test.id } } -`, name, description) +`, name, description, roleName) } -func testAccNutanixAccessControlPolicyConfigWithCategory(name, description, categoryValue string) string { +func testAccNutanixAccessControlPolicyConfigWithCategory(name, description, categoryValue, roleName string) string { return fmt.Sprintf(` resource "nutanix_role" "test" { - name = "test role" + name = "%[4]s" description = "description role" permission_reference_list { kind = "permission" @@ -198,13 +207,13 @@ resource "nutanix_access_control_policy" "test" { value = "%[3]s" } } -`, name, description, categoryValue) +`, name, description, categoryValue, roleName) } -func testAccNutanixAccessControlPolicyConfigWithUser(name, description string) string { +func testAccNutanixAccessControlPolicyConfigWithUser(name, description, roleName string) string { return fmt.Sprintf(` resource "nutanix_role" "test" { - name = "test role 2" + name = "%[3]s" description = "description role" permission_reference_list { kind = "permission" @@ -288,5 +297,5 @@ resource "nutanix_access_control_policy" "test" { } } } -`, name, description) +`, name, description, roleName) } diff --git a/nutanix/resource_nutanix_project.go b/nutanix/resource_nutanix_project.go index 7d1bc97e9..b7781c546 100644 --- a/nutanix/resource_nutanix_project.go +++ b/nutanix/resource_nutanix_project.go @@ -475,21 +475,21 @@ func resourceNutanixProjectUpdate(d *schema.ResourceData, meta interface{}) erro return err } + uuid := *resp.Metadata.UUID taskUUID := resp.Status.ExecutionContext.TaskUUID.(string) - // Wait for the Image to be available + // Wait for the Project to be available stateConf := &resource.StateChangeConf{ Pending: []string{"QUEUED", "RUNNING"}, Target: []string{"SUCCEEDED"}, Refresh: taskStateRefreshFunc(conn, taskUUID), - Timeout: subnetTimeout, - Delay: subnetDelay, - MinTimeout: subnetMinTimeout, + Timeout: vmTimeout, + Delay: vmDelay, + MinTimeout: vmMinTimeout, } - if _, err := stateConf.WaitForState(); err != nil { - d.SetId("") - return fmt.Errorf("error waiting for project (%s) to update: %s", d.Id(), err) + if _, errWaitTask := stateConf.WaitForState(); errWaitTask != nil { + return fmt.Errorf("error waiting for project(%s) to update: %s", uuid, errWaitTask) } return resourceNutanixProjectRead(d, meta) diff --git a/nutanix/resource_nutanix_role_test.go b/nutanix/resource_nutanix_role_test.go index c5eebca98..621fdffc7 100644 --- a/nutanix/resource_nutanix_role_test.go +++ b/nutanix/resource_nutanix_role_test.go @@ -1,7 +1,6 @@ package nutanix import ( - "encoding/json" "fmt" "strings" "testing" @@ -100,9 +99,6 @@ func testAccCheckNutanixRoleExists() resource.TestCheckFunc { return fmt.Errorf("not found: %s", resourceRole) } - pretty, _ := json.MarshalIndent(rs, "", " ") - fmt.Print("\n\n[DEBUG] State of Role", string(pretty)) - if rs.Primary.ID == "" { return fmt.Errorf("no ID is set") } diff --git a/nutanix/resource_nutanix_user_test.go b/nutanix/resource_nutanix_user_test.go index 8874e20bd..8cc06d5cf 100644 --- a/nutanix/resource_nutanix_user_test.go +++ b/nutanix/resource_nutanix_user_test.go @@ -13,7 +13,7 @@ const resourceNameUser = "nutanix_user.user" func TestAccNutanixUser_basic(t *testing.T) { principalName := "dou-user@ntnxlab.local" - directoryServiceUUID := "dd19a896-8e72-4158-b716-98455ceda220" + directoryServiceUUID := "542d7921-1385-4b6e-ab10-09f2ca4f054d" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, diff --git a/nutanix/resource_nutanix_virtual_machine_test.go b/nutanix/resource_nutanix_virtual_machine_test.go index 679fd3328..79f35c165 100644 --- a/nutanix/resource_nutanix_virtual_machine_test.go +++ b/nutanix/resource_nutanix_virtual_machine_test.go @@ -2,6 +2,7 @@ package nutanix import ( "fmt" + "os" "strings" "testing" "time" @@ -365,7 +366,7 @@ func TestAccNutanixVirtualMachine_cloningVM(t *testing.T) { func TestAccNutanixVirtualMachine_withDiskContainer(t *testing.T) { r := acctest.RandInt() resourceName := "nutanix_virtual_machine.vm-disk" - containerUIID := "de7413d7-2a86-4f9e-8e5a-bea4ce51b4e9" + containerUUID := os.Getenv("NUTANIX_STORAGE_CONTAINER") diskSize := 90 * 1024 * 1024 diskSizeUpdated := 90 * 1024 * 1024 * 1024 @@ -375,14 +376,14 @@ func TestAccNutanixVirtualMachine_withDiskContainer(t *testing.T) { CheckDestroy: testAccCheckNutanixVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccNutanixVMConfigWithDiskContainer(r, diskSize, containerUIID), + Config: testAccNutanixVMConfigWithDiskContainer(r, diskSize, containerUUID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "disk_list.#"), resource.TestCheckResourceAttr(resourceName, "disk_list.#", "1"), ), }, { - Config: testAccNutanixVMConfigWithDiskContainer(r, diskSizeUpdated, containerUIID), + Config: testAccNutanixVMConfigWithDiskContainer(r, diskSizeUpdated, containerUUID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(resourceName, "disk_list.#"), resource.TestCheckResourceAttr(resourceName, "disk_list.#", "1"),