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

Example for using config downloaded from install.nutanix.com to image nodes #444

Merged
merged 1 commit into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
107 changes: 107 additions & 0 deletions examples/foundation/install.nutanix.com/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"config": {
"bond_mode": "",
"bond_lacp_rate": null,
"rdma_passthrough": false,
"hypervisor_netmask": "xx.xx.xx.xx",
"cvm_netmask": "xx.xx.xx.xx",
"ipmi_netmask": "xx.xx.xx.xx",
"hypervisor_gateway": "10.xx.xx.xx",
"cvm_gateway": "10.xx.xx.xx",
"ipmi_gateway": "10.xx.xx.xx",
"ui_skip_network_check": true,
"clusters": [
{
"redundancy_factor": 2,
"cluster_members": [
"10.xx.xx.xx",
"10.xx.xx.xx",
"10.xx.xx.xx"
],
"cluster_name": "TestCheck",
"cluster_external_ip": "10.xx.xx.xx"
}
],
"blocks": [
{
"block_id": "XXXXXXXX",
"ui_block_id": "XXXXXXXX",
"nodes": [
{
"node_position": "A",
"ipmi_ip": "10.xx.xx.xx",
"hypervisor_ip": "10.xx.xx.xx",
"cvm_ip": "10.xx.xx.xx",
"hypervisor_hostname": "Check1",
"ipmi_user": "xxxxx",
"ipmi_password": "xxxx",
"cvm_gb_ram": null
},
{
"node_position": "B",
"ipmi_ip": "10.xx.xx.xx",
"hypervisor_ip": "10.xx.xx.xx",
"cvm_ip": "10.xx.xx.xx",
"hypervisor_hostname": "Check2",
"ipmi_user": "xxxxx",
"ipmi_password": "xxxx",
"cvm_gb_ram": null
},
{
"node_position": "C",
"ipmi_ip": "10.xx.xx.xx",
"hypervisor_ip": "10.xx.xx.xx",
"cvm_ip": "10.xx.xx.xx",
"hypervisor_hostname": "Check3",
"ipmi_user": "xxxxx",
"ipmi_password": "xxxx",
"cvm_gb_ram": null
}
]
},
{
"block_id": "XXXXXXXX",
"ui_block_id": "XXXXXXXX",
"nodes": [
{
"node_position": "A",
"ipmi_ip": "10.xx.xx.xx",
"hypervisor_ip": "10.xx.xx.xx",
"cvm_ip": "10.xx.xx.xx",
"hypervisor_hostname": "Check11",
"ipmi_user": "xxxxx",
"ipmi_password": "xxxx",
"cvm_gb_ram": null
},
{
"node_position": "B",
"ipmi_ip": "10.xx.xx.xx",
"hypervisor_ip": "10.xx.xx.xx",
"cvm_ip": "10.xx.xx.xx",
"hypervisor_hostname": "Check12",
"ipmi_user": "xxxxx",
"ipmi_password": "xxxx",
"cvm_gb_ram": null
},
{
"node_position": "C",
"ipmi_ip": "10.xx.xx.xx",
"hypervisor_ip": "10.xx.xx.xx",
"cvm_ip": "10.xx.xx.xx",
"hypervisor_hostname": "Check13",
"ipmi_user": "xxxxx",
"ipmi_password": "xxxx",
"cvm_gb_ram": null
}
]
}
],
"eos_metadata": {
"account_name": [
"Nutanix Corporate"
],
"config_id": "axaskmxaklsmxij92ji2x",
"email": "xx.xx@xx.com"
}
}
}
89 changes: 89 additions & 0 deletions examples/foundation/install.nutanix.com/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
Description:
- Here we will create an automation which picks up config.json, containing the blocks of nodes &
cluster info, create spec dynamically as per the struture of config.json and do imaging of nodes.
- You can download this config.json from install.nutanix.com or create one using the sample config.json given.
- Here we are following Bare metal workflow, imaging nodes using IPMI.
*/

/*
[IMPORTANT]
- Please note that this is just an example and the spec generated dynamically is only having minimal fields which are required
for imaging the blocks of nodes and creating cluster. You can add more fields as per the requirements.
- This example was created as per reference to config.json downloaded from install.nutanix.com -> Foundation Preconfiguration.
- Keep config.json in same directory where this .tf file is kept
*/



// pull provider plugin with appropriate version
terraform {
required_providers{
nutanix = {
source = "nutanix/nutanix"
version = "1.5.0-beta"
}
}
}

// give provider config
provider "nutanix" {
foundation_endpoint = "10.xx.xx.xx"
}

// import config.json . Replace the file location if required.
locals{
config = (jsondecode(file("config.json"))).config
}

// pull nos packages info
data "nutanix_foundation_nos_packages" "nos"{}

resource "nutanix_foundation_image_nodes" "batch1" {

// give required info
ipmi_netmask = local.config.ipmi_netmask
ipmi_gateway = local.config.ipmi_gateway
cvm_netmask = local.config.cvm_netmask
cvm_gateway = local.config.cvm_gateway
hypervisor_netmask = local.config.hypervisor_netmask
hypervisor_gateway = local.config.hypervisor_gateway

// use nos package info from data source
nos_package = data.nutanix_foundation_nos_packages.nos.entities[0]

// this will dynamically create multiple blocks of multiple nodes spec using array of blocks in config
dynamic "blocks" {
for_each = local.config.blocks
content{
block_id = blocks.value.block_id
dynamic "nodes" {
for_each = blocks.value.nodes
content {
ipmi_ip = nodes.value.ipmi_ip
ipmi_user = nodes.value.ipmi_user
ipmi_password = nodes.value.ipmi_password
cvm_ip = nodes.value.cvm_ip
image_now = true
hypervisor_ip = nodes.value.hypervisor_ip
hypervisor = "kvm"
hypervisor_hostname = nodes.value.hypervisor_hostname
node_position = nodes.value.node_position
}
}
}
}

// this will create multiple clusters spec as per array of cluster in config file
dynamic "clusters"{
for_each = local.config.clusters
content{
cluster_name = clusters.value.cluster_name
redundancy_factor = clusters.value.redundancy_factor
cluster_external_ip = clusters.value.cluster_external_ip
cluster_members = clusters.value.cluster_members
single_node_cluster = length(clusters.value.cluster_members) > 1 ? false : true
cluster_init_now = true
}
}
}