Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.2.0 beta #243

Merged
merged 222 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
222 commits
Select commit Hold shift + click to select a range
46642af
feat: added functions for access control policies in client
Oct 28, 2020
28b52b7
feat: added resource and datasource(s) for access control policies
Oct 28, 2020
da7d8fc
fix: fixes linter make test
Oct 28, 2020
7aa598e
fix: fixes and refactorized to make it work it the testacc
Oct 30, 2020
95a88e6
added validatefunc for some parameters
Oct 30, 2020
437dac5
docs: added docs for access control policies
Oct 30, 2020
63769d9
refactor: refactorized and fixes linters
Nov 1, 2020
2a6a8e2
updated docs
Nov 1, 2020
5935cfe
changed filter_context_list to context_filter_list
Nov 3, 2020
4783c44
feat: renabled the projects resources and datasource(s)
Nov 3, 2020
25d1eb0
renamed files and hardcoded kind for project_reference
Nov 4, 2020
331a899
added return nil in read function
yannickstruyf3 Nov 5, 2020
eda63df
modified code to support project and ACP use case. Also make sure tha…
yannickstruyf3 Nov 5, 2020
341af13
removed api_version hardcoded
yannickstruyf3 Nov 5, 2020
a06c474
chore: updated vendor
Nov 6, 2020
5dc46c0
updated imports
Nov 6, 2020
904ad6c
refactorized some mistakes
Nov 10, 2020
acbb25b
made resource_domain optional -> quotas are also optional in projects
yannickstruyf3 Nov 17, 2020
2f3ea52
added max items to resource_domain
yannickstruyf3 Nov 17, 2020
a93c052
Merge pull request #183 from yannickstruyf3/bugfix/projects-optional-…
marinsalinas Nov 17, 2020
aa1806e
feat: added functions for access control policies in client
Oct 28, 2020
1b1c4ce
feat: added resource and datasource(s) for access control policies
Oct 28, 2020
859a027
fix: fixes linter make test
Oct 28, 2020
5dc4da4
fix: fixes and refactorized to make it work it the testacc
Oct 30, 2020
fc857ef
added validatefunc for some parameters
Oct 30, 2020
aeafde3
docs: added docs for access control policies
Oct 30, 2020
e1de2e9
refactor: refactorized and fixes linters
Nov 1, 2020
b3488fa
updated docs
Nov 1, 2020
5ead910
changed filter_context_list to context_filter_list
Nov 3, 2020
e0226b2
feat: renabled the projects resources and datasource(s)
Nov 3, 2020
0a14a51
renamed files and hardcoded kind for project_reference
Nov 4, 2020
0570d0d
added return nil in read function
yannickstruyf3 Nov 5, 2020
fae5cf3
modified code to support project and ACP use case. Also make sure tha…
yannickstruyf3 Nov 5, 2020
5db9c7d
removed api_version hardcoded
yannickstruyf3 Nov 5, 2020
eaed354
chore: updated vendor
Nov 6, 2020
961a3cf
updated imports
Nov 6, 2020
7982f48
refactorized some mistakes
Nov 10, 2020
392a410
made resource_domain optional -> quotas are also optional in projects
yannickstruyf3 Nov 17, 2020
5ddab05
added max items to resource_domain
yannickstruyf3 Nov 17, 2020
ee6ca52
Merge pull request #185 from nutanix/acp-update
marinsalinas Nov 17, 2020
c80218f
modified typeset casting for user_reference_list and user_group_refer…
yannickstruyf3 Nov 18, 2020
f86555c
Merge pull request #187 from yannickstruyf3/acp_update_typeset
marinsalinas Nov 18, 2020
370943b
fix wwrong assignment of userreferencelist
yannickstruyf3 Nov 19, 2020
19ba3e3
Merge pull request #189 from yannickstruyf3/bugfix/acp-update-user-re…
marinsalinas Nov 19, 2020
947506e
updated client for protection rules and recovery plans
Dec 3, 2020
22357e5
added files protection rules and recovery plan
Dec 3, 2020
2b38de0
git merge
Dec 3, 2020
19f3a46
feat: update network security rule structs
marinsalinas Dec 3, 2020
9028c8b
refactor: make rule code re-usable
marinsalinas Dec 3, 2020
be80ab2
chore: remove vendor dependencies
marinsalinas Dec 3, 2020
a6a8e50
Merge pull request #175 from nutanix/access-policies
marinsalinas Dec 3, 2020
b53b5ec
feat: added resource/datasource for roles
Nov 10, 2020
5957b0a
docs: added docs for role(s)
Nov 10, 2020
77d44f0
tests: modified test when you can pass roles id in access policies tests
Nov 10, 2020
bd09963
fixes linter
Nov 16, 2020
506bb5a
chore: update vendor dependencie
marinsalinas Nov 17, 2020
890ef45
feat: added role name in datasource roles
Nov 23, 2020
0a5b685
fixes linter
Dec 3, 2020
54b9776
Merge pull request #181 from nutanix/roles
marinsalinas Dec 3, 2020
9ee5a03
deleted dr runbook for rebase
Dec 3, 2020
972c87d
Merge branch 'v1.2.0-beta' into dr-runbook-2
Dec 3, 2020
196c1b4
chore: update vendor dependencie
marinsalinas Nov 17, 2020
8ed700b
feat: add User SDK requests
marinsalinas Nov 4, 2020
8f30e82
wip/feat: added schema and create function
marinsalinas Nov 4, 2020
f2d8ea6
wip/feat: added user read function
marinsalinas Nov 5, 2020
3499dc2
wip/feat: added user update and delete function
marinsalinas Nov 5, 2020
8794641
feat: add user data source
marinsalinas Nov 5, 2020
2986b97
fix: change directory_service_user and identity_provider_user casting…
marinsalinas Nov 9, 2020
3a8c17e
fix: change directory_service_user and identity_provider_user casting…
marinsalinas Nov 9, 2020
e54da77
fix: avoid sending object when is empty
marinsalinas Nov 9, 2020
6345392
chore: return nil when user si not found
marinsalinas Nov 9, 2020
ce9d911
modified logs and modified directory_service_reference to slice in re…
yannickstruyf3 Nov 9, 2020
9a64e31
feat: add user data source by name
marinsalinas Nov 9, 2020
cabf816
feat: add user list data source
marinsalinas Nov 10, 2020
f8036bd
test: add testing for user endpoints
marinsalinas Nov 10, 2020
53e3d3f
test: add basic acceptance test for user resource
marinsalinas Nov 10, 2020
8d4c819
fix: get correct value when expand identity provider user
marinsalinas Nov 13, 2020
5bf1a55
test: add user data source acceptance testing
marinsalinas Nov 13, 2020
297855c
chore: add user resource website documentation
marinsalinas Nov 17, 2020
b585d8e
chore: add user data source website documentation
marinsalinas Nov 17, 2020
cc41372
chore: add users data source website documentation
marinsalinas Nov 17, 2020
c8a4c58
test: add testing for user endpoints
marinsalinas Nov 10, 2020
b3bea91
test: add basic acceptance test for user resource
marinsalinas Nov 10, 2020
3533598
feat: make user_reference_list and expernal_user_group_reference_list…
marinsalinas Nov 19, 2020
b283dc0
test: add user with identity_provider test case
marinsalinas Nov 20, 2020
2d6174a
chore: update go.sum
marinsalinas Nov 23, 2020
97d28f4
refactor: change metadata function in roles ds
marinsalinas Nov 24, 2020
985a89b
changed if statement in ds role and modified the conflictswith
yannickstruyf3 Nov 24, 2020
d7478ee
chore: fix linting issues
marinsalinas Dec 1, 2020
37e9e7a
feat: add user group singular datasource
marinsalinas Dec 1, 2020
02c9b9d
changed print messages and added filter based on DN
yannickstruyf3 Dec 1, 2020
2f8f9d3
renamed ds attributes and prints
yannickstruyf3 Dec 1, 2020
5058d5c
fix: rewrite if statement on user_group data source to get the resource
marinsalinas Dec 1, 2020
d71217e
chore: fix misspelling on user data source website docs
marinsalinas Dec 1, 2020
c56fe66
fixed bug that occured when updating the permissions of a role
yannickstruyf3 Dec 1, 2020
78c9187
kind in permission_reference_list is now by default 'permission'
yannickstruyf3 Dec 1, 2020
cc9b315
test: add acc test for user group data source
marinsalinas Dec 1, 2020
e5acd60
website: add user group data source website documentation
marinsalinas Dec 2, 2020
d7391f8
feat: add user groups datasource
marinsalinas Dec 2, 2020
1da0e7b
website: add user groups data source website documentation
marinsalinas Dec 2, 2020
6241b0d
chore: update vendor dependencies
marinsalinas Dec 3, 2020
1f34b86
chore: fix linting issues
marinsalinas Dec 3, 2020
50f43f9
Merge pull request #179 from nutanix/feat/users-rs-ds
marinsalinas Dec 3, 2020
7d8f17b
changed typemap to typelist
Dec 4, 2020
c239b04
added permissions for roles
yannickstruyf3 Dec 4, 2020
72f395c
chore: added testify for validate diff
Dec 4, 2020
600d828
test: added other validation diff and fixes the diff because of type …
Dec 4, 2020
ae558f9
fixes linter
Dec 4, 2020
d065440
fixes linter
Dec 4, 2020
3d83d07
feat: add ad_rule argument support
marinsalinas Dec 4, 2020
b532ed0
chore: remove unessesary trailing line
marinsalinas Dec 4, 2020
9f7aad6
feat: add bios_type support to VM resource and datasource
marinsalinas Dec 4, 2020
8686891
refactor: refactorized to make it compatible
Dec 4, 2020
32d49ce
fixes linter error
Dec 4, 2020
711c2ca
added other parameters of doc for network mapping in schema
Dec 7, 2020
aacd551
docs: added docs for resource and datasource(s) of protection rule an…
Dec 7, 2020
49659ce
added other parameters of doc for network mapping in schema
Dec 7, 2020
9823350
feat: add ad_rule to security network rule data source
marinsalinas Dec 9, 2020
f5707a3
feat: add missing attributes to network_security_rule resource and da…
marinsalinas Dec 9, 2020
d8fdf8a
refactor
Dec 10, 2020
d2bd539
test: add test case for vdi fule
marinsalinas Dec 10, 2020
fa1f9ab
added by name test for permission data source
yannickstruyf3 Dec 11, 2020
57e44df
Merge pull request #219 from yannickstruyf3/feat/data_source_permission
marinsalinas Dec 11, 2020
2ae0bd7
deleted to make it easy for git merge
Dec 16, 2020
90e17b3
merged
Dec 16, 2020
affa47d
feat: added filterbyname for protection rules and recovery plans
Dec 16, 2020
9f21497
make fmt
Dec 16, 2020
bcdb38f
fixes linter
Dec 16, 2020
a9baf11
fix: added instatiates to avoid nil exception error
Dec 17, 2020
b7135e3
fix: added validation for any entity reference
Dec 17, 2020
00ca1ca
change schema for categories entity info list and added testacc for t…
Dec 18, 2020
0627647
deleted printing logs
Dec 18, 2020
e483f18
fix: changed to only optional for any reference of entity info list
Dec 22, 2020
e44050d
test: updated testacc so it can repeat same steps to see if it works …
Dec 22, 2020
7e0ee7a
fixes linter code
Dec 22, 2020
76d71b8
fix: parse string to int for boot_device_disk_address.device_index pa…
marinsalinas Jan 5, 2021
3a6f836
feat: add value validation for boot_type
marinsalinas Jan 5, 2021
85b8f98
feat: add machine_type argument to vm
marinsalinas Jan 6, 2021
ca54157
feat: add vm boot_type force new since there is no option to update
marinsalinas Jan 6, 2021
2105455
added machine_type to data source
yannickstruyf3 Jan 6, 2021
7ee4c99
Merge pull request #226 from yannickstruyf3/bugfix/machine_type_for_s…
marinsalinas Jan 6, 2021
7affe8e
chore: add machine type to documentation
marinsalinas Jan 11, 2021
a116f08
chore: add vdi related attributes to network_security rule wensite doc
marinsalinas Jan 11, 2021
8daa93a
Merge pull request #217 from nutanix/feat/add-bios-type-to-vm
marinsalinas Jan 11, 2021
c34fd85
documentation review
yannickstruyf3 Jan 12, 2021
0cc1073
added machine_type to virtual machine resource doc
yannickstruyf3 Jan 12, 2021
91a8592
removed project_ref
yannickstruyf3 Jan 15, 2021
5551107
adding a VM to a project does not require a reboot
yannickstruyf3 Jan 16, 2021
ced5ac8
Merge pull request #232 from yannickstruyf3/bugfix-project-vm-reboot
marinsalinas Jan 19, 2021
04b10e6
refactor: added delete response for projects
Jan 19, 2021
45310a1
feat: added task completion for update and delete projects
Jan 19, 2021
7e8643a
test: fixes test linter
Jan 19, 2021
148337a
fixes test linter
Jan 19, 2021
a48168f
fixes test linter
Jan 19, 2021
54ac3cf
feat: added parameter to search by name in datasource of acp
Jan 20, 2021
70d87c0
test: added test for search by name using datasource of acp
Jan 20, 2021
991b2b6
feat: added parameter to search by name in project
Jan 21, 2021
5fd496f
test: added test for search by name using datasource of project
Jan 21, 2021
5110187
fixes linter code
Jan 21, 2021
aaf1d59
docs: added missing info for docs of resource and datasource(s) of pr…
Jan 21, 2021
a859ba3
alpha version of Karbon implementation
yannickstruyf3 Dec 7, 2020
848fa57
Applied linting recommendations
yannickstruyf3 Oct 6, 2020
dc1cb90
added default values for CNI config
yannickstruyf3 Oct 7, 2020
357d189
added additional validation
yannickstruyf3 Oct 7, 2020
7a801a8
changed cni config to typelist
yannickstruyf3 Oct 7, 2020
e1abe6a
added constants
yannickstruyf3 Oct 7, 2020
72f5282
modified for linting
yannickstruyf3 Oct 7, 2020
08ec1f0
changed typeset to typelist for cni config and modified check existan…
yannickstruyf3 Oct 9, 2020
f1f4c3b
removed unchecked d.get() and reviewed todo comments
yannickstruyf3 Oct 14, 2020
fb9251a
modified code for Karbon 2.1.2
yannickstruyf3 Oct 26, 2020
2415186
added forcenew for CNI config
yannickstruyf3 Nov 13, 2020
11d2215
added scaling capabilities
yannickstruyf3 Dec 2, 2020
ca8f30e
added read for cni_config
yannickstruyf3 Dec 3, 2020
b63b6bb
rebased v1.2.0-beta
yannickstruyf3 Dec 7, 2020
32d24e0
removed print statement
yannickstruyf3 Dec 9, 2020
5565ec1
wip: karbon acc test
marinsalinas Dec 10, 2020
f33fe4e
test: add karbon acceptance test cases
marinsalinas Dec 15, 2020
da26cd8
chore: remove log
marinsalinas Dec 15, 2020
09117ea
refactor: test use for intead if to get the cluster id
marinsalinas Dec 15, 2020
a868194
test: add scaledown karbon cluster test case
marinsalinas Dec 16, 2020
e3c588b
test: add updateCNI test case for karbon resource
marinsalinas Dec 16, 2020
84631bf
chore: fix test
marinsalinas Dec 17, 2020
7a8c58f
docs: added docs for resource and datasource(s) of cluster and privat…
Dec 11, 2020
b33022d
docs: made changes suggested by yannick and gaby
Dec 21, 2020
704f77b
Merge pull request #228 from nutanix/karbon-base
marinsalinas Jan 21, 2021
894a6dd
Merge pull request #220 from nutanix/feat/ad_rule_support
marinsalinas Jan 21, 2021
f85330f
fix: changed schema and type of struct for categories of right hand side
Jan 21, 2021
63ac2a2
fixed bug where datasource project search by name was empty
yannickstruyf3 Jan 22, 2021
b8d56a6
Merge pull request #240 from yannickstruyf3/bugfix/datasource-project…
marinsalinas Jan 22, 2021
8406709
Merge pull request #231 from yannickstruyf3/bugfix/acp-project-reference
marinsalinas Jan 22, 2021
927d91f
Merge pull request #234 from nutanix/task-completion-project
marinsalinas Jan 22, 2021
356f376
Merge pull request #229 from yannickstruyf3/bugfix/v1.2.0-beta-doc-re…
marinsalinas Jan 22, 2021
f0d5d38
Merge pull request #238 from nutanix/docs-projects
marinsalinas Jan 22, 2021
9bcc3da
Merge pull request #236 from nutanix/datasource-acp
marinsalinas Jan 22, 2021
03afcbc
Merge pull request #237 from nutanix/datasource-project
marinsalinas Jan 22, 2021
623113c
git merge
Jan 22, 2021
afb0809
test: complete testacc for protection rules and recovery plan with ne…
Jan 22, 2021
911c4b6
Merge pull request #216 from nutanix/dr-runbook-2
marinsalinas Jan 22, 2021
9273c14
test: fix all test to work with the current prism version
marinsalinas Jan 26, 2021
114caf3
test: changed data for variables of azurl for protection rules
Jan 27, 2021
e7a5190
chore: fix tests
marinsalinas Jan 27, 2021
dc786e9
chore: fix code lint issues
marinsalinas Jan 27, 2021
810c751
Merge pull request #241 from nutanix/v1.2.0-beta-fix-testacc
marinsalinas Jan 27, 2021
2799b2b
Merge pull request #242 from nutanix/fix-protection-rule-test
marinsalinas Jan 27, 2021
db06ee4
changed ide.3 behaviour
yannickstruyf3 Jan 7, 2021
2557f15
added check for guest customization
yannickstruyf3 Jan 7, 2021
fcda703
added additional error handling
yannickstruyf3 Jan 7, 2021
c6d78fb
fixed bug where cloud_init_cdrom_uuid was not set
yannickstruyf3 Jan 8, 2021
026de85
removed additional ide.3 reference
yannickstruyf3 Jan 8, 2021
0ca6f11
fix linting
yannickstruyf3 Jan 8, 2021
ffdd426
removed set of cloud_init_cdrom_uuid during create
yannickstruyf3 Jan 15, 2021
42128dd
fix import failures
yannickstruyf3 Jan 19, 2021
8daa6bd
Revert "fix import failures"
yannickstruyf3 Jan 19, 2021
e55fe7b
removed logs
yannickstruyf3 Jan 20, 2021
2c306e4
remove newline
yannickstruyf3 Jan 22, 2021
768ffd4
used getOk for cloud_init_cdrom_uuid
yannickstruyf3 Jan 22, 2021
2fb9add
fix linting
yannickstruyf3 Jan 22, 2021
79b8b5b
Merge pull request #227 from yannickstruyf3/bugfix/remove-ide3-depend…
marinsalinas Jan 27, 2021
601de16
chore: fix vm test
marinsalinas Jan 21, 2021
9a91cc0
Merge pull request #239 from nutanix/bugfix/remove-ide3-dependency-tests
marinsalinas Jan 27, 2021
4853eb9
persist uuid after creation
yannickstruyf3 Jan 29, 2021
c7356de
Merge pull request #244 from yannickstruyf3/bugfix/karbon-recover-fai…
marinsalinas Feb 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Service interface {
CreateProject(request *Project) (*Project, error)
GetProject(projectUUID string) (*Project, error)
ListProject(getEntitiesRequest *DSMetadata) (*ProjectListResponse, error)
ListAllProject() (*ProjectListResponse, error)
ListAllProject(filter string) (*ProjectListResponse, error)
UpdateProject(uuid string, body *Project) (*Project, error)
DeleteProject(uuid string) (*DeleteResponse, error)
CreateAccessControlPolicy(request *AccessControlPolicy) (*AccessControlPolicy, error)
Expand Down Expand Up @@ -1243,10 +1243,11 @@ func (op Operations) ListProject(getEntitiesRequest *DSMetadata) (*ProjectListRe
* Note: Entities that have not been created successfully are not listed.
* @return *ProjectListResponse
*/
func (op Operations) ListAllProject() (*ProjectListResponse, error) {
func (op Operations) ListAllProject(filter string) (*ProjectListResponse, error) {
entities := make([]*Project, 0)

resp, err := op.ListProject(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("project"),
Length: utils.Int64Ptr(itemsPerPage),
})
Expand All @@ -1261,6 +1262,7 @@ func (op Operations) ListAllProject() (*ProjectListResponse, error) {
if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListProject(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("project"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
Expand Down
60 changes: 55 additions & 5 deletions nutanix/data_source_nutanix_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package nutanix
import (
"fmt"

v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
"github.com/terraform-providers/terraform-provider-nutanix/utils"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand All @@ -11,8 +14,14 @@ func dataSourceNutanixProject() *schema.Resource {
Read: dataSourceNutanixProjectRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"project_name"},
},
"project_name": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"project_id"},
},
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -285,9 +294,23 @@ func dataSourceNutanixProject() *schema.Resource {
func dataSourceNutanixProjectRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*Client).API

projectID := d.Get("project_id").(string)
id, iok := d.GetOk("project_id")
name, nOk := d.GetOk("project_name")

if !iok && !nOk {
return fmt.Errorf("please provide `project_id` or `project_name`")
}

var err error
var project *v3.Project

if iok {
project, err = conn.V3.GetProject(id.(string))
}
if nOk {
project, err = findProjectByName(conn, name.(string))
}

project, err := conn.V3.GetProject(projectID)
if err != nil {
return err
}
Expand Down Expand Up @@ -347,7 +370,34 @@ func dataSourceNutanixProjectRead(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("error setting `api_version` for Project(%s): %s", d.Id(), err)
}

d.SetId(projectID)
d.SetId(utils.StringValue(project.Metadata.UUID))

return nil
}

func findProjectByName(conn *v3.Client, name string) (*v3.Project, error) {
filter := fmt.Sprintf("name==%s", name)
resp, err := conn.V3.ListAllProject(filter)
if err != nil {
return nil, err
}

entities := resp.Entities

found := make([]*v3.Project, 0)
for _, v := range entities {
if v.Spec.Name == name {
found = append(found, v)
}
}

if len(found) > 1 {
return nil, fmt.Errorf("your query returned more than one result. Please use project_id argument instead")
}

if len(found) == 0 {
return nil, fmt.Errorf("project with the given name, not found")
}

return found[0], nil
}
128 changes: 124 additions & 4 deletions nutanix/data_source_nutanix_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cast"
)

func TestAccNutanixProjectDataSource_basic(t *testing.T) {
func TestAccNutanixProjectDataSourceByID_basic(t *testing.T) {
resourceName := "nutanix_project.project_test"

subnetName := acctest.RandomWithPrefix("test-subnateName")
Expand All @@ -33,7 +33,7 @@ func TestAccNutanixProjectDataSource_basic(t *testing.T) {
CheckDestroy: testAccCheckNutanixProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccProjectDataSourceConfig(subnetName, name, description, categoryName, categoryVal, limit, rsType),
Config: testAccProjectDataSourceByIDConfig(subnetName, name, description, categoryName, categoryVal, limit, rsType),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProjectExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
Expand All @@ -47,7 +47,7 @@ func TestAccNutanixProjectDataSource_basic(t *testing.T) {
),
},
{
Config: testAccProjectDataSourceConfig(
Config: testAccProjectDataSourceByIDConfig(
subnetName, updateName, updateDescription, updateCategoryName, updateCategoryVal, updateLimit, updateRSType),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProjectExists(&resourceName),
Expand All @@ -65,7 +65,63 @@ func TestAccNutanixProjectDataSource_basic(t *testing.T) {
})
}

func testAccProjectDataSourceConfig(subnetName, name, description, categoryName, categoryVal, limit, rsType string) string {
func TestAccNutanixProjectDataSourceByName_basic(t *testing.T) {
resourceName := "nutanix_project.project_test"

subnetName := acctest.RandomWithPrefix("test-subnateName")
name := acctest.RandomWithPrefix("test-project-name-dou")
description := acctest.RandomWithPrefix("test-project-desc-dou")
categoryName := "Environment"
categoryVal := "Staging"
limit := cast.ToString(acctest.RandIntRange(2, 4))
rsType := "STORAGE"

updateName := acctest.RandomWithPrefix("test-project-name-dou")
updateDescription := acctest.RandomWithPrefix("test-project-desc-dou")
updateCategoryName := "Environment"
updateCategoryVal := "Production"
updateLimit := cast.ToString(acctest.RandIntRange(4, 8))
updateRSType := "MEMORY"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixProjectDestroy,
Steps: []resource.TestStep{
{
Config: testAccProjectDataSourceByNameConfig(subnetName, name, description, categoryName, categoryVal, limit, rsType),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProjectExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestCheckResourceAttr(resourceName, "resource_domain.#", "1"),
resource.TestCheckResourceAttr(resourceName, "resource_domain.0.resources.#", "1"),
resource.TestCheckResourceAttr(resourceName, "resource_domain.0.resources.0.limit", limit),
resource.TestCheckResourceAttr(resourceName, "resource_domain.0.resources.0.resource_type", rsType),
resource.TestCheckResourceAttr(resourceName, "categories.#", "1"),
resource.TestCheckResourceAttr(resourceName, "api_version", "3.1"),
),
},
{
Config: testAccProjectDataSourceByNameConfig(
subnetName, updateName, updateDescription, updateCategoryName, updateCategoryVal, updateLimit, updateRSType),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixProjectExists(&resourceName),
resource.TestCheckResourceAttr(resourceName, "name", updateName),
resource.TestCheckResourceAttr(resourceName, "description", updateDescription),
resource.TestCheckResourceAttr(resourceName, "resource_domain.#", "1"),
resource.TestCheckResourceAttr(resourceName, "resource_domain.0.resources.#", "1"),
resource.TestCheckResourceAttr(resourceName, "resource_domain.0.resources.0.limit", updateLimit),
resource.TestCheckResourceAttr(resourceName, "resource_domain.0.resources.0.resource_type", updateRSType),
resource.TestCheckResourceAttr(resourceName, "categories.#", "1"),
resource.TestCheckResourceAttr(resourceName, "api_version", "3.1"),
),
},
},
})
}

func testAccProjectDataSourceByIDConfig(subnetName, name, description, categoryName, categoryVal, limit, rsType string) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}

