Skip to content

Commit

Permalink
add docs for lcm invnetory, prechecks, status, config modules
Browse files Browse the repository at this point in the history
  • Loading branch information
GullapalliAkhil committed Feb 28, 2025
1 parent 4b86585 commit 49d826e
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 17 deletions.
40 changes: 29 additions & 11 deletions nutanix/services/lcmv2/resource_nutanix_lcm_config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package lcmv2
import (
"context"
"encoding/json"
"log"

"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"
Expand All @@ -14,6 +12,7 @@ import (
prismConfig "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"
"log"
)

func ResourceNutanixLcmConfigV2() *schema.Resource {
Expand Down Expand Up @@ -78,7 +77,7 @@ func ResourceNutanixLcmConfigV2Create(ctx context.Context, d *schema.ResourceDat
args := make(map[string]interface{})
args["If-Match"] = utils.StringPtr(etagValue)

body := &lcmconfigimport1.Config{}
body := readResp.Data.GetValue().(lcmconfigimport1.Config)
var connectivityTypeMap = map[string]resources.ConnectivityType{
"$UNKNOWN": resources.CONNECTIVITYTYPE_UNKNOWN,
"$REDACTED": resources.CONNECTIVITYTYPE_REDACTED,
Expand All @@ -90,9 +89,9 @@ func ResourceNutanixLcmConfigV2Create(ctx context.Context, d *schema.ResourceDat
if url, ok := d.GetOk("url"); ok {
body.Url = utils.StringPtr(url.(string))
}

if isAutoInventoryEnabled, ok := d.GetOk("is_auto_inventory_enabled"); ok {
body.IsAutoInventoryEnabled = utils.BoolPtr(isAutoInventoryEnabled.(bool))
if IsExplicitlySet(d, "is_auto_inventory_enabled") {
v := d.Get("is_auto_inventory_enabled").(bool)
body.IsAutoInventoryEnabled = utils.BoolPtr(v)
}
if autoInventorySchedule, ok := d.GetOk("auto_inventory_schedule"); ok {
body.AutoInventorySchedule = utils.StringPtr(autoInventorySchedule.(string))
Expand All @@ -104,16 +103,18 @@ func ResourceNutanixLcmConfigV2Create(ctx context.Context, d *schema.ResourceDat
}
}
}
if isHttpsEnabled, ok := d.GetOk("is_https_enabled"); ok {
body.IsHttpsEnabled = utils.BoolPtr(isHttpsEnabled.(bool))
if IsExplicitlySet(d, "is_https_enabled") {
v := d.Get("is_https_enabled").(bool)
body.IsHttpsEnabled = utils.BoolPtr(v)
}
if hasModuleAutoUpgradeEnabled, ok := d.GetOk("has_module_auto_upgrade_enabled"); ok {
body.HasModuleAutoUpgradeEnabled = utils.BoolPtr(hasModuleAutoUpgradeEnabled.(bool))
if IsExplicitlySet(d, "has_module_auto_upgrade_enabled") {
v := d.Get("has_module_auto_upgrade_enabled").(bool)
body.HasModuleAutoUpgradeEnabled = utils.BoolPtr(v)
}
aJSON, _ := json.MarshalIndent(body, "", " ")
log.Printf("[DEBUG] LCM Update Config Request Spec: %s", string(aJSON))

resp, err := conn.LcmConfigAPIInstance.UpdateConfig(body, clusterId, args)
resp, err := conn.LcmConfigAPIInstance.UpdateConfig(&body, clusterId, args)
if err != nil {
return diag.Errorf("error while updating the LCM config: %v", err)
}
Expand Down Expand Up @@ -180,3 +181,20 @@ func schemaForLinks() *schema.Schema {
},
}
}

func IsExplicitlySet(d *schema.ResourceData, key string) bool {
rawConfig := d.GetRawConfig() // Get raw Terraform config as cty.Value
log.Printf("[DEBUG] Raw Config: %s", rawConfig)
if rawConfig.IsNull() || !rawConfig.IsKnown() {
return false // If rawConfig is null/unknown, key wasn't explicitly set
}

// Convert rawConfig to map and check if key exists
configMap := rawConfig.AsValueMap()
if val, exists := configMap[key]; exists {
log.Printf("[DEBUG1] Key: %s, Value: %s", key, val)
log.Printf("[DEBUG2] values %t", val.IsNull())
return !val.IsNull() // Ensure key exists and isn't explicitly null
}
return false
}
24 changes: 18 additions & 6 deletions nutanix/services/lcmv2/resource_nutanix_lcm_config_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func TestAccV2NutanixLcmConfigUpdate(t *testing.T) {
resourceLcmConfig := "nutanix_lcm_config_v2.update_lcm_config"
datasourceLcmConfigAfterUpdate := "data.nutanix_lcm_config_v2.get_lcm_config_after_update"
datasourceLcmConfigBeforeUpdate := "data.nutanix_lcm_config_v2.get_lcm_config_before_update"

resource.Test(t, resource.TestCase{
PreCheck: func() {},
Expand All @@ -18,12 +19,16 @@ func TestAccV2NutanixLcmConfigUpdate(t *testing.T) {
{
Config: testLcmUpdateConfig(),
Check: resource.ComposeTestCheckFunc(
// Check LCM Config before Update
resource.TestCheckResourceAttr(datasourceLcmConfigBeforeUpdate, "is_auto_inventory_enabled", "false"),

// Update LCM Config Check
resource.TestCheckResourceAttr(resourceLcmConfig, "is_auto_inventory_enabled", "true"),

// Check Auto Inventory is enabled after Update
resource.TestCheckResourceAttr(datasourceLcmConfigAfterUpdate, "is_auto_inventory_enabled", "true"),

resource.TestCheckResourceAttr(datasourceLcmConfigAfterUpdate, "auto_inventory_schedule", "16:30"),
),
},
},
Expand All @@ -32,20 +37,27 @@ func TestAccV2NutanixLcmConfigUpdate(t *testing.T) {

func testLcmUpdateConfig() string {
return `
# Get LCM Config before Update
data "nutanix_lcm_config_v2" "get_lcm_config_before_update" {
}
# Update LCM Config: Enable auto inventory
resource "nutanix_lcm_config_v2" "update_lcm_config" {
is_auto_inventory_enabled = true
auto_inventory_schedule = "16:30"
depends_on = [data.nutanix_lcm_config_v2.get_lcm_config_before_update]
}
# Get LCM Config after Update
data "nutanix_lcm_config_v2" "get_lcm_config_after_update" {
lifecycle {
postcondition {
condition = self.is_auto_inventory_enabled == true
error_message = "Auto Inventory is not enabled, current value: ${self.is_auto_inventory_enabled}"
}
}
depends_on = [nutanix_lcm_config_v2.update_lcm_config]
}
# Update LCM Config: Enable auto inventory
resource "nutanix_lcm_config_v2" "update_lcm_config_reset_auto_inventory" {
is_auto_inventory_enabled = false
depends_on = [data.nutanix_lcm_config_v2.get_lcm_config_after_update]
}
`
}
18 changes: 18 additions & 0 deletions website/docs/d/lcm_config_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
layout: "nutanix"
page_title: "NUTANIX: nutanix_lcm_config_v2"
sidebar_current: "docs-nutanix-datasource-lcm-config-v2"
description: |-
Get LCM configuration.
---

# nutanix_lcm_entity_v2
Get LCM configuration.

## Example

```hcl
data "nutanix_lcm_config_v2" "lcm-configuration" {}
```

See detailed information in [Nutanix LCM Config V4] https://developers.nutanix.com/api-reference?namespace=lifecycle&version=v4.0#tag/Config/operation/getConfig
34 changes: 34 additions & 0 deletions website/docs/d/lcm_status_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: "nutanix"
page_title: "NUTANIX: nutanix_lcm_status_v2"
sidebar_current: "docs-nutanix-datasource-lcm-status-v2"
description: |-
Get the LCM framework status.
---

# nutanix_lcm_status_v2

Get the LCM framework status. Represents the Status of LCM. Status represents details about a pending or ongoing action in LCM.

## Example

```hcl
# 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_status_v2" "lcm_framework_status" {
x_cluster_id = local.pcExtID
}
```

# Argument Reference
The following arguments are supported:

* `x_cluster_id`: (Optional) Cluster uuid on which the resource is present or operation is being performed.

See detailed information in [Nutanix LCM Status v4] https://developers.nutanix.com/api-reference?namespace=lifecycle&version=v4.0#tag/Status
50 changes: 50 additions & 0 deletions website/docs/r/lcm_config_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
layout: "nutanix"
page_title: "NUTANIX: nutanix_lcm_config_v2"
sidebar_current: "docs-nutanix-lcm-config-v2"
description: |-
Update LCM configuration.
---

# nutanix_lcm_entity_v2
Update LCM configuration.

## Example

```hcl
# 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
}
# Enable Auto Inventory, Add Auto Inventory Schedule and enable 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
}
# Update the LCM url to darksite server
resource "nutanix_lcm_config_v2" "lcm-configuration-update-connectivity-type" {
x_cluster_id = local.pcExtID
url = "https://x.x.x.x:8000/builds"
connectivity_type = "DARKSITE_WEB_SERVER"
}
```
## Argument Reference
The following arguments are supported:

* `x_cluster_id`: (Optional) Cluster uuid on which the resource is present or operation is being performed.
* `url`: (Optional) URL of the LCM repository.
* `is_auto_inventory_enabled`: (Optional) Indicates if the auto inventory operation is enabled. The default value is set to False.
* `auto_inventory_schedule`: (Optional) The scheduled time in "%H:%M" 24-hour format of the next inventory execution. Used when auto_inventory_enabled is set to True. The default schedule time is 03:00(AM).
* `connectivity_type`: (Optional)This field indicates whether LCM framework on the cluster is running in connected-site mode or darksite mode.
* `is_https_enabled`: (Optional) Indicates if the LCM URL has HTTPS enabled. The default value is True.
* `has_module_auto_upgrade_enabled`: (Optional) Indicates if LCM is enabled to auto-upgrade products. The default value is False.

See detailed information in [Nutanix LCM Config V4] https://developers.nutanix.com/api-reference?namespace=lifecycle&version=v4.0#tag/Config/operation/updateConfig
35 changes: 35 additions & 0 deletions website/docs/r/lcm_perform_inventory_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
layout: "nutanix"
page_title: "NUTANIX: nutanix_lcm_perform_inventory_v2"
sidebar_current: "docs-nutanix_lcm_perform_inventory_v2"
description: |-
Perform an inventory operation to identify/scan entities on the cluster that can be updated through LCM.
---

# nutanix_lcm_perform_inventory_v2

Perform an inventory operation to identify/scan entities on the cluster that can be updated through LCM.

## Example

```hcl
# 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
}
# perform inventory
resource "nutanix_lcm_perform_inventory_v2" "inventory" {
x_cluster_id = local.pcExtID
}
```

# Argument Reference
The following arguments are supported:

* `x_cluster_id`: (Optional) Cluster uuid on which the resource is present or operation is being performed.

See detailed information in [Nutanix LCM Perform Inventory v4] https://developers.nutanix.com/api-reference?namespace=lifecycle&version=v4.0#tag/Inventory/operation/performInventory
68 changes: 68 additions & 0 deletions website/docs/r/lcm_prechecks_v2.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
layout: "nutanix"
page_title: "NUTANIX: nutanix_lcm_prechecks_v2"
sidebar_current: "docs-nutanix_lcm_prechecks_v2"
description: |-
Perform LCM prechecks for the intended update operation.
---

# nutanix_lcm_prechecks_v2

Perform LCM prechecks for the intended update operation.

## Example

```hcl
# 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
}
# In this example, we are trying to update Calm Policy Engine.
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
}
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"
}
}
```

## Argument Reference

The following arguments are supported:

* `x_cluster_id`: (Optional) Cluster uuid on which the resource is present or operation is being performed.
* `management_server`: (Optional) Cluster management server configuration used while updating clusters with ESX or Hyper-V.
* `entity_update_specs`: (Required) List of entity update objects for getting recommendations.
* `skipped_precheck_flags`: (Optional) List of prechecks to skip. The allowed value is 'powerOffUvms' that skips the pinned VM prechecks. Items Enum: `POWER_OFF_UVMS`

### Management Server
The `management_server` attribute supports the following:

* `hypervisor_type`: (Required) Type of Hypervisor present in the cluster. Enum Values:
* "HYPERV" : Hyper-V Hypervisor.
* "ESX" : ESX Hypervisor.
* "AHV" : Nutanix AHV Hypervisor.
* `ip`: (Required) IP address of the management server.
* `username`: (Required) Username to login to the management server.
* `password`: (Required) Password to login to the management server.

### Entity Update Specs
The `entity_update_specs` attribute supports the following:

* `entity_uuid`: (Required) UUID of the LCM entity.
* `to_version`: (Required) Version to upgrade to.

See detailed information in [Nutanix LCM Prechecks v4] https://developers.nutanix.com/api-reference?namespace=lifecycle&version=v4.0#tag/Prechecks/operation/performPrechecks

0 comments on commit 49d826e

Please sign in to comment.