nutanix / terraform-provider-nutanix

Terraform Nutanix Provider
https://www.terraform.io/docs/providers/nutanix/
Mozilla Public License 2.0
100 stars 112 forks source link

Upload images to Foundation VM from a remote server using nutanix_foundation_image resource #455

Closed bhati-pradeep closed 2 years ago

bhati-pradeep commented 2 years ago

Is your feature request related to a problem? Please describe. Current nutanix_foundation_image resource uploads file from local setup to the foundation VM. New feature can be a way to upload image to foundation vm using remote server/ filer URL using same resource. This would reduce dependency on local setup for running terraform automation.

glover-chris commented 2 years ago

Thanks for opening the issue. I think you have the requirements stated fine.

bhati-pradeep commented 2 years ago

Discussed with team and this operation can be done by terraform builtin resources itself. For foundation image upload resource, the file needs to be there in the local workstation. So in order to download file from remote server first we can use below code snippet. This will download file from remote server at a certain directory.


resource "null_resource" "download_image" {
    triggers = {
        temp_var = "${timestamp()}"
    }
    provisioner "local-exec" {
        command = "wget <remote-server-file-link>"
        working_dir = "/User/pradeep.bhati/Downloads/images/"
    }
}

In code, triggers always make sure the resource is run everytime there is terraform apply. working_dir is used to run this command in the particulary directory.

Reference: https://www.terraform.io/language/resources/provisioners/local-exec