Expand Down Expand Up @@ -128,3 +184,67 @@ func testAccProjectDataSourceConfig(subnetName, name, description, categoryName,
}
`, subnetName, name, description, categoryName, categoryVal, limit, rsType)
}

func testAccProjectDataSourceByNameConfig(subnetName, name, description, categoryName, categoryVal, limit, rsType string) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}

locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

resource "nutanix_subnet" "subnet" {
cluster_uuid = local.cluster1
name = "%s"
description = "Description of my unit test VLAN"
vlan_id = 31
subnet_type = "VLAN"
subnet_ip = "10.250.140.0"
default_gateway_ip = "10.250.140.1"
prefix_length = 24

dhcp_options = {
boot_file_name = "bootfile"
domain_name = "nutanix"
tftp_server_name = "10.250.140.200"
}

dhcp_domain_name_server_list = ["8.8.8.8", "4.2.2.2"]
dhcp_domain_search_list = ["terraform.nutanix.com", "terraform.unit.test.com"]
}

resource "nutanix_project" "project_test" {
name = "%s"
description = "%s"

categories {
name = "%s"
value = "%s"
}

resource_domain {
resources {
limit = %s
resource_type = "%s"
}
}

default_subnet_reference {
uuid = nutanix_subnet.subnet.metadata.uuid
}

subnet_reference_list {
uuid = nutanix_subnet.subnet.metadata.uuid
}

api_version = "3.1"
}

data "nutanix_project" "test" {
project_name = nutanix_project.project_test.name
}
`, subnetName, name, description, categoryName, categoryVal, limit, rsType)
}
8 changes: 7 additions & 1 deletion nutanix/data_source_nutanix_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,14 @@ func dataSourceNutanixProjects() *schema.Resource {
func dataSourceNutanixProjectsRead(d *schema.ResourceData, meta interface{}) error {
// Get client connection
conn := meta.(*Client).API
req := &v3.DSMetadata{}

resp, err := conn.V3.ListAllProject()
metadata, filtersOk := d.GetOk("metadata")
if filtersOk {
req = buildDataSourceListMetadata(metadata.(*schema.Set))
}

resp, err := conn.V3.ListProject(req)
if err != nil {
return err
}
Expand Down