Using scripts in a manifestBeta
Scripts allow performing various operations during service deployment, for example, synchronizing nodes when combining them into a cluster.
There are two ways to use scripts:
- via the cloud-init package;
- via the Marketplace agent.
Cloud-init allows configuring the order in which scripts are executed and specifying the moment of their launch on a single server. For example, a script can be executed at every OS boot or only once.
- An error during script execution will stop the instance deployment. This means that not all the required settings will be applied.
- It is impossible to set a dependency between the script execution and the operation of other Terraform resources: the script may still be running, but the Marketplace will already indicate that the instance deployment is complete.
- (Optional) Description of the script contents in input variables. Bash and Python languages are supported.
- Description of the script execution order and settings in the
user_scriptargument of the ivkcs_user_data resource. - Description of the script contents in the
ivkcs_user_dataresource directly or using variables.
The VK CS Infra (iVK CS) provider reference provides an example of describing scripts in the ivkcs_user_data resource of a Terraform manifest.
The Marketplace agent allows setting the dependency of script execution relative to the operation of other Terraform resources, setting a timeout, monitoring exit codes, and stopping the application deployment on errors.
During service deployment, the agent transmits the hash of the executed scripts to the configuration management service. This makes it possible to assess the current state of the VM with the service instance (which scripts have been executed at the current moment) and bring it to the state described in the Terraform manifest.
The Marketplace agent transmits the script status to the configuration management service. Possible statuses:
-
ok— the script completed successfully. -
running— the script is being executed. -
failed— the script completed with an error. The cause of the error can be determined by viewing the agent logs.Upon receiving the
failedstatus, the deployment system restarts the service deployment process. Retries can take up to an hour and a half. They can be disabled in the settings.yaml file.
The script execution results can be transmitted to the configuration management service in a formatted form and used when executing other scripts.
- Installation of the Marketplace agent is required.
- It is impossible to restart scripts on OS reboot.
-
Description of the Marketplace agent installation on the instance VM. For more details, see the VK CS Infra (iVK CS) provider reference.
-
(Optional) Description of the script contents in input variables. Bash and Python languages are supported.
-
Description of the script execution order and settings using the ivkcs_agent_exec resource or a
localsblock.For example, using the
ivkcs_agent_execresource, you can set a execution timeout and the number of script execution attempts before it is assigned thefailedstatus for each script. -
Description of the script contents in the
ivkcs_user_dataresource directly or using variables. -
(Optional) Retrieving the script execution results using the
ivkcs_agent_script_resultdata source. The script execution results can be transmitted in output parameters or used in other Terraform manifest resources.
The section Terraform manifest provides an example of a manifest using scripts in the ivkcs_agent_exec resource.