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

Feat/lcm integration terraform #753

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ad6ed41
LCM config and inventory changes
GullapalliAkhil Feb 11, 2025
0caf884
LCM config and inventory changes
GullapalliAkhil Feb 17, 2025
3664b9b
utilise lifecycle client
GullapalliAkhil Feb 17, 2025
6a54cb8
Add LCM config update chanegs
GullapalliAkhil Feb 17, 2025
2e38b7e
Changes for lcm
GullapalliAkhil Feb 18, 2025
18bff9a
implement data sources for get LCM entity and list LCM entities
Haroon-Dweikat-Ntx Feb 18, 2025
654dcfa
lcm changes to support datasource
GullapalliAkhil Feb 18, 2025
e68354e
merge
GullapalliAkhil Feb 18, 2025
a8ecd31
implement resource for LCM Preload Artifacts
Haroon-Dweikat-Ntx Feb 18, 2025
496b9b0
Merge remote-tracking branch 'origin/feat/lcm-integration-terraform' …
Haroon-Dweikat-Ntx Feb 18, 2025
4e65dbc
implement resource for LCM Upgrade
Haroon-Dweikat-Ntx Feb 18, 2025
5874f64
fix lcm status data source id
Haroon-Dweikat-Ntx Feb 18, 2025
39a05a9
fix lcm entities data source
Haroon-Dweikat-Ntx Feb 18, 2025
b95f5b1
fix precheck resource schema and code
Haroon-Dweikat-Ntx Feb 18, 2025
a38d97d
add nutanix_lcm_prechecks_v2 to provider resource map
Haroon-Dweikat-Ntx Feb 18, 2025
8d1802b
fix lcm inventory code
Haroon-Dweikat-Ntx Feb 18, 2025
0c2bb26
fix preload artifacts, extracting task with correct type
Haroon-Dweikat-Ntx Feb 18, 2025
a70dded
fix lcm upgrade resource, extracting task with correct type
Haroon-Dweikat-Ntx Feb 18, 2025
8abd5e9
Merge branch 'feat/lcm-integration-terraform' of github.com:nutanix/t…
GullapalliAkhil Feb 19, 2025
7c6cffc
add get config in provider
GullapalliAkhil Feb 19, 2025
4d15a5f
fix lcm status
Haroon-Dweikat-Ntx Feb 19, 2025
adb8586
Fix data source lcm config
GullapalliAkhil Feb 19, 2025
7a73361
Merge branch 'feat/lcm-integration-terraform' of github.com:nutanix/t…
GullapalliAkhil Feb 19, 2025
0412236
lcm status fix operation type
Haroon-Dweikat-Ntx Feb 19, 2025
85e413e
Merge branch 'feat/lcm-integration-terraform' of github.com:nutanix/t…
Haroon-Dweikat-Ntx Feb 19, 2025
3777292
rename resource_nutanix_lcm_upgrade_v2.go
Haroon-Dweikat-Ntx Feb 19, 2025
3727d7f
dev test for lcm inventory, prechecks, and upgrade
Haroon-Dweikat-Ntx Feb 19, 2025
010d1f4
update json var file with lcm vars
Haroon-Dweikat-Ntx Feb 19, 2025
27bbb06
docs and examples for lcm upgrade
Haroon-Dweikat-Ntx Feb 19, 2025
90b5f00
fix lcm upgrade test
Haroon-Dweikat-Ntx Feb 19, 2025
a4e1341
lint fix
Haroon-Dweikat-Ntx Feb 19, 2025
2203d50
lint fixes
Haroon-Dweikat-Ntx Feb 19, 2025
d6e6826
lint fixes
Haroon-Dweikat-Ntx Feb 19, 2025
4d25935
lint fixes
Haroon-Dweikat-Ntx Feb 19, 2025
1eae4dc
fix precheck, call create in Read ctx instead of update ctx
Haroon-Dweikat-Ntx Feb 19, 2025
24715ef
docs and examples for lcm entities
Haroon-Dweikat-Ntx Feb 19, 2025
bd560c0
Merge branch 'feat/lcm-integration-terraform' of github.com:nutanix/t…
GullapalliAkhil Feb 20, 2025
5922ea6
Add changes for update config
GullapalliAkhil Feb 20, 2025
bddb32d
Make cluster if field optional as per api reference documentation
GullapalliAkhil Feb 24, 2025
856a689
Rename files to follow a specifc format and add testcase for LCM config
GullapalliAkhil Feb 24, 2025
035b40a
change var names and commit deleted files change
GullapalliAkhil Feb 24, 2025
4b86585
change of testcase
GullapalliAkhil Feb 27, 2025
49d826e
add docs for lcm invnetory, prechecks, status, config modules
GullapalliAkhil Feb 28, 2025
2fd0e11
Add argument reference for Get config
GullapalliAkhil Mar 3, 2025
e12859b
Add example for lcm config
GullapalliAkhil Mar 3, 2025
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
41 changes: 41 additions & 0 deletions examples/lcm_config_v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "2.1.0"
}
}
}

