Add Terraform Orchestration interface on a resource block
After you have activated the Terraform store app for Cloud Provisioning and Governance, to support cloud-based operations for cloud providers using Terraform Open Source Edition. Add the Terraform Orchestration interface on resource block, to execute cloud-based operations via terraform templates.
Avant de commencer
Procédure
- On the Cloud Admin portal, navigate to Design > Resource Block.
- Click the resource block, for example Azure Datacenter.
- Move the state of the resource block from Published to Draft to make it editable.
- Navigate to General Information > Guest Interface, and then click New.
- Search for and select the Terraform Orchestration Interface from the Guest Interface list, and click Submit.
- Click the Operations tab.
- In the Input Parameterstab, navigate to Interface and select Terraform Orchestration Interface
-
On the Input Parameters tab, configure the CAPI
operation inputs.
On the CAPI interface, which in this case is Terraform Orchestration Interface, open CreateStack method. The inputs from CAPI display on the Input tab, where you create parameters.
The Input Parameters tab is where users enter values. You can map those input parameters to the parameters on the Input tab. To do this, copy the Mapping value from the Input Parameters tab into the Value field on the Steps > Input tab.
If this step is invoking a script, and that script requires arguments to return values, you can add a new input parameter for each argument. Use this syntax in the Value field: ${parameter.arg1}.
- Click the Steps sub-tab under Operations.
- Click Add Step.
-
Fill in the form fields.
Field Description Operation Type Select the type of operation.
Invoke Cloud API: Select this option to select a provider, interface, and method from CAPI.
API Provider Select the API that provides the interfaces you need. The providers are part of the Cloud API (CAPI).
For example, CAPI supplies the Terraform OpenSourceprovider, which provides the Configuration Orchestration Interface.
This value appears if you select the Invoke Cloud API operation type.
API Interface Select the interface that has the methods you want to use. For this example, the Configuration Orchestration Interface provides multiple interfaces or methods, which the system uses during provisioning. API Method Select the method to perform the operation. In this example, ExecuteCommand is required to provision terraform templates. CAPI Version Enter the version of the CAPI API. Condition Enter an optional condition that must be met before the system uses this step. -
Click Submit.
The Input and Response Processor tabs appear for the step.
-
On the Input tab, configure the CAPI operation
inputs.
On the CAPI interface, which in this case is Configuration Orchestration Interface, open ExecuteCommand method. The inputs from CAPI show on the Input tab, where you create parameters.
Remember that the parameters on the Input Parameters tab is where users enter values. You can map those input parameters to the parameters on the Input tab. Copy the Mapping value from the Input Parameters tab into the Value field on the Steps > Input tab.
If this step is invoking a script, and that script requires arguments to return values, you can add a new input parameter for each argument. Use this syntax in the Value field: ${parameter.arg1}.
Remarque :Map the values as mentioned in the following table for the following parameters:Parameter Value AdditionalParameters Enter the following script: {"ServerType":"$(Script:sn_cmp_terraform.TerraformCommandUtils. getConfigProviderServerTypeByName[arg=${parameter.WorkloadConfigProvider}])"}ConfigMgmtProviderInfo $(capiResolver.NodeCredentialResolver#nodeCredentialId=$(ci.sn_cmp_wl_cfg_mgmt_provider [name=${parameter.WorkloadConfigProvider}].credential))Node Address $(ci.cmdb_ci_workload_config_provider[name=${parameter.WorkloadConfigProvider}].url)Script For CreateStack operation
${CloudScript.scripts.TerraformDeploy}Script For DeleteStack operation
${CloudScript.scripts.DestroyTerraform} -
On the Response Processor tab, configure the response
processors by attaching resource scripts.
You would have added Resource Scripts to the resource block, while creating the Resource Block.
- From the Operation list, select the CreateStack or DeleteStack operation.
-
Click the add icon
for Add Response Processor.
- Click the Resource Script sub tab, and then click New.
-
Complete the form.
Tableau 1. New Record Field Description Name Enter a name (For example, Create_AzureTF_Stack_Response_Processor) for the resource script. Type Select a type (Response Processor) for the script. Script Resource Script for Create
Enter the following script: function processResponse (response, cloudServiceAccountId, ldc, correlationId, step, requestorContext, stackId) { var responseObject = global.JSON.parse(response); var tfState = global.JSON.parse(responseObject.terraform.state); var processor = new sn_cmp_terraform.TerraformResponseProcessor(); var processedResponses = processor.processResponse(tfState, cloudServiceAccountId, ldc, correlationId, step, requestorContext, stackId); return global.JSON.stringify(processedResponses); }Script Resource Script for Delete
Enter the following script: function processResponse (response, cloudServiceAccountId, ldc, correlationId, step, requestorContext, stackId) { var responseObject = global.JSON.parse(response); var tfState = global.JSON.parse(responseObject.terraform.state); var processor = new sn_cmp_terraform.TerraformResponseProcessor(); var processedResponses = processor.processResponse(tfState, cloudServiceAccountId, ldc, correlationId, step, requestorContext, stackId); return global.JSON.stringify(processedResponses); } - From the Script Name list, select the script corresponding to the selected operation, and click Submit.
-
Move the state of the resource block from Draft to
Published.
The datacenter resource block moves from the draft to the published state and you cannot make further changes to the resource block. You can only modify a resource block after you set the status to Draft.