All Products
Search
Document Center

Hologres:Manage Hologres instances using Terraform

Last Updated:Feb 04, 2026

Use Terraform to manage Hologres resources without manual intervention. This ensures consistency and repeatability, simplifies infrastructure configuration and maintenance, reduces potential human error, and provides a more efficient and reliable infrastructure management experience.

Note

The example code in this topic supports one-click run. You can run the code directly.

Prerequisites

  • An Alibaba Cloud account, also known as a root account, has full permissions for all of your cloud resources. If the credentials for this account are compromised, your resources are at high risk. We recommend that you use a Resource Access Management (RAM) user and create an AccessKey for that RAM user instead. For more information, see Create a RAM user and Create an AccessKey.

  • Use RAM authorization to manage access permissions for your cloud resources. This approach supports multi-user collaboration and lets you assign permissions based on the principle of least privilege, which reduces security risks that are caused by excessive permissions. For more information, see Manage permissions for RAM users.

    {
        "Version": "1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "vpc:DescribeVpcAttribute",
                    "vpc:DescribeRouteTableList",
                    "vpc:DescribeVSwitchAttributes",
                    "vpc:DeleteVpc",
                    "vpc:DeleteVSwitch",
                    "vpc:CreateVpc",
                    "vpc:CreateVSwitch"
                ],
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": "bss:ModifyAgreementRecord",
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "bss:DescribeOrderList",
                    "bss:DescribeOrderDetail",
                    "bss:PayOrder",
                    "bss:CancelOrder"
                ],
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "hologram:CreateInstance",
                    "hologram:GetInstance",
                    "hologram:DeleteInstance",
                    "hologram:UpdateInstanceNetworkType"
                ],
                "Resource": "*"
            }
        ]
    }
  • Prepare a Terraform runtime environment. You can choose one of the following options to use Terraform.

    • Use Terraform in Terraform Explorer: Alibaba Cloud provides an online Terraform environment. After you log on, you can use and test Terraform without installing it. This option is ideal for testing and debugging Terraform quickly and conveniently at no cost.

    • Cloud Shell: Cloud Shell has Terraform preinstalled and identity credentials preconfigured. You can run Terraform commands directly in Cloud Shell. This option is ideal for accessing and using Terraform quickly and conveniently at a low cost.

    • Install and configure Terraform locally: Use this option if you have poor network connectivity or need a custom development environment.

Resources used

Note

Some resources that are used in the examples in this topic incur charges. To avoid unnecessary charges, release these resources promptly when they are no longer needed.

Create a Hologres instance