#defining nutanix configuration
provider "nutanix" {
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}

# List Prism Central
data "nutanix_clusters_v2" "pc" {
filter = "config/clusterFunction/any(t:t eq Clustermgmt.Config.ClusterFunctionRef'PRISM_CENTRAL')"
}

locals {
pcExtID = data.nutanix_clusters_v2.pc.cluster_entities[0].ext_id
}

# Example here, we are enabling Auto Inventory, adding Auto Inventory Schedule and enabling auto upgrade
resource "nutanix_lcm_config_v2" "lcm-configuration-update" {
x_cluster_id = local.pcExtID
is_auto_inventory_enabled = true
auto_inventory_schedule = "16:30"
has_module_auto_upgrade_enabled = true
}

# Read LCM config.
data "nutanix_lcm_config_v2" "get-lcm-configuration" {
x_cluster_id = local.pcExtID
depends_on = [nutanix_lcm_config_v2.lcm-configuration-update]
}

5 changes: 5 additions & 0 deletions examples/lcm_config_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 = "password"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/lcm_config_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
}
41 changes: 41 additions & 0 deletions examples/lcm_entities_v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "2.1.0"
}
}
}

#defining nutanix configuration
provider "nutanix" {
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}

# get all entities
data "nutanix_lcm_entities_v2" "lcm-entities" {}

# get filtered entities
data "nutanix_lcm_entities_v2" "lcm-entities-filtered" {
filter = "entityModel eq 'Calm Policy Engine'"
}

# get limited entities
data "nutanix_lcm_entities_v2" "lcm-entities-limited" {
limit = 5
}

# get filtered and limited entities
data "nutanix_lcm_entities_v2" "lcm-entities-filter-and-limit" {
filter = "startswith(entityModel,'Calm')"
limit = 5
}

# get specific entity
data "nutanix_lcm_entity_v2" "entity" {
ext_id = data.nutanix_lcm_entities_v2.lcm-entities.entities[0].ext_id
}
5 changes: 5 additions & 0 deletions examples/lcm_entities_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 = "password"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/lcm_entities_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
}
104 changes: 104 additions & 0 deletions examples/lcm_upgrade_v2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "2.1.0"
}
}
}

#defining nutanix configuration
provider "nutanix" {
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}

# List Prism Central
data "nutanix_clusters_v2" "pc" {
filter = "config/clusterFunction/any(t:t eq Clustermgmt.Config.ClusterFunctionRef'PRISM_CENTRAL')"
}

locals {
pcExtID = data.nutanix_clusters_v2.pc.cluster_entities[0].ext_id
}

data "nutanix_lcm_entities_v2" "lcm-entities" {
filter = "entityModel eq 'Calm Policy Engine'"
}

data "nutanix_lcm_entity_v2" "entity-before-upgrade" {
ext_id = data.nutanix_lcm_entities_v2.lcm-entities.entities[0].ext_id
}

# perform inventory
resource "nutanix_lcm_perform_inventory_v2" "inventory" {
x_cluster_id = local.pcExtID
depends_on = [data.nutanix_lcm_entity_v2.entity-before-upgrade]
}

resource "nutanix_lcm_prechecks_v2" "pre-checks" {
x_cluster_id = local.pcExtID
entity_update_specs {
entity_uuid = data.nutanix_lcm_entity_v2.entity-before-upgrade.ext_id
to_version = "4.0.0"
}
depends_on = [nutanix_lcm_perform_inventory_v2.inventory]
}

