From c28261ceaf4ebf6f0335316ab7cc7b110c43e957 Mon Sep 17 00:00:00 2001 From: Shekhar Joshi Date: Thu, 22 Aug 2024 09:50:33 -0400 Subject: [PATCH] Update SDC Host Linux module to add autobuild scini case --- examples/sdc_host_linux/README.md | 32 +++++++++-------- examples/sdc_host_linux/main.tf | 2 +- examples/sdc_host_linux/variables.tf | 27 ++++++++++---- modules/sdc_host_linux/README.md | 29 +++------------ modules/sdc_host_linux/main.tf | 53 ++++++++++++++++++++++++---- modules/sdc_host_linux/variables.tf | 26 ++++++++++---- 6 files changed, 111 insertions(+), 58 deletions(-) diff --git a/examples/sdc_host_linux/README.md b/examples/sdc_host_linux/README.md index f371dbd..09b3fd3 100644 --- a/examples/sdc_host_linux/README.md +++ b/examples/sdc_host_linux/README.md @@ -37,29 +37,34 @@ remote_host={ } -ip="1.2.11.10" -scini_url="http://example.com/sw_dev/Artifacts/Build-All-Ubuntu22.04/3.6.700.103/release/5.15.0-112-generic" +ip="1.2.11.4" versions={ - pflex = "3.6.700.103" - kernel = "5.15.0-112-generic" + pflex = "4.5.3000.118" + kernel = "5.15.0-1-generic" +} +scini = { + url = "http://example.com/release/5.15.0-1-generic" + linux_distro = "RHEL" #"Ubuntu" + autobuild_scini = true } sdc_pkg = { - url = "http://example.com/release/SIGNED/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar" - local_pkg = "EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar" + url = "http://example.com/release/SIGNED/EMC-ScaleIO-sdc-4.5-3000.118.Ubuntu.22.04.x86_64.tar" local_dir = "/tmp" - pkg_name = "EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar" + pkg_name = "EMC-ScaleIO-sdc-4.5-3000.118.Ubuntu.22.04.x86_64.tar" remote_pkg_name = "emc-sdc-package.tar" remote_dir = "/tmp" - remote_file = "EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar" - use_remote_path = false + remote_file = "EMC-ScaleIO-sdc-4.5-3000.118.Ubuntu.22.04.x86_64.tar" + use_remote_path = true + skip_download_sdc = false } powerflex_config = { username = "admin" - endpoint = "https://1.2.3.4:443" - password = "Password" + endpoint = "https://1.2.6.4:443" + password = "Password" } + ``` ## Usage @@ -77,7 +82,6 @@ After successful operation of above commands, to remove deployment, you need to ```bash terraform destroy ``` - ## Requirements @@ -107,8 +111,8 @@ No resources. | [mdm\_ips](#input\_mdm\_ips) | all the mdms (either primary,secondary or virtual ips) in a comma separated list by cluster if unset will use the mdms of the cluster set in the provider block eg. ['10.10.10.5,10.10.10.6', '10.10.10.7,10.10.10.8'] | `list(string)` | `[]` | no | | [powerflex\_config](#input\_powerflex\_config) | Stores the configuration for terraform PowerFlex provider. |
object({
# Define the attributes of the configuration for terraform PowerFlex provider.
username = string
endpoint = string
password = string
})
| n/a | yes | | [remote\_host](#input\_remote\_host) | Stores the SSH credentials for connecting to the remote Linux host. |
object({
# Define the `user` attribute of the `remote` variable.
user = string
# Define the ssh `private_key` file with path for the SDC login user
private_key = optional(string, "")
# Define the ssh `certificate` file path, issued to the SDC login user
certificate = optional(string, "")
password = optional(string)
})
| n/a | yes | -| [scini\_url](#input\_scini\_url) | The URL where the SCINI module package is located. | `string` | n/a | yes | -| [sdc\_pkg](#input\_sdc\_pkg) | configuration for SDC package like url to download package from, copy as local package or directory on remote server. One of local\_dir or remote\_dir will be used based on the variable use\_remote\_path |
object({
# examples "http://example.com/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar", "ftp://username:password@ftpserver/path/to/file"
url = string
pkg_name = string
remote_pkg_name = optional(string)
local_dir = string
remote_dir = optional(string, "/tmp")
# use the SDC package on remote machine path (where SDC is deployed)
use_remote_path = bool
})
| n/a | yes | +| [scini](#input\_scini) | The SCINI module package related variables. |
object({
# The URL where the SCINI module package is located.
url = optional(string)
# specify distro where SDC will be deployed eg. RHEL, Ubuntu, SLES etc. as case sensitive
linux_distro = string
#allow to build scini on destination machine. This may not work on PowerFlex v3.X. Prerequisites here https://www.dell.com/support/kbdoc/en-us/000224134/how-to-on-demand-compilation-of-the-powerflex-sdc-driver
autobuild_scini = optional(bool, false)
})
| n/a | yes | +| [sdc\_pkg](#input\_sdc\_pkg) | configuration for SDC package like url to download package from, copy as local package or directory on remote server. One of local\_dir or remote\_dir will be used based on the variable use\_remote\_path |
object({
# examples "http://example.com/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar", "ftp://username:password@ftpserver/path/to/file"
url = optional(string)
#the name of the SDC package for local.
pkg_name = optional(string)
#the name of the SDC package for remote machine. It should be emc-sdc-package.(tar/rpm)
remote_pkg_name = optional(string)
#local directory where the SDC package will be downloaded.
local_dir = optional(string)
#remote directory where the SDC package will be downloaded. (if use_remote_path is true)
remote_dir = optional(string, "/tmp")
# use the SDC package on remote machine path (where SDC is deployed)
use_remote_path = bool
# if SDC package is available in local directory, download can be skipped by setting to true
skip_download_sdc = optional(bool, false)
})
| n/a | yes | | [versions](#input\_versions) | n/a |
object({
pflex = string
kernel = string
})
| n/a | yes | ## Outputs diff --git a/examples/sdc_host_linux/main.tf b/examples/sdc_host_linux/main.tf index f6e420b..9597d62 100644 --- a/examples/sdc_host_linux/main.tf +++ b/examples/sdc_host_linux/main.tf @@ -27,7 +27,7 @@ module "sdc_host_linux" { versions = var.versions ip = var.ip remote_host = var.remote_host - scini_url = var.scini_url + scini = var.scini sdc_pkg = var.sdc_pkg mdm_ips = var.mdm_ips } diff --git a/examples/sdc_host_linux/variables.tf b/examples/sdc_host_linux/variables.tf index 13bbbb4..5096a0c 100644 --- a/examples/sdc_host_linux/variables.tf +++ b/examples/sdc_host_linux/variables.tf @@ -53,22 +53,37 @@ variable "mdm_ips" { default = [] } -variable "scini_url" { - type = string - description = "The URL where the SCINI module package is located." + +variable "scini" { + + description = "The SCINI module package related variables." + type = object({ + # The URL where the SCINI module package is located. + url = optional(string) + # specify distro where SDC will be deployed eg. RHEL, Ubuntu, SLES etc. as case sensitive + linux_distro = string + #allow to build scini on destination machine. This may not work on PowerFlex v3.X. Prerequisites here https://www.dell.com/support/kbdoc/en-us/000224134/how-to-on-demand-compilation-of-the-powerflex-sdc-driver + autobuild_scini = optional(bool, false) + }) } variable "sdc_pkg" { description = "configuration for SDC package like url to download package from, copy as local package or directory on remote server. One of local_dir or remote_dir will be used based on the variable use_remote_path" type = object({ # examples "http://example.com/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar", "ftp://username:password@ftpserver/path/to/file" - url = string - pkg_name = string + url = optional(string) + #the name of the SDC package for local. + pkg_name = optional(string) + #the name of the SDC package for remote machine. It should be emc-sdc-package.(tar/rpm) remote_pkg_name = optional(string) - local_dir = string + #local directory where the SDC package will be downloaded. + local_dir = optional(string) + #remote directory where the SDC package will be downloaded. (if use_remote_path is true) remote_dir = optional(string, "/tmp") # use the SDC package on remote machine path (where SDC is deployed) use_remote_path = bool + # if SDC package is available in local directory, download can be skipped by setting to true + skip_download_sdc = optional(bool, false) }) } diff --git a/modules/sdc_host_linux/README.md b/modules/sdc_host_linux/README.md index b03f0c4..012bb64 100644 --- a/modules/sdc_host_linux/README.md +++ b/modules/sdc_host_linux/README.md @@ -19,27 +19,6 @@ limitations under the License. This Terraform module installs the SDC package on a remote Linux host using the `powerflex_sdc_host` resource. -## Variables - -| Variable Name | Description | -|---------------|-------------| -| `ip` | Stores the IP address of the remote Linux host. | -| `remote_host` | Stores the SSH credentials for connecting to the remote Linux host. | -| `remote_host.user` | Stores the username for connecting to the remote Linux host. root will have all required privileges.| -| `remote_host.private_key` | Stores the SSH private key for connecting to the remote Linux host. | -| `remote_host.certificate` | Stores the SSH certificate for connecting to the remote Linux host. | -| `remote_host.password` | Stores the password for connecting to the remote Linux host. | -| `sdc_pkg` | Stores the SDC package information. | -| `sdc_pkg.url` | Stores the URL to download the SDC package from. eg. "http://example.com/path/to/file", "ftp://username:password@ftpserver/path/to/file"| -| `sdc_pkg.pkg_name` | Stores the name of the SDC package for local. | -| `sdc_pkg.remote_pkg_name` | Stores the name of the SDC package for remote machine. It should be emc-sdc-package.(tar/rpm)| -| `sdc_pkg.local_dir` | Stores the local directory where the SDC package will be downloaded. | -| `sdc_pkg.remote_dir` | Stores the remote directory where the SDC package will be downloaded. Dir should be present. | -| `sdc_pkg.use_remote_path` | Stores the flag to use the SDC package on a remote machine path or not. | -| `versions` | Stores the kernel and PowerFlex versions. | -| `scini_url` | The URL where the SCINI module package is located. | - - ### Prerequisites SDC Host module can only be used with terraform provider PowerFlex v1.6.0 and above. @@ -57,7 +36,7 @@ module "sdc_host" { versions = var.versions ip = var.ip remote_host = var.remote_host - scini_url = var.scini_url + scini = var.scini sdc_pkg = var.sdc_pkg } ``` @@ -69,7 +48,6 @@ After providing proper values to all the attributes eg. using terraform.tfvars, terraform init terraform apply ``` - ## Requirements @@ -97,6 +75,7 @@ No modules. | powerflex_sdc_host.sdc_remote_path | resource | | [terraform_data.compare_version](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | | [terraform_data.linux_scini](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | +| [terraform_data.linux_scini_auto](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | | [terraform_data.sdc_pkg_local](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | | [terraform_data.sdc_pkg_remote](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource | | [local_sensitive_file.ssh_cert](https://registry.terraform.io/providers/hashicorp/local/latest/docs/data-sources/sensitive_file) | data source | @@ -109,8 +88,8 @@ No modules. | [ip](#input\_ip) | Stores the IP address of the remote Linux host. | `string` | n/a | yes | | [mdm\_ips](#input\_mdm\_ips) | all the mdms (either primary,secondary or virtual ips) in a comma separated list by cluster if unset will use the mdms of the cluster set in the provider block eg. ['10.10.10.5,10.10.10.6', '10.10.10.7,10.10.10.8'] | `list(string)` | n/a | yes | | [remote\_host](#input\_remote\_host) | Stores the SSH credentials for connecting to the remote Linux host. |
object({
# Define the `user` attribute of the `remote` variable.
user = string
# Define the ssh `private_key` file with path for the SDC login user
private_key = optional(string, "")
# Define the ssh `certificate` file path, issued to the SDC login user
certificate = optional(string, "")
password = optional(string)
})
| n/a | yes | -| [scini\_url](#input\_scini\_url) | The URL where the SCINI module package is located. | `string` | n/a | yes | -| [sdc\_pkg](#input\_sdc\_pkg) | configuration for SDC package like url to download package from, copy as local package or directory on remote server. One of local\_dir or remote\_dir will be used based on the variable use\_remote\_path |
object({
# examples "http://example.com/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar", "ftp://username:password@ftpserver/path/to/file"
url = string
pkg_name = string
remote_pkg_name = optional(string)
local_dir = string
remote_dir = optional(string, "/tmp")
# use the SDC package on remote machine path (where SDC is deployed)
use_remote_path = bool
})
| n/a | yes | +| [scini](#input\_scini) | The SCINI module package related variables. |
object({
# The URL where the SCINI module package is located.
url = optional(string)
# specify distro where SDC will be deployed eg. RHEL, Ubuntu, SLES etc. as case sensitive
linux_distro = string
#allow to build scini on destination machine. This may not work on PowerFlex v3.X. Prerequisites here https://www.dell.com/support/kbdoc/en-us/000224134/how-to-on-demand-compilation-of-the-powerflex-sdc-driver
autobuild_scini = optional(bool, false)
})
| n/a | yes | +| [sdc\_pkg](#input\_sdc\_pkg) | configuration for SDC package like url to download package from, copy as local package or directory on remote server. One of local\_dir or remote\_dir will be used based on the variable use\_remote\_path |
object({
# examples "http://example.com/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar", "ftp://username:password@ftpserver/path/to/file"
url = optional(string)
#the name of the SDC package for local.
pkg_name = optional(string)
#the name of the SDC package for remote machine. It should be emc-sdc-package.(tar/rpm)
remote_pkg_name = optional(string)
#local directory where the SDC package will be downloaded.
local_dir = optional(string)
#remote directory where the SDC package will be downloaded. (if use_remote_path is true)
remote_dir = optional(string, "/tmp")
# use the SDC package on remote machine path (where SDC is deployed)
use_remote_path = bool
# if SDC package is available in local directory, download can be skipped by setting to true
skip_download_sdc = optional(bool, false)
})
| n/a | yes | | [versions](#input\_versions) | n/a |
object({
pflex = string
kernel = string
})
| n/a | yes | ## Outputs diff --git a/modules/sdc_host_linux/main.tf b/modules/sdc_host_linux/main.tf index b995463..4e28c47 100644 --- a/modules/sdc_host_linux/main.tf +++ b/modules/sdc_host_linux/main.tf @@ -33,11 +33,11 @@ locals { locals { use_remote_path = var.sdc_pkg.use_remote_path - share_url_scini = var.scini_url + share_url_scini = var.scini.url } resource terraform_data sdc_pkg_local { #do if use_remote_path is false. - count = var.sdc_pkg.use_remote_path ? 0: 1 + count = ( var.sdc_pkg.use_remote_path && !var.sdc_pkg.skip_download_sdc) ? 0: 1 input = var.sdc_pkg #One option is to download sdc on local drive and provide local path provisioner "local-exec" { @@ -113,7 +113,7 @@ resource "terraform_data" "compare_version" { #copy SDC package on remote server resource terraform_data sdc_pkg_remote { # perform if variable is true - count = local.use_remote_path ? 1 : 0 + count = ( local.use_remote_path && !var.sdc_pkg.skip_download_sdc) ? 1: 0 connection { type = "ssh" user = self.output.user.name @@ -154,6 +154,7 @@ resource terraform_data sdc_pkg_remote { # # STEP 3 - install pre-requisites (scini module) # # provisioner to install scini module on SDC resource "terraform_data" "linux_scini" { + count = ( var.scini.linux_distro == "RHEL" || var.scini.autobuild_scini) ? 0 : 1 connection { type = "ssh" user = self.output.user.name @@ -175,7 +176,7 @@ resource "terraform_data" "linux_scini" { password = var.remote_host.password } ip = var.ip - scini_url = var.scini_url + scini_url = var.scini.url } provisioner "remote-exec" { @@ -192,12 +193,51 @@ resource "terraform_data" "linux_scini" { } } +# # provisioner to install scini module on SDC +resource "terraform_data" "linux_scini_auto" { + # Execute when autobuild flag is set and if it is not RHEL + count = ( var.scini.linux_distro != "RHEL" && var.scini.autobuild_scini) ? 1 : 0 + connection { + type = "ssh" + user = self.output.user.name + private_key = self.output.user.private_key + certificate = self.output.user.certificate + host = self.output.ip + password = self.output.user.password + } + input = { + user = { + name = var.remote_host.user + #user can use keys or userid/password. Make sure to copy the keys to remote server before using keys + private_key = var.remote_host.private_key == "" ? "" : data.local_sensitive_file.ssh_key[0].content + certificate = var.remote_host.certificate == "" ? "" : data.local_sensitive_file.ssh_cert[0].content + password = var.remote_host.password + } + ip = var.ip + } + + provisioner "remote-exec" { + inline = [ + "mkdir -p /etc/emc/scaleio/scini_sync", + "touch /etc/emc/scaleio/scini_sync/.build_scini", + ] + } + provisioner "remote-exec" { + when = destroy + inline = [ + "rm /etc/emc/scaleio/scini_sync/.build_scini" + ] + } +} + + # # STEP 4 - Install actual SDC # # SDC configuration resource powerflex_sdc_host sdc_local_path { count = local.use_remote_path ? 0 : 1 #deploy if variable is false - depends_on = [ terraform_data.linux_scini ] + depends_on = [ terraform_data.compare_version, + terraform_data.linux_scini] ip = var.ip remote = { user = var.remote_host.user @@ -215,7 +255,8 @@ resource "terraform_data" "linux_scini" { resource powerflex_sdc_host sdc_remote_path { count = local.use_remote_path ? 1 : 0 #deploy if variable is true - depends_on = [ terraform_data.linux_scini ] + depends_on = [ terraform_data.compare_version, + terraform_data.linux_scini] ip = var.ip remote = { user = var.remote_host.user diff --git a/modules/sdc_host_linux/variables.tf b/modules/sdc_host_linux/variables.tf index 57ad2c5..3a1883e 100644 --- a/modules/sdc_host_linux/variables.tf +++ b/modules/sdc_host_linux/variables.tf @@ -43,22 +43,36 @@ variable "mdm_ips" { } -variable "scini_url" { - type = string - description = "The URL where the SCINI module package is located." +variable "scini" { + + description = "The SCINI module package related variables." + type = object({ + # The URL where the SCINI module package is located. + url = optional(string) + # specify distro where SDC will be deployed eg. RHEL, Ubuntu, SLES etc. as case sensitive + linux_distro = string + #allow to build scini on destination machine. This may not work on PowerFlex v3.X. Prerequisites here https://www.dell.com/support/kbdoc/en-us/000224134/how-to-on-demand-compilation-of-the-powerflex-sdc-driver + autobuild_scini = optional(bool, false) + }) } variable "sdc_pkg" { description = "configuration for SDC package like url to download package from, copy as local package or directory on remote server. One of local_dir or remote_dir will be used based on the variable use_remote_path" type = object({ # examples "http://example.com/EMC-ScaleIO-sdc-3.6-700.103.Ubuntu.22.04.x86_64.tar", "ftp://username:password@ftpserver/path/to/file" - url = string - pkg_name = string + url = optional(string) + #the name of the SDC package for local. + pkg_name = optional(string) + #the name of the SDC package for remote machine. It should be emc-sdc-package.(tar/rpm) remote_pkg_name = optional(string) - local_dir = string + #local directory where the SDC package will be downloaded. + local_dir = optional(string) + #remote directory where the SDC package will be downloaded. (if use_remote_path is true) remote_dir = optional(string, "/tmp") # use the SDC package on remote machine path (where SDC is deployed) use_remote_path = bool + # if SDC package is available in local directory, download can be skipped by setting to true + skip_download_sdc = optional(bool, false) }) }