Scripting
Create the Scripting Resource in Terraform to execute Scripts
3 minute read
To learn more about the Scripting module in OneFuse, refer to Scripting.
Prerequisites
- Configure the OneFuse Provider
- Review an overview on OneFuse Modules with Terraform
Steps
- Create
variables.tffile - Create
main.tffile - Run terraform commands to deploy a OneFuse Scripting Deployment and run the Provision Script:
terraform initterraform planterraform apply
- Run terraform command to destroy the OneFuse Scripting Deployment and run the Deprovision Script:
terraform destroy
Create variables.tf
Add the following in the variables.tf file. Update the values as needed.
It is a best practice to separate configurations into identifiable files, refer to Best practices for OneFuse modules.
The sample below shows all configurations in one variables.tf file for simplicity.
// SAMPLE VARIABLES.TF FILE CONFIGURATIONS
variable "onefuse_scheme" {
type = string
default = "https"
}
variable "onefuse_address" {
type = string
}
variable "onefuse_port" {
type = string
default = "443"
}
variable "onefuse_user" {
type = string
default = "admin"
}
variable "onefuse_password" {
type = string
default = "admin"
}
variable "onefuse_verify_ssl" {
type = bool
default = false
}
variable "workspace_url" {
type = string
default = "" // Default
}
variable "template_properties" {
type = map
default = {
"Environment" = "d" //p for production or d for development
"Location" = "w" //e for East or w for West
"Application" = "wp" //wp for wordpress or iis for IIS
"OS" = "l" //l for Linux or w for Windows
}
}
Create main.tf for Scripting resource
Add the following in the main.tf file. Update the values as needed.
Parameter references
The following defines the function of each Scripting specific parameter.
| Parameter Name | Required? | Notes |
|---|---|---|
policy_id |
Required | OneFuse Module Policy ID (integer). |
workspace_url |
Optional | OneFuse Workspace URL path. Use "" for the default workspace. |
template_properties |
Optional | Additional properties that are referenced within the Policy. |
Scripting specific parameters:
| Parameter Name | Required? | Notes |
|---|---|---|
timeouts |
Optional | Timeout (in minutes) for create and/or delete operations. See the example below the table. |
timeouts {
create = "20m"
delete = "20m"
}
Sample main.tf
// Terraform OneFuse Provider
terraform {
required_providers {
onefuse = {
source = "CloudBoltSoftware/onefuse"
version = ">= 1.50.2"
}
}
required_version = ">= 0.13"
}
// Inititalize OneFuse Provider
provider "onefuse" {
scheme = var.onefuse_scheme
address = var.onefuse_address
port = var.onefuse_port
user = var.onefuse_user
password = var.onefuse_password
verify_ssl = var.onefuse_verify_ssl
}
// Data Source for Scripting Policy - lookup Policy ID by Policy Name
data "onefuse_scripting_policy" "scripting_policy" {
name = "my_policy_name" // Replace with Policy Name
}
// Resource for Scripting
resource "onefuse_scripting_deployment" "script" {
policy_id = data.onefuse_scripting_policy.scripting_policy.id // Refers to Data Source to get Policy ID
workspace_url = ""
template_properties = var.template_properties
timeouts {
create = "20m"
delete = "20m"
}
}
// Outputs for Resource
output "script_output" {
value = jsondecode(onefuse_scripting_deployment.script.provisioning_details)
}
OneFuse module: Scripting import
Create main.tf for script resource import
Add the following in the main.tf file.
The following parameter is required to import a Scripting object.
Parameter references:
| Parameter Name | Required? | Notes |
|---|---|---|
policy_id |
Required | OneFuse Module Policy ID (integer). |
Sample main.tf
// Terraform OneFuse Provider
terraform {
required_providers {
onefuse = {
source = "CloudBoltSoftware/onefuse"
version = ">= 1.50.2"
}
}
required_version = ">= 0.13"
}
// Inititalize OneFuse Provider
// Create the separate variables.tf file or hard code the values.
provider "onefuse" {
scheme = var.onefuse_scheme
address = var.onefuse_address
port = var.onefuse_port
user = var.onefuse_user
password = var.onefuse_password
verify_ssl = var.onefuse_verify_ssl
}
resource "onefuse_scripting_deployment" "my_scripting_deployment" {
policy_id = 1
}
Run the following command to import the OneFuse Scripting resource:
terraform import <resource_type>.<resource_name> <resource_id>
terraform import onefuse_scripting_deployment.my_scripting_deployment 2