All Products
Search
Document Center

Managed Service for Prometheus:Use Terraform to manage environment instances

Last Updated:Aug 24, 2026

Terraform is an open source tool from HashiCorp that lets you preview, configure, and manage cloud infrastructure and resources. With Terraform, you can automatically create and update Alibaba Cloud infrastructure resources, and keep those resources under version management. Use Terraform to create the environment instances that connect your cloud resources to Application Real-Time Monitoring Service (ARMS), so that you can monitor the performance metrics of the resources in real time.

Prerequisites

  • Terraform v0.12.28 or later is installed. Run terraform --version to check the installed version. Install Terraform in one of the following ways:

  • Resource Orchestration Service provides managed Terraform capabilities, allowing you to create Terraform templates, define resources on Alibaba Cloud, AWS, or Azure, and configure resource parameters and dependencies. For more information, see Create a Terraform template and Create a Terraform stack.

  • Your Alibaba Cloud account information is configured. Provide the identity credentials in one of the following ways:

    • Environment variables — Add environment variables to store the identity credentials:

      export ALICLOUD_ACCESS_KEY="************"
      export ALICLOUD_SECRET_KEY="************"
      export ALICLOUD_REGION="cn-beijing"
    • Configuration file — Specify the identity credentials in the provider block of the configuration file:

      provider "alicloud" {
        access_key = "************"
        secret_key = "************"
        region     = "cn-beijing"
      }
    Note

    To improve the flexibility and security of permission management, create a Resource Access Management (RAM) user named Terraform, create an AccessKey for the RAM user, and grant permissions to the RAM user. For instructions, see Create a RAM user and Manage permissions for a RAM user.

  • Managed Service for Prometheus is activated.

Create an environment instance

ARMS supports environment instances for Container Service, ECS, and cloud services. The three environment types share the same Terraform workflow and differ only in the alicloud_arms_environment resource that you declare in the main.tf configuration file:

Environment type

environment_type

environment_sub_type

bind_resource_id

Container Service

CS

ACK

The cluster ID of Container Service

ECS

ECS

ECS

The VPC ID, for example, vpc-bp1jxxx

Cloud service

Cloud

Cloud

The region ID of the cloud service instance, for example, cn-hangzhou

Identify the environment type that matches the cloud resources you want to monitor, and then follow the steps in the corresponding section.

Container Service environment instance

  1. Create a working directory and a configuration file named main.tf in it:

    # provider, use alicloud
    provider "alicloud" {
      # access_key = "************"
      # secret_key = "************"
      # region = "cn-beijing"
    }
    
    # The environment instance of Container Service.
    resource "alicloud_arms_environment" "my_ack-env1" {
      environment_name     = "Container Service environment name 1"
      environment_type     = "CS"
      environment_sub_type = "ACK"
      bind_resource_id     = "The cluster ID of Container Service"
    }

    access_key, secret_key, and region fields commented out.

  2. Initialize the Terraform runtime environment:

    terraform init
    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.90.1...
    ...
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Preview the resources that Terraform plans to create:

    terraform plan
    Refreshing Terraform state in-memory prior to plan...
    The refreshed state will be used to calculate this plan, but will not be
    persisted to local or remote state storage.
    ...
    Plan: 5 to add, 0 to change, 0 to destroy.
    ...
  4. Create the Container Service environment instance:

    terraform apply

    Enter a value, enter yes. The following output is returned:

    ...
    Do you want to perform these actions?
     Terraform will perform the actions described above.
     Only 'yes' will be accepted to approve.
    
     Enter a value: yes
    ...
    alicloud_arms_environment: Creation complete after 8m26s [id=************]
    
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  5. Log on to the ARMS console. On the Integration Management page, verify that the Container Service environment instance appears in the environment list.

ECS environment instance

  1. Create a working directory and a configuration file named main.tf in it:

    # provider, use alicloud
    provider "alicloud" {
      # access_key = "************"
      # secret_key = "************"
      # region = "cn-beijing"
    }
    
    # The ECS environment instance.
    resource "alicloud_arms_environment" "my_ecs-env1" {
      environment_name     = "ECS environment name 1"
      environment_type     = "ECS"
      environment_sub_type = "ECS"
      bind_resource_id     = "The vpcId, for example, vpc-bp1jxxx"
    }

    access_key, secret_key, and region fields commented out.

  2. Initialize the Terraform runtime environment:

    terraform init
    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.90.1...
    ...
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Preview the resources that Terraform plans to create:

    terraform plan
    Refreshing Terraform state in-memory prior to plan...
    The refreshed state will be used to calculate this plan, but will not be
    persisted to local or remote state storage.
    ...
    Plan: 5 to add, 0 to change, 0 to destroy.
    ...
  4. Create the ECS environment instance:

    terraform apply

    Enter a value, enter yes. The following output is returned:

    ...
    Do you want to perform these actions?
     Terraform will perform the actions described above.
     Only 'yes' will be accepted to approve.
    
     Enter a value: yes
    ...
    alicloud_arms_environment: Creation complete after 8m26s [id=************]
    
    Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
  5. Log on to the ARMS console. On the Integration Management page, verify that the ECS environment instance appears in the environment list.

Cloud service environment instance

  1. Create a working directory and a configuration file named main.tf in it:

    # provider, use alicloud
    provider "alicloud" {
      # access_key = "************"
      # secret_key = "************"
      # region = "cn-beijing"
    }
    
    # The cloud service environment instance.
    resource "alicloud_arms_environment" "my_cloud-env1" {
      environment_name     = "Cloud service environment name 1"
      environment_type     = "Cloud"
      environment_sub_type = "Cloud"
      bind_resource_id     = "The regionId of the cloud service instance, for example, cn-hangzhou"
    }

    access_key, secret_key, and region fields commented out.

  2. Initialize the Terraform runtime environment:

    terraform init
    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.90.1...
    ...
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Preview the resources that Terraform plans to create:

    terraform plan
    Refreshing Terraform state in-memory prior to plan...
    The refreshed state will be used to calculate this plan, but will not be
    persisted to local or remote state storage.
    ...
    Plan: 5 to add, 0 to change, 0 to destroy.
    ...
  4. Create the cloud service environment instance:

    terraform apply

    Enter a value, enter yes. The following output is returned:

    ...
    Do you want to perform these actions?
     Terraform will perform the actions described above.
     Only 'yes' will be accepted to approve.
    
     Enter a value: yes
    ...
    alicloud_arms_environment: Creation complete after 8m26s [id=************]
    
    Apply complete! Resources: 4 added, 0 changed, 0 destroyed.
  5. Log on to the ARMS console. On the Integration Management page, verify that the cloud service environment instance appears in the environment list.

Delete an environment instance

The following steps apply to all three environment types: Container Service, ECS, and cloud service.

Warning

terraform destroy destroys all the infrastructure that Terraform manages, and the operation cannot be undone.

  1. Delete the environment instance that you created by using Terraform:

    terraform destroy

    Enter a value, enter yes. The following output is returned:

    ...
    Do you really want to destroy all resources?
     Terraform will destroy all your managed infrastructure, as shown above.
     There is no undo. Only 'yes' will be accepted to confirm.
    
     Enter a value: yes
    ...
    Destroy complete! Resources: 1 destroyed.
  2. Log on to the ARMS console. On the Integration Management page, verify that the environment instance is deleted from the environment list.