-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/v4 categories on v4-temp-design (#21)
* Feat/1.9.3 (#633) Co-authored-by: Abhishekism9450 <[email protected]> Co-authored-by: Deepak Muley <[email protected]> Co-authored-by: Abhishek <[email protected]> * Feat/1.9.4 (#645) Co-authored-by: Frederic M <[email protected]> Co-authored-by: ArtemProt <[email protected]> Co-authored-by: Abhishekism9450 <[email protected]> * new tf design * import changes * package name change for fc * package name for fc is foundationCentral * package name to foundationcentral * fixes around acctest * examples folder * v4 design * some fixes after merging * datasource for subnets,vpcs, fips * datasource for pbrs * lint fixes. go error (gomnd, gosimple, golint) * go checks, magic numbers(gomnd) * fix config testcase as base client will differ in sdks * datasourc for route tables * resource for static route * resource for subnets * adding go mod for public repo * lint fixes * lint fix * lint fix for client name * test config as client will be different for sdks * adding crud for fips * address groups v4 * service groups * resource for service groups * crud for service groups * CRUD for address groups * data source for network security * CRUD for network security * microseg sdk pointing to internals * datasource for directory services * CRUD for directory service * datasource for saml * CRUD for idp * CRUD auth policy * delete Operation for directory service * CRUD for user groups * datasource for categories * Crud and tcs for categories * tcs for category * test for subnet * docs for subnet * tcs for fips * lint fixes * lint fix in fips * lint fix * docs for fip * docs and tcs for vpc * tests and docs for pbrs * docs for route table * docs for static route * lint fixes * testcases for address groups * fixing lint issues * lint fix * docs for address groups * test and docs for service groups * fix CRUD and info for auth policies, there is a bug in CRUD , and info . identities.reserved and entities.reserved treated as JSONString * fix bug on update auth policy * acc test for authorization policy * authorization policy v4 docs * docs and tcs for NSP * resource tests for NSP * tcs for NSP * fixing go mod for external sdks * fixing lint issues * fixing go lint issues * test and docs for categories * dummy values in test_config * remove all other modules * rename module from v4 to v2 * add examples * rename package from prism to prismv2 * rename package from prism to prismv2 --------- Co-authored-by: Abhishek Chaudhary <[email protected]> Co-authored-by: Abhishekism9450 <[email protected]> Co-authored-by: Deepak Muley <[email protected]> Co-authored-by: Abhishek <[email protected]> Co-authored-by: Frederic M <[email protected]> Co-authored-by: ArtemProt <[email protected]>
- Loading branch information
1 parent
9e9725c
commit c13c005
Showing
16 changed files
with
1,258 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
terraform{ | ||
required_providers { | ||
nutanix = { | ||
source = "nutanix/nutanix" | ||
version = "1.3.0" | ||
} | ||
} | ||
} | ||
|
||
#definig nutanix configuration | ||
provider "nutanix"{ | ||
username = var.nutanix_username | ||
password = var.nutanix_password | ||
endpoint = var.nutanix_endpoint | ||
port = 9440 | ||
insecure = true | ||
} | ||
|
||
|
||
|
||
#creating category | ||
resource "nutanix_category_v2" "example" { | ||
key = "category_example_key" | ||
value = "category_example_value" | ||
description = "category example description" | ||
} | ||
|
||
|
||
#pull all categories data | ||
data "nutanix_categories_v2" "clusters"{} | ||
|
||
|
||
# get category by ext id | ||
data "nutanix_category_v2" "example" { | ||
ext_id = resource.nutanix_category_v2.example.ext_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#define values to the variables to be used in terraform file | ||
nutanix_username = "admin" | ||
nutanix_password = "password" | ||
nutanix_endpoint = "10.xx.xx.xx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#define the type of variables to be used in terraform file | ||
variable "nutanix_username" { | ||
type = string | ||
} | ||
variable "nutanix_password" { | ||
type = string | ||
} | ||
variable "nutanix_endpoint" { | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
225 changes: 225 additions & 0 deletions
225
nutanix/services/v2/prismv2/data_source_nutanix_categories_v2.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
package prismv2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
import1 "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/models/prism/v4/config" | ||
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix" | ||
"github.com/terraform-providers/terraform-provider-nutanix/utils" | ||
) | ||
|
||
func DatasourceNutanixCategoriesV2() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: DatasourceNutanixCategoriesV2Read, | ||
Schema: map[string]*schema.Schema{ | ||
"page": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
"limit": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
"filter": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"order_by": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"expand": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"select": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"categories": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"ext_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"owner_uuid": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"associations": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"category_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"resource_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"resource_group": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"count": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"detailed_associations": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"category_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"resource_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"resource_group": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"resource_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"tenant_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"links": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"rel": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"href": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func DatasourceNutanixCategoriesV2Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.Client).PrismAPI | ||
|
||
// initialize query params | ||
var filter, orderBy, expand, selects *string | ||
var page, limit *int | ||
|
||
if pagef, ok := d.GetOk("page"); ok { | ||
page = utils.IntPtr(pagef.(int)) | ||
} else { | ||
page = nil | ||
} | ||
if limitf, ok := d.GetOk("limit"); ok { | ||
limit = utils.IntPtr(limitf.(int)) | ||
} else { | ||
limit = nil | ||
} | ||
if filterf, ok := d.GetOk("filter"); ok { | ||
filter = utils.StringPtr(filterf.(string)) | ||
} else { | ||
filter = nil | ||
} | ||
if order, ok := d.GetOk("order_by"); ok { | ||
orderBy = utils.StringPtr(order.(string)) | ||
} else { | ||
orderBy = nil | ||
} | ||
if expandf, ok := d.GetOk("expand"); ok { | ||
expand = utils.StringPtr(expandf.(string)) | ||
} else { | ||
expand = nil | ||
} | ||
if selectf, ok := d.GetOk("select"); ok { | ||
selects = utils.StringPtr(selectf.(string)) | ||
} else { | ||
selects = nil | ||
} | ||
resp, err := conn.CategoriesAPIInstance.ListCategories(page, limit, filter, orderBy, expand, selects) | ||
if err != nil { | ||
return diag.Errorf("error while fetching categories : %v", err) | ||
} | ||
|
||
checkResp := resp.Data | ||
|
||
if checkResp != nil { | ||
getResp := resp.Data.GetValue().([]import1.Category) | ||
|
||
if err := d.Set("categories", flattenCategoriesEntities(getResp)); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
} | ||
|
||
d.SetId(resource.UniqueId()) | ||
return nil | ||
} | ||
|
||
func flattenCategoriesEntities(pr []import1.Category) []interface{} { | ||
if len(pr) > 0 { | ||
ctgList := make([]interface{}, len(pr)) | ||
|
||
for k, v := range pr { | ||
ctg := make(map[string]interface{}) | ||
|
||
ctg["ext_id"] = v.ExtId | ||
ctg["key"] = v.Key | ||
ctg["value"] = v.Value | ||
ctg["type"] = flattenCategoryType(v.Type) | ||
ctg["description"] = v.Description | ||
ctg["owner_uuid"] = v.OwnerUuid | ||
ctg["associations"] = flattenAssociationSummary(v.Associations) | ||
ctg["detailed_associations"] = flattenAssociationDetail(v.DetailedAssociations) | ||
ctg["tenant_id"] = v.TenantId | ||
ctg["links"] = flattenLinks(v.Links) | ||
|
||
ctgList[k] = ctg | ||
} | ||
return ctgList | ||
} | ||
return nil | ||
} |
Oops, something went wrong.