# check if there is any operation in progress before starting the upgrade
data "nutanix_lcm_status_v2" "status-before-upgrade" {
x_cluster_id = local.pcExtID
lifecycle {
postcondition {
condition = self.in_progress_operation[0].operation_type == "" && self.in_progress_operation[0].operation_id == ""
error_message = "operation is in progress: ${self.in_progress_operation[0].operation_type}"
}
}
depends_on = [nutanix_lcm_prechecks_v2.pre-checks]
}

# upgrade the entity
resource "nutanix_lcm_upgrade_v2" "upgrade" {
entity_update_specs {
entity_uuid = data.nutanix_lcm_entity_v2.entity-before-upgrade.ext_id
to_version = "4.0.0"
}
depends_on = [data.nutanix_lcm_status_v2.status-before-upgrade]
}

# check if there is any operation in progress after upgrade
data "nutanix_lcm_status_v2" "status-after-upgrade" {
x_cluster_id = local.pcExtID
lifecycle {
postcondition {
condition = self.in_progress_operation[0].operation_type == "" && self.in_progress_operation[0].operation_id == ""
error_message = "operation is in progress: ${self.in_progress_operation[0].operation_type}"
}
}
depends_on = [nutanix_lcm_upgrade_v2.upgrade]
}

# fetch the entity after upgrade
data "nutanix_lcm_entity_v2" "entity-after-upgrade" {
ext_id = data.nutanix_lcm_entities_v2.lcm-entities.entities[0].ext_id
lifecycle {
postcondition {
condition = self.ext_id == data.nutanix_lcm_entity_v2.entity-before-upgrade.ext_id
error_message = "entity ext id changed"
}
postcondition {
condition = self.entity_version == "4.0.0"
error_message = "entity version is not upgraded, current version: ${self.entity_version}"
}
postcondition {
condition = self.entity_model == "Calm Policy Engine"
error_message = "entity model is changed, current model: ${self.entity_model}"
}
}
depends_on = [nutanix_lcm_upgrade_v2.upgrade, data.nutanix_lcm_status_v2.status-after-upgrade]
}