This topic uses an 8-core, 32 GB General-purpose Hologres instance as an example.

  1. Create a working directory. In this directory, create a configuration file named main.tf. Copy the following code into main.tf.

    variable "region" {
      default = "cn-shenzhen"
    }
    
    provider "alicloud" {
      region = var.region
    }
    
    variable "zone_id" {
      default = "cn-shenzhen-f"
    }
    
    # Create a VPC
    resource "alicloud_vpc" "main" {
      vpc_name   = "alicloud"
      cidr_block = "172.16.0.0/16"
    }
    
    # Create a vSwitch
    resource "alicloud_vswitch" "main" {
      vpc_id     = alicloud_vpc.main.id
      cidr_block = "172.16.192.0/20"
      zone_id    = var.zone_id
    }
    
    # Create a Hologres instance
    resource "alicloud_hologram_instance" "default" {
      instance_type = "Standard"
      pricing_cycle = "Hour"
      cpu           = "8"
      endpoints {
        type = "Intranet"
      }
      endpoints {
        type       = "VPCSingleTunnel"
        vswitch_id = alicloud_vswitch.main.id
        vpc_id     = alicloud_vswitch.main.vpc_id
      }
      zone_id       = alicloud_vswitch.main.zone_id
      instance_name = "terraform-hologram"
      payment_type  = "PayAsYouGo"
    }

    To create a Serverless instance, add the following code before the preceding code:

    terraform {   # Serverless instance
      required_version = ">= 0.13"
      required_providers {
        alicloud = {
          source = "hashicorp/alicloud"
          version = "1.259.0"
        }
      }
    }
    Note

    When you create a Serverless instance, refer to the following parameter settings:

    resource "alicloud_hologram_instance" "default" {
      payment_type  = "PayAsYouGo"
      instance_type = "Serverless"
      pricing_cycle = "Hour" # Serverless instances support only pay-as-you-go billing.
      cpu           = "4"  # Serverless instances have a fixed CPU count of 4 and are completely free.
    }
  2. Run the following command to initialize the Terraform environment.

    terraform init

    If the initialization is successful, output similar to the following is returned:

    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
  3. Create an execution plan and preview the changes.

    terraform plan
  4. Run the following command to create the resources.

    terraform apply

    When the command is running, enter yes at the prompt and press Enter. Wait for the command to complete. If the following output is returned, the operation is successful.

    alicloud_vpc.main: Creating...
    alicloud_vpc.main: Creation complete after 7s [id=vpc-****]
    alicloud_vswitch.main: Creating...
    alicloud_vswitch.main: Creation complete after 4s [id=vsw-****]
    alicloud_hologram_instance.default: Creating...
    alicloud_hologram_instance.default: Still creating... [10s elapsed]
    alicloud_hologram_instance.default: Still creating... [20s elapsed]
    alicloud_hologram_instance.default: Still creating... [30s elapsed]
    alicloud_hologram_instance.default: Still creating... [40s elapsed]
    alicloud_hologram_instance.default: Still creating... [50s elapsed]
    alicloud_hologram_instance.default: Still creating... [1m0s elapsed]
    alicloud_hologram_instance.default: Still creating... [1m10s elapsed]
    alicloud_hologram_instance.default: Still creating... [1m20s elapsed]
    alicloud_hologram_instance.default: Still creating... [1m30s elapsed]
    alicloud_hologram_instance.default: Still creating... [1m40s elapsed]
    alicloud_hologram_instance.default: Still creating... [1m50s elapsed]
    alicloud_hologram_instance.default: Still creating... [2m0s elapsed]
    alicloud_hologram_instance.default: Still creating... [2m10s elapsed]
    alicloud_hologram_instance.default: Creation complete after 2m10s [id=hgpostcn-cn-****]
    
    Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
  5. Verify the results.

    Run the terraform show command

    Run the terraform show command to view the details of the Hologres instance.

    terraform show
    # alicloud_hologram_instance.default:
    resource "alicloud_hologram_instance" "default" {
        cold_storage_size  = 0
        cpu                = 8
        create_time        = "2024-11-18T05:24:14.693Z"
        gateway_count      = 0
        id                 = "hgpostcn-cn-****"
        instance_name      = "terraform-hologram"
        instance_type      = "Standard"
        leader_instance_id = null
        payment_type       = "PayAsYouGo"
        pricing_cycle      = "Hour"
        resource_group_id  = "rg-****"
        status             = "Running"
        storage_size       = 0
        zone_id            = "cn-shenzhen-f"
    
        endpoints {
            alternative_endpoints = null
            enabled               = true
            endpoint              = "hgpostcn-cn-****-cn-shenzhen-internal.hologres.aliyuncs.com:80"
            type                  = "Intranet"
            vpc_id                = null
            vpc_instance_id       = null
            vswitch_id            = null
        }
        endpoints {
            alternative_endpoints = null
            enabled               = true
            endpoint              = "hgpostcn-cn-****-cn-shenzhen-vpc-st.hologres.aliyuncs.com:80"
            type                  = "VPCSingleTunnel"
            vpc_id                = "vpc-****"
            vpc_instance_id       = "hgpostcn-cn-****-frontend-st"
            vswitch_id            = "vsw-****"
        }
    }

    Log on to the Hologres Management Console

    Log on to the Hologres Management Console to view the details of the Hologres instance.image

Clean up resources

After you no longer need the resources that are created or managed by Terraform, run the following command to release them. For more information about the terraform destroy command, see Common commands.

terraform destroy

Complete example

Note

The example code supports one-click run. You can run the code directly.

Example code

variable "region" {
  default = "cn-shenzhen"
}

provider "alicloud" {
  region = var.region
}

variable "zone_id" {
  default = "cn-shenzhen-f"
}

# Create a VPC
resource "alicloud_vpc" "main" {
  vpc_name   = "alicloud"
  cidr_block = "172.16.0.0/16"
}

# Create a vSwitch
resource "alicloud_vswitch" "main" {
  vpc_id     = alicloud_vpc.main.id
  cidr_block = "172.16.192.0/20"
  zone_id    = var.zone_id
}

# Create a Hologres instance
resource "alicloud_hologram_instance" "default" {
  instance_type = "Standard"
  pricing_cycle = "Hour"
  cpu           = "8"
  endpoints {
    type = "Intranet"
  }
  endpoints {
    type       = "VPCSingleTunnel"
    vswitch_id = alicloud_vswitch.main.id
    vpc_id     = alicloud_vswitch.main.vpc_id
  }
  zone_id       = alicloud_vswitch.main.zone_id
  instance_name = "terraform-hologram"
  payment_type  = "PayAsYouGo"
}