Pearl1594 opened a new pull request, #256:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/256

   Support for:
   - Userdata
   - Linking User data to a template
   - Passing parameters values for the userdata linked to the template
   
   Example config:
   
   ```
   terraform {
     required_providers {
       cloudstack = {
         source = "hashicorp.com/dev/cloudstack"
       }
     }
   }
   
   provider "cloudstack" {
     api_url    = "http://xx.xx.xx.xx:8080/client/api";
     api_key    = 
"LIN6rqXuaJwMPfGYFh13qDwYz5VNNz1J2J6qIOWcd3oLQOq0WtD4CwRundBL6rzXToa3lQOC_vKjI3nkHtiD8Q"
     secret_key = 
"R6QPwRUz09TVXBjXNwZk7grTjcPtsFRphH6xhN1oPvnc12YUk296t4KHytg8zRLczDA0X5NsLVi4d8rfMMx3yg"
     timeout    = 1800 
   }
   
   
   resource "cloudstack_userdata" "simple_web" {
     name = "simple-web-userdata"
     
     userdata = base64encode(<<-EOF
       #!/bin/bash
       apt-get update
       apt-get install -y nginx
       
       # Use parameters from userdata_details
       echo "<h1>Hello from $${app_name}!</h1>" > /var/www/html/index.html
       echo "<p>Environment: $${environment}</p>" >> /var/www/html/index.html
       echo "<p>Debug Mode: $${debug_mode}</p>" >> /var/www/html/index.html
       
       systemctl enable nginx
       systemctl start nginx
     EOF
     )
     params = ["app_name", "environment", "debug_mode"]
   }
   
   resource "cloudstack_template" "web_template" {
     name         = "simple-web-template-1"
     display_text = "Simple Web Server Template"
     format       = "QCOW2"
     hypervisor   = "KVM"
     os_type      = "Ubuntu 20.04"
     url          = "http://<template_url>"
     zone         = "ref-trl-9797-k-Mol8-pearl-dsilva"
     is_public        = false
     is_extractable   = true
     password_enabled = true
     is_ready_timeout = 1800
     
     # Link userdata to template
     userdata_link {
       userdata_id     = cloudstack_userdata.simple_web.id
       userdata_policy = "ALLOWOVERRIDE"  # Allow users to override userdata
     }
     
     tags = {
       Purpose = "demo"
     }
   }
   
   resource "cloudstack_instance" "web_server" {
     name            = "demo-web-server"
     display_name    = "Demo Web Server"
     template        = cloudstack_template.web_template.id
     service_offering = "CKSMinimum"
     network_id      = "09acfb00-fe9b-423d-b993-468dfe69776e"
     zone            = "ref-trl-9797-k-Mol8-pearl-dsilva"
     
     # Use the linked userdata from template
     userdata_id = cloudstack_userdata.simple_web.id
     
     # Pass parameters to the userdata script
     userdata_details = {
       "app_name"    = "My Demo App"
       "environment" = "production"
       "debug_mode"  = "false"
     }
     
     tags = {
       Environment = "demo"
       Purpose     = "web-server"
     }
   }
   
   output "userdata_info" {
     description = "Userdata information"
     value = {
       id   = cloudstack_userdata.simple_web.id
       name = cloudstack_userdata.simple_web.name
     }
   }
   
   output "template_info" {
     description = "Template information"
     value = {
       id            = cloudstack_template.web_template.id
       name          = cloudstack_template.web_template.name
       userdata_name = 
cloudstack_template.web_template.userdata_link[0].userdata_name
     }
   }
   
   output "instance_info" {
     description = "Instance information"
     value = {
       id         = cloudstack_instance.web_server.id
       name       = cloudstack_instance.web_server.name
       ip_address = cloudstack_instance.web_server.ip_address
     }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to