Install and use the template test tool

更新时间:
复制 MD 格式

This topic explains how to install, configure, and use Iact3 (Infrastructure as Code Template Test Tool) to test your Alibaba Cloud Resource Orchestration Service (ROS) and Terraform templates.

Why use Iact3?

After you write a ROS or Terraform template, use Iact3 to verify that a stack can be created from it. This process tests whether the system can create or update the resources defined in your template, such as an instance group, a virtual private cloud (VPC), or a security group.

Prerequisites

  • Iact3 is developed in Python. Ensure that you have Python 3.7 or later installed. For more information, see the official Python website.

  • You have a template ready for testing.

Install Iact3

Install with pip

Run the following command to install Iact3.

pip install alibabacloud-ros-iact3

Install from source

  1. Download the Iact3 source code.

    git clone https://github.com/aliyun/alibabacloud-ros-tool-iact3.git
  2. Navigate to the alibabacloud-ros-tool-iact3 directory.

    cd alibabacloud-ros-tool-iact3
  3. Install Iact3.

    python setup.py install

Configure identity credentials

Alibaba Cloud CLI

If you have installed Alibaba Cloud CLI, Iact3 can use its configuration file directly. The default path for this file is ~/.aliyun/config.json. For example:

{
    "current": "default",
    "profiles":
    [
        {
            "name": "default",
            "mode": "AK",
            "access_key_id": "***",
            "access_key_secret": "***",
        },
    ],
    "meta_path": ""
}

Alibaba Cloud SDK

Iact3 can use the configuration file for Alibaba Cloud SDK credentials. The default path is ~/.alibabacloud/credentials.ini or ~/.aliyun/credentials.ini. You can also specify a custom path by using the ALIBABA_CLOUD_CREDENTIALS_FILE environment variable. For example:

[default]
enable=true
type=access_key
access_key_id=<ALIBABA_CLOUD_ACCESS_KEY_ID>
access_key_secret=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>

[client1]
enable=true
type=ecs_ram_role
role_name=<ecs_ram_role_name>

[client2]
enable=true
type=ram_role_arn
policy=<policy>
access_key_id=<ALIBABA_CLOUD_ACCESS_KEY_ID>
access_key_secret=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>
role_arn=<ram_role_arn>
role_session_name=<role_session_name>

[client3]
enable=true
type=oidc_role_arn
policy=<policy>
oidc_provider_arn=<ALIBABA_CLOUD_ACCESS_KEY_ID>
oidc_token_file_path=<ALIBABA_CLOUD_ACCESS_KEY_SECRET>
role_arn=<ram_role_arn>
role_session_name=<role_session_name>

Environment variables

To configure your credentials, set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

Prepare a configuration file

Iact3 uses a YAML configuration file to specify the template and parameters for your test:

project:
  name: my-first-test
  template_config: 
    template_url: 'https://xxx/create-ecs.yaml'
  regions:
    - cn-hangzhou
    - cn-beijing
tests:
  test-name-1:
    parameters:
      ZoneId: $[iact3-auto]
      InstanceType: ecs.g6e.large
  test-name-2:
    parameters:
      ZoneId: $[iact3-auto]
      InstanceType: ecs.c6.large

Parameters

  • project: Defines the basic information for the project. This parameter includes the following fields:

    • name: Specifies the name of the configuration.

    • Specifies the URL of the template to test in the template_url field.

    • regions: Specifies a list of regions where the test will run.

  • tests: Defines the test cases. In this example, the configuration file contains two test cases named test-name-1 and test-name-2.

    • parameters: Specifies the parameter values for the template. The value $[iact3-auto] indicates that Iact3 will automatically generate a suitable value for the parameter.

      Note

      Automatic parameter generation is supported only in the following two scenarios:

      • The resource attributes for the parameter are supported by the ROS GetTemplateParameterConstraints API operation. For more information, see Query parameter constraints.

      • The parameter name has a conventional meaning. For example, VpcId typically represents the ID of a virtual private cloud. When $[iact3-auto] is used, Iact3 automatically selects a random VPC instance ID from the current account in the specified region.

For details about the configuration file, see the Iact3 configuration documentation.

Test the template

  1. Navigate to the directory that contains your configuration file and run the following command to start the test.

    iact3 test run
  2. Iact3 creates a stack based on the template and parameters defined in your configuration file. After the test is complete, Iact3 automatically deletes the stack.

    image

  3. After the test is complete, Iact3 automatically generates a test report.

    image

  4. Click View Logs to view the detailed logs for each report.

    The logs show resource creation and status updates from the cloud service.

    image

More features

Iact3 offers several other features. Run the iact3 -h command to view the help information and learn about all supported commands and features.

Cost estimation

Iact3 can estimate the cost of the resources defined in a template. Run the following command to get a cost estimate.

iact3 cost

Resource preview

Iact3 can preview the resources that will be created from a template. Run the following command to preview the resources.

iact3 preview

Policy query

Iact3 can determine the permissions required to create a stack from a template. Run the following command to query the necessary permissions for a RAM user.

iact3 policy

References