Skip to content

Commit

Permalink
V4 storage containers on v4 temp design 2.0 (#18)
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

* datadource for clusters

* lint fixes

* 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

* delete Operation for directory service

* CRUD for user groups

* datasource for categories

* Crud and tcs for categories

* crud & test for images

* sdk versioning

* templates datasource

* datasource for template versions

* deploy templates

* spec for vms

* create Ops

* CUD ops done

* Get VMs

* VMs

* CRUD for vm disks

* CRUD/ds serial ports

* cdrom CRUD

* insert/eject cdrom

* vm actions power

* vm shutdown actions

* CRUD gpus

* missing return in vms

* vm clone resource

* tcs for vm resource

* tcs for vms

* acc for images

* adding more tcs

* Vms disk Tcs

* tcs for serial port

* resource tcs for cdrom

* TCs for cdroms

* vm clone example and docs

* tcs for vm power state

* power state testcase

* shutdown Tcs

* Adding TCs for Gpus

* vm clone testcases

* fic for argument naming

* resource and tests for update guest customization for next boot

* guest customization update doc and example

* cluster v4 resource

* fix for b2 version

* data source for storage containers and storage container  modules

* implement storage containers resources, Create Operation done

* fix create operation for storage containers, implement Delete Operation

* implement Update  Operation for storage containers

* acc tests for storage containers

* storage container docs for resource and data source

* test_config_v4 file for acc tests

* extract storage containers into separate package, use new prism sdk instead of internal sdk

* implement data source for storage stats info

* set the default values for sampling interval and stat type attributes, convert timestamp to string in the flattenValueTimestamp  method

* Revert "set the default values for sampling interval and stat type attributes, convert timestamp to string in the flattenValueTimestamp  method"

This reverts commit 2abc8b3b2dc11c453aaa775a0f84ffeaf677246a.

* set the default values for sampling interval and stat type attributes, convert timestamp to string in the flattenValueTimestamp  method

* acc test for storage stat info

* rename from storage stats to storage container stat

* add test case to validate required args

* docs for storage container stats info

* use internal prism sdk

* use internal prism sdk

* set the default values for sampling interval and stat type attributes, convert timestamp to string in the flattenValueTimestamp  method

* exclude vendor

* remove all other modules and  sdk, update provider resource/data maps, change the name from v4 to v2

* remove all other modules and  sdk, update provider resource/data maps, change the name from v4 to v2

* change the storage container stats info from v4 to v2, add examples

* change the test_config_v4 from v4 to v2

* Revert "exclude vendor"

This reverts commit 5728f1196ec8c29ed0382b757d22342fe64fe89e.

---------

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]>
Co-authored-by: Gevorg <[email protected]>
  • Loading branch information
8 people authored Sep 9, 2024
1 parent 81820b5 commit 9e9725c
Show file tree
Hide file tree
Showing 26 changed files with 3,054 additions and 1 deletion.
37 changes: 37 additions & 0 deletions examples/storage_containers_stats_info_v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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
}

#pull all clusters data
data "nutanix_clusters" "clusters"{}

#create local variable pointing to desired cluster
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

#pull the storage container stats data
data "nutanix_storage_container_stats_info_v2" "test" {
ext_id = "<storage_container_ext_id>"
start_time = "<start_time>"
end_time = "<end_time>"
}


5 changes: 5 additions & 0 deletions examples/storage_containers_stats_info_v2/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "Nutanix/123456"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/storage_containers_stats_info_v2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#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
}
variable "nutanix_port" {
type = string
}
67 changes: 67 additions & 0 deletions examples/storage_containers_v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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
}

#pull all clusters data
data "nutanix_clusters" "clusters"{}

#create local variable pointing to desired cluster
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

#creating storage container
resource "nutanix_storage_containers_v2" "example" {
name = "<storage_container_name>"
cluster_ext_id = local.cluster1
logical_advertised_capacity_bytes = <logical_advertised_capacity_bytes>
logical_explicit_reserved_capacity_bytes = <logical_explicit_reserved_capacity_bytes>
replication_factor = <replication_factor>
nfs_whitelist_addresses {
ipv4 {
value = "<nfs_whitelist_addresses>"
prefix_length ="<prefix_length>"
}
}
erasure_code = "OFF"
is_inline_ec_enabled = false
has_higher_ec_fault_domain_preference = false
cache_deduplication = "OFF"
on_disk_dedup = "OFF"
is_compression_enabled = true
is_internal = false
is_software_encryption_enabled = false
}

#output the storage container info
output "subnet" {
value = nutanix_storage_containers_v2.example
}


#pull all storage containers data in the system
data "nutanix_storage_containers_v2" "example"{}


