Skip to content

Commit

Permalink
Merge branch 'v4-temp-design-2.0-structure' into feat/2.1/deploy-pc
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroon-Dweikat-Ntx committed Dec 11, 2024
2 parents fb00f22 + e9bd475 commit 0a0e5f5
Show file tree
Hide file tree
Showing 58 changed files with 180 additions and 138 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/acceptance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:
elif [ "$provider" = "v4" ]
then
runFlag+="TestAccV2Nutanix*"
elif [ "$provider" = "prism" ]
then
runFlag+="TestAccV2NutanixCategories*"
elif [ "$provider" = "era" ]
then
runFlag+="TestAccEra*"
Expand Down
6 changes: 4 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ test: fmtcheck
go test --tags=unit $(TEST) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 500m -coverprofile c.out -covermode=count

@echo "==> Running testcases..."
@echo "TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 500m -coverprofile c.out -covermode=count"
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 500m -coverprofile c.out -covermode=count

fmt:
@echo "==> Fixing source code with gofmt..."
goimports -w ./$(PKG_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
const resourceNameDiscoverUnconfiguredNodes = "nutanix_clusters_discover_unconfigured_nodes_v2.test"

func TestAccV2NutanixClusterDiscoverUnconfiguredNodesResource_basic(t *testing.T) {
if testVars.Clusters.Nodes[0].CvmIP == "" {
t.Skip("Skipping test as No available node to be used for testing")
}
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const (
)

func TestAccV2NutanixClusterAddNodeResource_Basic(t *testing.T) {
if testVars.Clusters.Nodes[1].CvmIP == "" &&
testVars.Clusters.Nodes[2].CvmIP == "" &&
testVars.Clusters.Nodes[3].CvmIP == "" {
t.Skip("Skipping test as No available nodes to be used for testing")
}
r := acctest.RandInt()
clusterName := fmt.Sprintf("tf-3node-cluster-%d", r)

Expand Down Expand Up @@ -153,7 +158,7 @@ resource "nutanix_cluster_v2" "cluster-3nodes" {
}
provisioner "local-exec" {
command = " sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[1].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[1].username} password=${local.clusters.nodes[1].password}' "
command = "ssh-keygen -f "~/.ssh/known_hosts" -R "${local.clusters.nodes[0].cvm_ip}"; sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[1].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[1].username} password=${local.clusters.nodes[1].password}' "
on_failure = continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const (
)

func TestAccV2NutanixClusterResource_CreateClusterWithMinimumConfig(t *testing.T) {
if testVars.Clusters.Nodes[0].CvmIP == "" {
t.Skip("Skipping test as No available node to be used for testing")
}
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-cluster-%d", r)

Expand Down Expand Up @@ -49,6 +52,9 @@ func TestAccV2NutanixClusterResource_CreateClusterWithMinimumConfig(t *testing.T
}

func TestAccV2NutanixClusterResource_CreateClusterWithAllConfig(t *testing.T) {
if testVars.Clusters.Nodes[0].CvmIP == "" {
t.Skip("Skipping test as No available node to be used for testing")
}
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-cluster-%d", r)

Expand Down Expand Up @@ -180,7 +186,7 @@ func testAccClusterResourceMinimumConfig(name string) string {
}
provisioner "local-exec" {
command = " sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[0].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[0].username} password=${local.clusters.nodes[0].password}' "
command = "ssh-keygen -f "~/.ssh/known_hosts" -R "${local.clusters.nodes[0].cvm_ip}"; sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[0].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[0].username} password=${local.clusters.nodes[0].password}' "
on_failure = continue
}
Expand Down Expand Up @@ -295,7 +301,7 @@ func testAccClusterResourceAllConfig(name string) string {
}
provisioner "local-exec" {
command = " sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[0].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[0].username} password=${local.clusters.nodes[0].password}' "
command = "ssh-keygen -f "~/.ssh/known_hosts" -R "${local.clusters.nodes[0].cvm_ip}"; sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[0].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[0].username} password=${local.clusters.nodes[0].password}' "
on_failure = continue
}
Expand Down Expand Up @@ -425,7 +431,8 @@ func testAccClusterResourceUpdateConfig(updatedName string) string {
}
provisioner "local-exec" {
command = " sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[0].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[0].username} password=${local.clusters.nodes[0].password}' "
command = "ssh-keygen -f "~/.ssh/known_hosts" -R "${local.clusters.nodes[0].cvm_ip}"; ssh-keygen -f "/home/haroon/.ssh/known_hosts" -R "${local.clusters.nodes[0].cvm_ip}" ; sshpass -p '${local.clusters.pe_password}' ssh -o StrictHostKeyChecking=no ${local.clusters.pe_username}@${local.clusters.nodes[0].cvm_ip} '/home/nutanix/prism/cli/ncli user reset-password user-name=${local.clusters.nodes[0].username} password=${local.clusters.nodes[0].password}' "
on_failure = continue
}
Expand Down
26 changes: 26 additions & 0 deletions nutanix/services/iamv2/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package iamv2_test
import (
"fmt"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
acc "github.com/terraform-providers/terraform-provider-nutanix/nutanix/acctest"
)

func checkAttributeLength(resourceName, attribute string, minLength int) resource.TestCheckFunc {
Expand Down Expand Up @@ -33,3 +36,26 @@ func checkAttributeLength(resourceName, attribute string, minLength int) resourc
return nil
}
}

func testAccCheckNutanixUserDestroy(s *terraform.State) error {
fmt.Println("Checking user destroy")
conn := acc.TestAccProvider.Meta().(*conns.Client)

for _, rs := range s.RootModule().Resources {
if rs.Type != "nutanix_users_v2" {
continue
}
if _, err := conn.API.V3.GetUser(rs.Primary.ID); err != nil {
if strings.Contains(fmt.Sprint(err), "ENTITY_NOT_FOUND") {
return nil
}
return err
}
_, err := conn.API.V3.DeleteUser("4f1d9cf6-83dc-5fe2-8dd1-a84e062aaeee")
if err != nil {
return err
}
fmt.Println("Deleted user")
}
return nil
}
2 changes: 2 additions & 0 deletions nutanix/services/iamv2/resource_nutanix_users_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func TestAccV2NutanixUsersResource_LDAPUser(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccFoundationPreCheck(t) },
Providers: acc.TestAccProviders,
// using V3 API to delete user
CheckDestroy: testAccCheckNutanixUserDestroy,
Steps: []resource.TestStep{
{
Config: testLDAPUserWithMinimalConfigResourceConfig(filepath),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameaddgrp = "data.nutanix_address_group_v2.test"

func TestAccNutanixAddressGroupV2DataSource_basic(t *testing.T) {
func TestAccV2NutanixAddressGroupDataSource_basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("test-service-%d", r)
desc := "test service description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameAddGroups = "data.nutanix_address_groups_v2.test"

func TestAccNutanixAddressGroupsV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixAddressGroupsDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("test-service-%d", r)
desc := "test service description"
Expand All @@ -30,7 +30,7 @@ func TestAccNutanixAddressGroupsV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixAddressGroupsV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixAddressGroupsDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("test-service-%d", r)
desc := "test service description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameFIP = "data.nutanix_floating_ip_v2.test"

func TestAccNutanixFloatingIPV2DataSource_basic(t *testing.T) {
func TestAccV2NutanixFloatingIPDataSource_basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-fip-%d", r)
desc := "test fip description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameFIPps = "data.nutanix_floating_ips_v2.test"

func TestAccNutanixFloatingIPsV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixFloatingIPsDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-fip-%d", r)
desc := "test fip description"
Expand All @@ -30,7 +30,7 @@ func TestAccNutanixFloatingIPsV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixFloatingIPsV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixFloatingIPsDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-fip-%d", r)
desc := "test fip description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameNSPS = "data.nutanix_network_security_policies_v2.test"

func TestAccNutanixNSPsV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixNSPsDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-nsp-%d", r)

Expand All @@ -30,7 +30,7 @@ func TestAccNutanixNSPsV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixNSPsV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixNSPsDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-nsp-%d", r)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameNsp = "data.nutanix_network_security_policy_v2.test"

func TestAccNutanixNSPV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixNSPDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-nsp-%d", r)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNamePbr = "data.nutanix_pbr_v2.test"

func TestAccNutanixPbrV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixPbrDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-fip-%d", r)
desc := "test fip description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNamePbrs = "data.nutanix_pbrs_v2.test"

func TestAccNutanixPbrsV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixPbrsDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-fip-%d", r)
desc := "test fip description"
Expand All @@ -30,7 +30,7 @@ func TestAccNutanixPbrsV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixPbrsV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixPbrsDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-fip-%d", r)
desc := "test fip description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const datasourceNameRouteTable = "data.nutanix_route_table_v2.test"

func TestAccNutanixRouteTableV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixRouteTableDataSource_Basic(t *testing.T) {
r := acctest.RandInt()

//goland:noinspection ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const datasourceNameRouteTables = "data.nutanix_route_tables_v2.test"

func TestAccNutanixRouteTablesV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixRouteTablesDataSource_Basic(t *testing.T) {
r := acctest.RandInt()

resource.Test(t, resource.TestCase{
Expand All @@ -28,7 +28,7 @@ func TestAccNutanixRouteTablesV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixRouteTablesV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixRouteTablesDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()

resource.Test(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameRoute = "data.nutanix_route_v2.test"

func TestAccNutanixRouteV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixRouteDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-route-%d", r)
desc := "test terraform route description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameRoutes = "data.nutanix_routes_v2.test"

func TestAccNutanixRoutesV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixRoutesDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-route-%d", r)
desc := "test terraform route description"
Expand All @@ -31,7 +31,7 @@ func TestAccNutanixRoutesV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixRoutesV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixRoutesDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-route-%d", r)
desc := "test terraform route description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameServiceGroup = "data.nutanix_service_group_v2.test"

func TestAccNutanixServiceGroupV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixServiceGroupDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-service-%d", r)
desc := "test service description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameServiceGroups = "data.nutanix_service_groups_v2.test"

func TestAccNutanixServiceGroupsV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixServiceGroupsDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-service-%d", r)
desc := "test service description"
Expand All @@ -30,7 +30,7 @@ func TestAccNutanixServiceGroupsV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixServiceGroupsV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixServiceGroupsDataSource_WithFilter(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("tf-test-service-%d", r)
desc := "test service description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const datasourceNameSubnet = "data.nutanix_subnet_v2.test"

func TestAccNutanixSubnetV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixSubnetDataSource_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

const datasourceNameSubnets = "data.nutanix_subnets_v2.test"

func TestAccNutanixSubnetsV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixSubnetsDataSource_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Expand All @@ -25,7 +25,7 @@ func TestAccNutanixSubnetsV2DataSource_Basic(t *testing.T) {
})
}

func TestAccNutanixSubnetsV2DataSource_WithFilter(t *testing.T) {
func TestAccV2NutanixSubnetsDataSource_WithFilter(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

const datasourceNameVPC = "data.nutanix_vpc_v2.test"

func TestAccNutanixVpcV2DataSource_Basic(t *testing.T) {
func TestAccV2NutanixVpcDataSource_Basic(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("test-vpc-%d", r)
desc := "test vpc description"
Expand Down
Loading

0 comments on commit 0a0e5f5

Please sign in to comment.