Skip to content

Commit

Permalink
Feat/v4 categories on v4-temp-design (#21)
Browse files Browse the repository at this point in the history
* 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
7 people authored Sep 10, 2024
1 parent 9e9725c commit c13c005
Show file tree
Hide file tree
Showing 16 changed files with 1,258 additions and 1 deletion.
36 changes: 36 additions & 0 deletions examples/categories_v2/main.tf
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
}
4 changes: 4 additions & 0 deletions examples/categories_v2/terraform.tfvars
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"
10 changes: 10 additions & 0 deletions examples/categories_v2/variables.tf
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
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/nutanix-core/ntnx-api-golang-sdk-internal/iam-go-client/v16 v16.8.0-5280
github.com/nutanix-core/ntnx-api-golang-sdk-internal/clustermgmt-go-client/v16 v16.9.0-8538
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-8500
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ github.com/nutanix-core/ntnx-api-golang-sdk-internal/clustermgmt-go-client/v16 v
github.com/nutanix-core/ntnx-api-golang-sdk-internal/clustermgmt-go-client/v16 v16.9.0-8538/go.mod h1:Wt2vo6h0QCGvQGKyY2Tw9OOU0dhhtjRL5nTd0Lx8Gho=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-8500 h1:UPGaPcMuM30BTQ6FflAgF5LP/8t8/zVDFIOeZAtXn+8=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-8500/go.mod h1:qmOw/29LhPpII8cDmbTL0OF3btwp97ss7nFcQz72NDM=
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1 h1:hvy3QCc2SgVidYxTq0rRPOazJOt1PP8A86kW7j6sywU=
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1/go.mod h1:Yhk+xD4mN90OKEHnk5ARf97CX5p4+MEC/B/YIVoZeZ0=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down
4 changes: 4 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v2/networkingv2"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v2/iamv2"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v2/storagecontainersv2"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v2/prismv2"
)

var requiredProviderFields map[string][]string = map[string][]string{
Expand Down Expand Up @@ -255,6 +256,8 @@ func Provider() *schema.Provider {
"nutanix_storage_container_v2": storagecontainersv2.DatasourceNutanixStorageContainerV2(),
"nutanix_storage_containers_v2": storagecontainersv2.DatasourceNutanixStorageContainersV2(),
"nutanix_storage_container_stats_info_v2": storagecontainersv2.DatasourceNutanixStorageStatsInfoV2(),
"nutanix_category_v2": prismv2.DatasourceNutanixCategoryV2(),
"nutanix_categories_v2": prismv2.DatasourceNutanixCategoriesV2(),
},
ResourcesMap: map[string]*schema.Resource{
"nutanix_virtual_machine": prism.ResourceNutanixVirtualMachine(),
Expand Down Expand Up @@ -321,6 +324,7 @@ func Provider() *schema.Provider {
"nutanix_authorization_policy_v2": iamv2.ResourceNutanixAuthPoliciesV2(),
"nutanix_saml_identity_providers_v2": iamv2.ResourceNutanixSamlIdpV2(),
"nutanix_storage_containers_v2": storagecontainersv2.ResourceNutanixStorageContainersV2(),
"nutanix_category_v2": prismv2.ResourceNutanixCategoriesV2(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down
2 changes: 1 addition & 1 deletion nutanix/sdks/v4/prism/prism.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewPrismClient(credentials client.Credentials) (*Client, error) {
}

f := &Client{
TaskRefAPI: api.NewTasksApi(baseClient),
TaskRefAPI: api.NewTasksApi(baseClient),
CategoriesAPIInstance: api.NewCategoriesApi(baseClient),
}

Expand Down
225 changes: 225 additions & 0 deletions nutanix/services/v2/prismv2/data_source_nutanix_categories_v2.go
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
}
Loading

0 comments on commit c13c005

Please sign in to comment.