5 changes: 5 additions & 0 deletions examples/lcm_upgrade_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 = "password"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/lcm_upgrade_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
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/nutanix/ntnx-api-golang-clients/clustermgmt-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/dataprotection-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/iam-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.1
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ github.com/nutanix/ntnx-api-golang-clients/dataprotection-go-client/v4 v4.0.1 h1
github.com/nutanix/ntnx-api-golang-clients/dataprotection-go-client/v4 v4.0.1/go.mod h1:S07bx9/6uUbMOY/OUJsaIUdvZ/LDaE46Kx9VX7Pt7Ek=
github.com/nutanix/ntnx-api-golang-clients/iam-go-client/v4 v4.0.1 h1:zWbA2qtSJt0WsBcEhqqv6FQTSz8pIwBnHA5etaQg4qo=
github.com/nutanix/ntnx-api-golang-clients/iam-go-client/v4 v4.0.1/go.mod h1:+HvW0f4QGDRZ3/1jcXvF7xA/gQsvQc4XtZy6OUobaO4=
github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4 v4.0.1 h1:JBSalV1dvI+5YjZzzE9E/tz8V4A7CbSA7wl4C3L8iYs=
github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4 v4.0.1/go.mod h1:fQTNQlfh5g4SavaQn+sDoMn29K+Lur5lHWtnbq3uA28=
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1 h1:9SC9PsLQjvkuo0MyL2HMDXQ/dQl1a57RDR4OS22so/U=
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1/go.mod h1:75Ro+aFIepNAkf2eWjFrFR7m+Ct36EVrD9n9pwAYBrc=
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.1 h1:2D2ZJd5Cn0fMeWYnTEHsR1Fcv2G1BSrOAl1fVURtfn4=
Expand Down
7 changes: 7 additions & 0 deletions nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/clusters"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/dataprotection"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/iam"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/lcm"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/microseg"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/networking"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/prism"
Expand Down Expand Up @@ -111,6 +112,10 @@ func (c *Config) Client() (*Client, error) {
if err != nil {
return nil, err
}
LcmClient, err := lcm.NewLcmClient(configCreds)
if err != nil {
return nil, err
}
return &Client{
WaitTimeout: c.WaitTimeout,
API: v3Client,
Expand All @@ -126,6 +131,7 @@ func (c *Config) Client() (*Client, error) {
VolumeAPI: volumeClient,
DataProtectionAPI: dataprotectionClient,
VmmAPI: vmmClient,
LcmAPI: LcmClient,
}, nil
}

Expand All @@ -145,4 +151,5 @@ type Client struct {
VolumeAPI *volumes.Client
DataProtectionAPI *dataprotection.Client
VmmAPI *vmm.Client
LcmAPI *lcm.Client
}
9 changes: 9 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
foundationCentral "github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/foundationCentral"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/iam"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/iamv2"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/lcmv2"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/ndb"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/networking"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/networkingv2"
Expand Down Expand Up @@ -289,6 +290,10 @@ func Provider() *schema.Provider {
"nutanix_clusters_v2": clustersv2.DatasourceNutanixClusterEntitiesV2(),
"nutanix_host_v2": clustersv2.DatasourceNutanixHostEntityV2(),
"nutanix_hosts_v2": clustersv2.DatasourceNutanixHostEntitiesV2(),
"nutanix_lcm_status_v2": lcmv2.DatasourceNutanixLcmStatusV2(),
"nutanix_lcm_entities_v2": lcmv2.DatasourceNutanixLcmEntitiesV2(),
"nutanix_lcm_entity_v2": lcmv2.DatasourceNutanixLcmEntityV2(),
"nutanix_lcm_config_v2": lcmv2.DatasourceNutanixLcmConfigV2(),
},
ResourcesMap: map[string]*schema.Resource{
"nutanix_virtual_machine": vmm.ResourceNutanixVirtualMachine(),
Expand Down Expand Up @@ -385,6 +390,10 @@ func Provider() *schema.Provider {
"nutanix_pc_registration_v2": clustersv2.ResourceNutanixClusterPCRegistrationV2(),
"nutanix_clusters_discover_unconfigured_nodes_v2": clustersv2.ResourceNutanixClusterDiscoverUnconfiguredNodesV2(),
"nutanix_clusters_unconfigured_node_networks_v2": clustersv2.ResourceNutanixClusterUnconfiguredNodeNetworkV2(),
"nutanix_lcm_perform_inventory_v2": lcmv2.ResourceNutanixLcmPerformInventoryV2(),
"nutanix_lcm_prechecks_v2": lcmv2.ResourceNutanixPreChecksV2(),
"nutanix_lcm_upgrade_v2": lcmv2.ResourceLcmUpgradeV2(),
"nutanix_lcm_config_v2": lcmv2.ResourceNutanixLcmConfigV2(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down
43 changes: 43 additions & 0 deletions nutanix/sdks/v4/lcm/lcm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lcm

import (
"github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4/api"
lcm "github.com/nutanix/ntnx-api-golang-clients/lifecycle-go-client/v4/client"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type Client struct {
LcmConfigAPIInstance *api.ConfigApi
LcmInventoryAPIInstance *api.InventoryApi
LcmPreChecksAPIInstance *api.PrechecksApi
LcmStatusAPIInstance *api.StatusApi
LcmEntitiesAPIInstance *api.EntitiesApi
LcmUpgradeAPIInstance *api.UpgradesApi
}

func NewLcmClient(credentials client.Credentials) (*Client, error) {
var baseClient *lcm.ApiClient

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

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

baseClient = pcClient
}

f := &Client{
LcmInventoryAPIInstance: api.NewInventoryApi(baseClient),
LcmConfigAPIInstance: api.NewConfigApi(baseClient),
LcmPreChecksAPIInstance: api.NewPrechecksApi(baseClient),
LcmStatusAPIInstance: api.NewStatusApi(baseClient),
LcmEntitiesAPIInstance: api.NewEntitiesApi(baseClient),
LcmUpgradeAPIInstance: api.NewUpgradesApi(baseClient),
}
return f, nil
}
Loading
Loading