#pull a storage containers data by ext id
data "nutanix_storage_container_v2" "example"{
cluster_ext_id = local.cluster1
storage_container_ext_id = nutanix_storage_containers_v2.example.id
}
5 changes: 5 additions & 0 deletions examples/storage_containers_v2/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "Nutanix/123456"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/storage_containers_v2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#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
}
variable "nutanix_port" {
type = string
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ require (
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1
// github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.3-alpha.2
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/spf13/cast v1.3.1
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1-beta.1 h1:h
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/nutanix-core/ntnx-api-golang-sdk-internal/iam-go-client/v16 v16.8.0-5280 h1:sYX9SWnyph1+gjibK8kOQNS5WmbdakCVw2kU8/oCWn8=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/iam-go-client/v16 v16.8.0-5280/go.mod h1:cSEUNcUEpaGpZq3CXj4wSczM3zzPQLzTDfYwhkl0aLQ=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/clustermgmt-go-client/v16 v16.9.0-8538 h1:cL38XRjDYwwoKMiK9qRXF7ADXO2wxMqI64lpgn2yQR4=
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/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
8 changes: 8 additions & 0 deletions nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v3/foundation"
v3 "github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v3/prism"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/iam"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/clusters"
)

// Version represents api version
Expand Down Expand Up @@ -99,6 +100,11 @@ func (c *Config) Client() (*Client, error) {
if err != nil {
return nil, err
}
clustersClient, err := clusters.NewClustersClient(configCreds)
if err != nil {
return nil, err
}

return &Client{
WaitTimeout: c.WaitTimeout,
API: v3Client,
Expand All @@ -110,6 +116,7 @@ func (c *Config) Client() (*Client, error) {
PrismAPI: prismClient,
MicroSegAPI: microsegClient,
IamAPI: iamClient,
ClusterAPI: clustersClient,
}, nil
}

Expand All @@ -125,4 +132,5 @@ type Client struct {
PrismAPI *prism.Client
MicroSegAPI *microseg.Client
IamAPI *iam.Client
ClusterAPI *clusters.Client
}
5 changes: 5 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v1/prism"
"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"
)

var requiredProviderFields map[string][]string = map[string][]string{
Expand Down Expand Up @@ -251,6 +252,9 @@ func Provider() *schema.Provider {
"nutanix_users_v2": iamv2.DatasourceNutanixUsersV2(),
"nutanix_authorization_policy_v2": iamv2.DatasourceNutanixAuthorizationPolicyV2(),
"nutanix_authorization_policies_v2": iamv2.DatasourceNutanixAuthorizationPoliciesV2(),
"nutanix_storage_container_v2": storagecontainersv2.DatasourceNutanixStorageContainerV2(),
"nutanix_storage_containers_v2": storagecontainersv2.DatasourceNutanixStorageContainersV2(),
"nutanix_storage_container_stats_info_v2": storagecontainersv2.DatasourceNutanixStorageStatsInfoV2(),
},
ResourcesMap: map[string]*schema.Resource{
"nutanix_virtual_machine": prism.ResourceNutanixVirtualMachine(),
Expand Down Expand Up @@ -316,6 +320,7 @@ func Provider() *schema.Provider {
"nutanix_users_v2": iamv2.ResourceNutanixUserV2(),
"nutanix_authorization_policy_v2": iamv2.ResourceNutanixAuthPoliciesV2(),
"nutanix_saml_identity_providers_v2": iamv2.ResourceNutanixSamlIdpV2(),
"nutanix_storage_containers_v2": storagecontainersv2.ResourceNutanixStorageContainersV2(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down
37 changes: 37 additions & 0 deletions nutanix/sdks/v4/clusters/clusters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package clusters

import (
"github.com/nutanix-core/ntnx-api-golang-sdk-internal/clustermgmt-go-client/v16/api"
network "github.com/nutanix-core/ntnx-api-golang-sdk-internal/clustermgmt-go-client/v16/client"

"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type Client struct {
ClusterEntityAPI *api.ClustersApi
StorageContainersAPI *api.StorageContainersApi
}

func NewClustersClient(credentials client.Credentials) (*Client, error) {
var baseClient *network.ApiClient

// check if all required fields are present. Else create an empty client
if credentials.Username != "" && credentials.Password != "" && credentials.Endpoint != "" {
pcClient := network.NewApiClient()

pcClient.Host = credentials.Endpoint
pcClient.Password = credentials.Password
pcClient.Username = credentials.Username
pcClient.Port = 9440
pcClient.VerifySSL = false

baseClient = pcClient
}

f := &Client{
ClusterEntityAPI: api.NewClustersApi(baseClient),
StorageContainersAPI: api.NewStorageContainersApi(baseClient),
}

return f, nil
}
6 changes: 5 additions & 1 deletion nutanix/sdks/v4/prism/prism.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package prism
import (
"github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/api"
prism "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/client"
"github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16/api"
prism "github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16/client"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type Client struct {
TaskRefAPI *api.TasksApi
TaskRefAPI *api.TasksApi
CategoriesAPIInstance *api.CategoriesApi
}

func NewPrismClient(credentials client.Credentials) (*Client, error) {
Expand All @@ -28,6 +31,7 @@ func NewPrismClient(credentials client.Credentials) (*Client, error) {

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

return f, nil
Expand Down
Loading

0 comments on commit 9e9725c

Please sign in to comment.